Examples of VBucketNodeLocator


Examples of com.couchbase.client.vbucket.VBucketNodeLocator

    }

    if (config.getConfigType() == ConfigType.MEMCACHE) {
      return new KetamaNodeLocator(nodes, DefaultHashAlgorithm.KETAMA_HASH);
    } else if (config.getConfigType() == ConfigType.COUCHBASE) {
      return new VBucketNodeLocator(nodes, getVBucketConfig());
    } else {
      throw new IllegalStateException("Unhandled locator type: "
          + config.getConfigType());
    }
  }
View Full Code Here

Examples of com.couchbase.client.vbucket.VBucketNodeLocator

    if (bucketReplicaCount == 0) {
      getLogger().debug("No replica configured for this bucket, trying to get "
        + "the document from active node only.");
    }

    VBucketNodeLocator locator = (VBucketNodeLocator) mconn.getLocator();
    List<Integer> actualReplicaIndexes = locator.getReplicaIndexes(key);

    final ReplicaGetFuture<T> replicaFuture = new ReplicaGetFuture<T>(
      operationTimeout, executorService);

    for(int index : actualReplicaIndexes) {
      final CountDownLatch latch = new CountDownLatch(1);
      final GetFuture<T> rv =
        new GetFuture<T>(latch, operationTimeout, key, executorService);
      Operation op = createOperationForReplicaGet(key, rv, replicaFuture,
        latch, tc, index, true);

      rv.setOperation(op);
      mconn.enqueueOperation(key, op);

      if (op.isCancelled()) {
        discardedOps++;
        getLogger().debug("Silently discarding replica get for key \""
          + key + "\" (cancelled).");
      } else {
        replicaFuture.addFutureToMonitor(rv);
      }

    }

    if (locator.hasActiveMaster(key)) {
      final CountDownLatch latch = new CountDownLatch(1);
      final GetFuture<T> additionalActiveGet = new GetFuture<T>(latch, operationTimeout, key,
        executorService);
      Operation op = createOperationForReplicaGet(key, additionalActiveGet,
        replicaFuture, latch, tc, 0, false);
View Full Code Here

Examples of com.couchbase.client.vbucket.VBucketNodeLocator

  }

  private Map<MemcachedNode, ObserveResponse> observe(final String key,
    final long cas, final boolean toMaster, final boolean toReplica) {
    Config cfg = ((CouchbaseConnectionFactory) connFactory).getVBucketConfig();
    VBucketNodeLocator locator = (VBucketNodeLocator) mconn.getLocator();

    final int vb = locator.getVBucketIndex(key);
    List<MemcachedNode> bcastNodes = new ArrayList<MemcachedNode>();

    if (toMaster) {
      MemcachedNode primary = locator.getPrimary(key);
      if (primary != null) {
        bcastNodes.add(primary);
      }
    }

    if (toReplica) {
      for (int i = 0; i < cfg.getReplicasCount(); i++) {
        MemcachedNode replica = locator.getReplica(key, i);
        if (replica != null) {
          bcastNodes.add(replica);
        }
      }
    }
View Full Code Here

Examples of com.couchbase.client.vbucket.VBucketNodeLocator

    return shutdownResult;
  }

  private void checkObserveReplica(String key, int numPersist, int numReplica) {
    Config cfg = ((CouchbaseConnectionFactory) connFactory).getVBucketConfig();
    VBucketNodeLocator locator = (VBucketNodeLocator) mconn.getLocator();

    if(numReplica > 0) {
      int vBucketIndex = locator.getVBucketIndex(key);
      int currentReplicaNum = cfg.getReplica(vBucketIndex, numReplica-1);
      if (currentReplicaNum < 0) {
        throw new ObservedException("Currently, there is no replica node "
          + "available for the given replication index (" + numReplica + ").");
      }
    }

    int replicaCount = Math.min(locator.getAll().size() - 1, cfg.getReplicasCount());
    if (numReplica > replicaCount) {
      throw new ObservedException("Requested replication to " + numReplica
          + " node(s), but only " + replicaCount + " are available.");
    } else if (numPersist > replicaCount + 1) {
      throw new ObservedException("Requested persistence to " + (numPersist + 1)
View Full Code Here

Examples of com.couchbase.client.vbucket.VBucketNodeLocator

      replicate = ReplicateTo.ZERO;
    }

    final int maxPolls = cbConnFactory.getObsPollMax();
    final long pollInterval = cbConnFactory.getObsPollInterval();
    final VBucketNodeLocator locator = (VBucketNodeLocator) mconn.getLocator();

    final int shouldPersistTo = persist.getValue() > 0 ? persist.getValue() - 1 : 0;
    final int shouldReplicateTo = replicate.getValue();
    final boolean shouldPersistToMaster = persist.getValue() > 0;

    final boolean toMaster = persist.getValue() > 0;
    final boolean toReplica = replicate.getValue() > 0 || persist.getValue() > 1;

    int donePolls = 0;
    int alreadyPersistedTo = 0;
    int alreadyReplicatedTo = 0;
    boolean alreadyPersistedToMaster = false;
    while(shouldReplicateTo > alreadyReplicatedTo
      || shouldPersistTo - 1 > alreadyPersistedTo
      || (!alreadyPersistedToMaster && shouldPersistToMaster)) {
      checkObserveReplica(key, shouldPersistTo, shouldReplicateTo);

      if (++donePolls >= maxPolls) {
        long timeTried = maxPolls * pollInterval;
        throw new ObservedTimeoutException("Observe Timeout - Polled"
          + " Unsuccessfully for at least "
          + TimeUnit.MILLISECONDS.toSeconds(timeTried) + " seconds.");
      }

      Map<MemcachedNode, ObserveResponse> response = observe(key, cas, toMaster,
        toReplica);

      MemcachedNode master = locator.getPrimary(key);
      alreadyPersistedTo = 0;
      alreadyReplicatedTo = 0;
      alreadyPersistedToMaster = false;
      for (Entry<MemcachedNode, ObserveResponse> r : response.entrySet()) {
        MemcachedNode node = r.getKey();
View Full Code Here

Examples of com.couchbase.client.vbucket.VBucketNodeLocator

    assert o.isCancelled() || placeIn != null : "No node found for key " + key;
    if (placeIn != null) {
      // add the vbucketIndex to the operation
      if (locator instanceof VBucketNodeLocator) {
        VBucketNodeLocator vbucketLocator = (VBucketNodeLocator) locator;
        short vbucketIndex = (short) vbucketLocator.getVBucketIndex(key);
        if (o instanceof VBucketAware) {
          VBucketAware vbucketAwareOp = (VBucketAware) o;
          vbucketAwareOp.setVBucket(key, vbucketIndex);
          Collection<MemcachedNode> notMyVbucketNodes =
            vbucketAwareOp.getNotMyVbucketNodes();
          if (!notMyVbucketNodes.isEmpty()) {
            cf.checkConfigUpdate();
            MemcachedNode alternative = vbucketLocator.getAlternative(key,
              notMyVbucketNodes);
            if (alternative == null) {
              notMyVbucketNodes.clear();
            } else {
              placeIn = alternative;
View Full Code Here

Examples of com.couchbase.client.vbucket.VBucketNodeLocator

      Operation o = me.getValue();
      // add the vbucketIndex to the operation
      if (locator instanceof VBucketNodeLocator) {
        if (o instanceof KeyedOperation && o instanceof VBucketAware) {
          Collection<String> keys = ((KeyedOperation) o).getKeys();
          VBucketNodeLocator vbucketLocator = (VBucketNodeLocator) locator;
          for (String key : keys) {
            short vbucketIndex = (short) vbucketLocator.getVBucketIndex(key);
            VBucketAware vbucketAwareOp = (VBucketAware) o;
            vbucketAwareOp.setVBucket(key, vbucketIndex);
          }
        }
      }
View Full Code Here

Examples of com.couchbase.client.vbucket.VBucketNodeLocator

    if (bucketReplicaCount == 0) {
      getLogger().debug("No replica configured for this bucket, trying to get "
        + "the document from active node only.");
    }

    VBucketNodeLocator locator = (VBucketNodeLocator) mconn.getLocator();
    List<Integer> actualReplicaIndexes = locator.getReplicaIndexes(key);

    final ReplicaGetFuture<T> replicaFuture = new ReplicaGetFuture<T>(
      operationTimeout, executorService);

    for(int index : actualReplicaIndexes) {
      final CountDownLatch latch = new CountDownLatch(1);
      final GetFuture<T> rv =
        new GetFuture<T>(latch, operationTimeout, key, executorService);
      Operation op = createOperationForReplicaGet(key, rv, replicaFuture,
        latch, tc, index, true);

      rv.setOperation(op);
      mconn.enqueueOperation(key, op);

      if (op.isCancelled()) {
        discardedOps++;
        getLogger().debug("Silently discarding replica get for key \""
          + key + "\" (cancelled).");
      } else {
        replicaFuture.addFutureToMonitor(rv);
      }

    }

    if (locator.hasActiveMaster(key)) {
      final CountDownLatch latch = new CountDownLatch(1);
      final GetFuture<T> additionalActiveGet = new GetFuture<T>(latch, operationTimeout, key,
        executorService);
      Operation op = createOperationForReplicaGet(key, additionalActiveGet,
        replicaFuture, latch, tc, 0, false);
View Full Code Here

Examples of com.couchbase.client.vbucket.VBucketNodeLocator

    if (bucketReplicaCount == 0) {
      getLogger().debug("No replica configured for this bucket, trying to get "
        + "the document from active node only.");
    }

    VBucketNodeLocator locator = (VBucketNodeLocator) mconn.getLocator();
    List<Integer> actualReplicaIndexes = locator.getReplicaIndexes(key);

    final ReplicaGetFuture<CASValue<T>> replicaFuture = new ReplicaGetFuture<CASValue<T>>(
      operationTimeout, executorService);

    for(int index : actualReplicaIndexes) {
      final CountDownLatch latch = new CountDownLatch(1);
      final OperationFuture<CASValue<T>> rv =
        new OperationFuture<CASValue<T>>(key, latch, operationTimeout, executorService);
      Operation op = createOperationForReplicaGets(key, rv, replicaFuture,
        latch, tc, index, true);

      rv.setOperation(op);
      mconn.enqueueOperation(key, op);

      if (op.isCancelled()) {
        discardedOps++;
        getLogger().debug("Silently discarding replica get for key \""
          + key + "\" (cancelled).");
      } else {
        replicaFuture.addFutureToMonitor(rv);
      }

    }

    if (locator.hasActiveMaster(key)) {
      final CountDownLatch latch = new CountDownLatch(1);
      final OperationFuture<CASValue<T>> additionalActiveGet =
        new OperationFuture<CASValue<T>>(key, latch, operationTimeout, executorService);
      Operation op = createOperationForReplicaGets(key, additionalActiveGet,
        replicaFuture, latch, tc, 0, false);
View Full Code Here

Examples of com.couchbase.client.vbucket.VBucketNodeLocator

  }

  private Map<MemcachedNode, ObserveResponse> observe(final String key,
    final long cas, final boolean toMaster, final boolean toReplica) {
    Config cfg = ((CouchbaseConnectionFactory) connFactory).getVBucketConfig();
    VBucketNodeLocator locator = (VBucketNodeLocator) mconn.getLocator();

    final int vb = locator.getVBucketIndex(key);
    List<MemcachedNode> bcastNodes = new ArrayList<MemcachedNode>();

    if (toMaster) {
      MemcachedNode primary = locator.getPrimary(key);
      if (primary != null) {
        bcastNodes.add(primary);
      }
    }

    if (toReplica) {
      for (int i = 0; i < cfg.getReplicasCount(); i++) {
        MemcachedNode replica = locator.getReplica(key, i);
        if (replica != null) {
          bcastNodes.add(replica);
        }
      }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.