@Override
 public boolean hasAffinity(K key) {
   DistributionManager dist = this.cache.getAdvancedCache().getDistributionManager();
   if (dist != null) {
     DataLocality locality = dist.getLocality(key);
     return locality.isLocal() || locality.isUncertain();
   }
   return true;
 }
Beispiel #2
0
 /**
  * Encodes the cases for an asyncGet operation in which it makes sense to actually perform the
  * operation in sync.
  *
  * @param flags
  * @param key
  * @return true if we skip the thread (performing it in sync)
  */
 private boolean asyncSkipsThread(EnumSet<Flag> flags, K key) {
   boolean isSkipLoader = isSkipLoader(flags);
   if (!isSkipLoader) {
     // if we can't skip the cacheloader, we really want a thread for async.
     return false;
   }
   CacheMode cacheMode = config.getCacheMode();
   if (!cacheMode.isDistributed()) {
     // in these cluster modes we won't RPC for a get, so no need to fork a thread.
     return true;
   } else if (flags != null
       && (flags.contains(Flag.SKIP_REMOTE_LOOKUP) || flags.contains(Flag.CACHE_MODE_LOCAL))) {
     // with these flags we won't RPC either
     return true;
   }
   // finally, we will skip the thread if the key maps to the local node
   return distributionManager.getLocality(key).isLocal();
 }
  /**
   * 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;
  }
 private boolean isRemote(Object key) {
   return distributionManager != null && !distributionManager.getLocality(key).isLocal();
 }
 @Override
 public boolean localNodeIsOwner(Object key) {
   return dm.getLocality(key).isLocal();
 }
 private boolean getMightGoRemote(InvocationContext ctx, Object key) {
   return ctx.isOriginLocal()
       && configuration.getCacheMode().isDistributed()
       && !ctx.hasFlag(Flag.SKIP_REMOTE_LOOKUP)
       && !distManager.getLocality(key).isLocal();
 }