コード例 #1
0
  /**
   * @param nodeId Sender node ID.
   * @param req Dht atomic update request.
   * @param res Dht atomic update response.
   */
  public void processDhtAtomicUpdateRequest(
      UUID nodeId, GridDhtAtomicUpdateRequest req, GridDhtAtomicUpdateResponse res) {
    GridCacheVersion ver = req.writeVersion();

    assert ver != null;

    Collection<KeyCacheObject> backupKeys = req.keys();

    boolean intercept = req.forceTransformBackups() && ctx.config().getInterceptor() != null;

    String taskName = ctx.kernalContext().task().resolveTaskName(req.taskNameHash());

    for (int i = 0; i < req.nearSize(); i++) {
      KeyCacheObject key = req.nearKey(i);

      try {
        while (true) {
          try {
            GridCacheEntryEx entry = peekEx(key);

            if (entry == null) {
              res.addNearEvicted(key);

              break;
            }

            if (F.contains(backupKeys, key)) { // Reader became backup.
              if (entry.markObsolete(ver)) removeEntry(entry);

              break;
            }

            CacheObject val = req.nearValue(i);
            EntryProcessor<Object, Object, Object> entryProcessor = req.nearEntryProcessor(i);

            GridCacheOperation op =
                entryProcessor != null ? TRANSFORM : (val != null) ? UPDATE : DELETE;

            long ttl = req.nearTtl(i);
            long expireTime = req.nearExpireTime(i);

            GridCacheUpdateAtomicResult updRes =
                entry.innerUpdate(
                    ver,
                    nodeId,
                    nodeId,
                    op,
                    op == TRANSFORM ? entryProcessor : val,
                    op == TRANSFORM ? req.invokeArguments() : null,
                    /*write-through*/ false,
                    /*read-through*/ false,
                    /*retval*/ false,
                    req.keepBinary(),
                    null,
                    /*event*/ true,
                    /*metrics*/ true,
                    /*primary*/ false,
                    /*check version*/ !req.forceTransformBackups(),
                    req.topologyVersion(),
                    CU.empty0(),
                    DR_NONE,
                    ttl,
                    expireTime,
                    null,
                    false,
                    intercept,
                    req.subjectId(),
                    taskName,
                    null,
                    null);

            if (updRes.removeVersion() != null) ctx.onDeferredDelete(entry, updRes.removeVersion());

            break;
          } catch (GridCacheEntryRemovedException ignored) {
            if (log.isDebugEnabled())
              log.debug("Got removed entry while updating near value (will retry): " + key);
          }
        }
      } catch (IgniteCheckedException e) {
        res.addFailedKey(
            key, new IgniteCheckedException("Failed to update near cache key: " + key, e));
      }
    }
  }
コード例 #2
0
  /**
   * @param ver Version.
   * @param key Key.
   * @param val Value.
   * @param valBytes Value bytes.
   * @param ttl TTL.
   * @param expireTime Expire time.
   * @param nodeId Node ID.
   * @param subjId Subject ID.
   * @param taskName Task name.
   * @throws IgniteCheckedException If failed.
   */
  private void processNearAtomicUpdateResponse(
      GridCacheVersion ver,
      KeyCacheObject key,
      @Nullable CacheObject val,
      @Nullable byte[] valBytes,
      long ttl,
      long expireTime,
      boolean keepBinary,
      UUID nodeId,
      UUID subjId,
      String taskName)
      throws IgniteCheckedException {
    try {
      while (true) {
        GridCacheEntryEx entry = null;

        AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();

        try {
          entry = entryEx(key, topVer);

          GridCacheOperation op = (val != null || valBytes != null) ? UPDATE : DELETE;

          GridCacheUpdateAtomicResult updRes =
              entry.innerUpdate(
                  ver,
                  nodeId,
                  nodeId,
                  op,
                  val,
                  null,
                  /*write-through*/ false,
                  /*read-through*/ false,
                  /*retval*/ false,
                  keepBinary,
                  /*expiry policy*/ null,
                  /*event*/ true,
                  /*metrics*/ true,
                  /*primary*/ false,
                  /*check version*/ true,
                  topVer,
                  CU.empty0(),
                  DR_NONE,
                  ttl,
                  expireTime,
                  null,
                  false,
                  false,
                  subjId,
                  taskName,
                  null,
                  null);

          if (updRes.removeVersion() != null) ctx.onDeferredDelete(entry, updRes.removeVersion());

          break; // While.
        } catch (GridCacheEntryRemovedException ignored) {
          if (log.isDebugEnabled())
            log.debug("Got removed entry while updating near cache value (will retry): " + key);

          entry = null;
        } finally {
          if (entry != null) ctx.evicts().touch(entry, topVer);
        }
      }
    } catch (GridDhtInvalidPartitionException ignored) {
      // Ignore.
    }
  }