コード例 #1
0
  /**
   * Processes unlock request.
   *
   * @param nodeId Sender node ID.
   * @param req Unlock request.
   */
  @SuppressWarnings({"unchecked"})
  private void processUnlockRequest(UUID nodeId, GridDistributedUnlockRequest req) {
    assert nodeId != null;

    try {
      ClassLoader ldr = ctx.deploy().globalLoader();
      List<byte[]> keys = req.keyBytes();

      for (byte[] keyBytes : keys) {
        K key = (K) U.unmarshal(ctx.marshaller(), new ByteArrayInputStream(keyBytes), ldr);

        while (true) {
          boolean created = false;

          GridDistributedCacheEntry<K, V> entry = peekexx(key);

          if (entry == null) {
            entry = entryexx(key);

            created = true;
          }

          try {
            entry.doneRemote(
                req.version(), req.version(), req.committedVersions(), req.rolledbackVersions());

            // Note that we don't reorder completed versions here,
            // as there is no point to reorder relative to the version
            // we are about to remove.
            if (entry.removeLock(req.version())) {
              if (log.isDebugEnabled())
                log.debug("Removed lock [lockId=" + req.version() + ", key=" + key + ']');

              if (created && entry.markObsolete(req.version())) removeIfObsolete(entry.key());
            } else if (log.isDebugEnabled())
              log.debug(
                  "Received unlock request for unknown candidate "
                      + "(added to cancelled locks set): "
                      + req);

            break;
          } catch (GridCacheEntryRemovedException ignored) {
            if (log.isDebugEnabled())
              log.debug(
                  "Received remove lock request for removed entry (will retry) [entry="
                      + entry
                      + ", req="
                      + req
                      + ']');
          }
        }
      }
    } catch (GridException e) {
      U.error(log, "Failed to unmarshal unlock key (unlock will not be performed): " + req, e);
    }
  }
コード例 #2
0
  /**
   * @param nodeId Node ID.
   * @param req Request.
   */
  @SuppressWarnings({"RedundantTypeArguments"})
  public void clearLocks(UUID nodeId, GridDhtUnlockRequest<K, V> req) {
    assert nodeId != null;

    GridCacheVersion obsoleteVer = ctx.versions().next();

    List<K> keys = req.nearKeys();

    if (keys != null) {
      for (K key : keys) {
        while (true) {
          GridDistributedCacheEntry<K, V> entry = peekExx(key);

          try {
            if (entry != null) {
              entry.doneRemote(
                  req.version(), req.version(), req.committedVersions(), req.rolledbackVersions());

              // Note that we don't reorder completed versions here,
              // as there is no point to reorder relative to the version
              // we are about to remove.
              if (entry.removeLock(req.version())) {
                if (log.isDebugEnabled())
                  log.debug("Removed lock [lockId=" + req.version() + ", key=" + key + ']');

                // Try to evict near entry dht-mapped locally.
                evictNearEntry(entry, obsoleteVer);
              } else {
                if (log.isDebugEnabled())
                  log.debug(
                      "Received unlock request for unknown candidate "
                          + "(added to cancelled locks set): "
                          + req);
              }
            } else if (log.isDebugEnabled())
              log.debug("Received unlock request for entry that could not be found: " + req);

            break;
          } catch (GridCacheEntryRemovedException ignored) {
            if (log.isDebugEnabled())
              log.debug(
                  "Received remove lock request for removed entry (will retry) [entry="
                      + entry
                      + ", req="
                      + req
                      + ']');
          }
        }
      }
    }
  }