/**
  * Method that skips invocation if: - The store is a shared one and node storing the key is not
  * the 1st owner of the key or, - This is an L1 put operation.
  */
 @Override
 protected boolean skipKey(Object key) {
   if (loaderConfig.shared()) {
     if (!dm.getPrimaryLocation(key).equals(address)) {
       log.trace(
           "Skipping cache store since the cache loader is shared "
               + "and the caller is not the first owner of the key");
       return true;
     }
   } else {
     List<Address> addresses = dm.locate(key);
     if (isL1Put(addresses)) {
       log.trace("Skipping cache store since this is an L1 put");
       return true;
     }
   }
   return false;
 }
  /**
   * This method retrieves an entry from a remote cache and optionally stores it in L1 (if L1 is
   * enabled).
   *
   * <p>This method only works if a) this is a locally originating invocation and b) the entry in
   * question is not local to the current cache instance and c) the entry is not in L1. If either of
   * a, b or c does not hold true, this method returns a null and doesn't do anything.
   *
   * @param ctx invocation context
   * @param key key to retrieve
   * @return value of a remote get, or null
   * @throws Throwable if there are problems
   */
  private Object remoteGetAndStoreInL1(InvocationContext ctx, Object key, boolean isWrite)
      throws Throwable {
    DataLocality locality = dm.getLocality(key);

    if (ctx.isOriginLocal() && !locality.isLocal() && isNotInL1(key)) {
      return realRemoteGet(ctx, key, true, isWrite);
    } else {
      // maybe we are still rehashing as a joiner? ISPN-258
      if (locality.isUncertain()) {
        if (trace)
          log.tracef(
              "Key %s is mapped to local node %s, but a rehash is in progress so may need to look elsewhere",
              key, rpcManager.getAddress());
        // try a remote lookup all the same
        return realRemoteGet(ctx, key, false, isWrite);
      } else {
        if (trace)
          log.tracef(
              "Not doing a remote get for key %s since entry is mapped to current node (%s), or is in L1.  Owners are %s",
              key, rpcManager.getAddress(), dm.locate(key));
      }
    }
    return null;
  }
예제 #3
0
 private static boolean isOwner(Cache<?, ?> cache, Object key) {
   DistributionManager dm = cache.getAdvancedCache().getDistributionManager();
   return dm == null || dm.locate(key).contains(addressOf(cache));
 }
 @Override
 public List<Address> getOwners(Object key) {
   return Immutables.immutableListConvert(dm.locate(key));
 }