Package net.spy.memcached

Examples of net.spy.memcached.MemcachedNode


    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


      }

      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();
        ObserveResponse observeResponse = r.getValue();

        boolean isMaster = node == master ? true : false;
        if (isMaster && observeResponse == ObserveResponse.MODIFIED) {
          throw new ObservedModifiedException("Key was modified");
View Full Code Here

   * @param key the key the operation is operating upon
   * @param o the operation
   */
  @Override
  public void addOperation(final String key, final Operation o) {
    MemcachedNode placeIn = null;

    MemcachedNode primary;
    if(o instanceof ReplicaGetOperation
      && locator instanceof VBucketNodeLocator) {
      primary = ((VBucketNodeLocator)locator).getReplica(key,
        ((ReplicaGetOperation)o).getReplicaIndex());
    } else {
      primary = locator.getPrimary(key);
    }

    if (primary == null) {
      o.cancel();
      cf.checkConfigUpdate();
      return;
    }

    boolean needsRecheckConfigUpdate = false;
    if (primary.isActive() || failureMode == FailureMode.Retry) {
      placeIn = primary;
      needsRecheckConfigUpdate = !primary.isActive();
    } else if (failureMode == FailureMode.Cancel) {
      o.cancel();
      needsRecheckConfigUpdate = true;
    } else {
      // Look for another node in sequence that is ready.
      for (Iterator<MemcachedNode> i = locator.getSequence(key); placeIn == null
          && i.hasNext();) {
        MemcachedNode n = i.next();
        if (n.isActive()) {
          placeIn = n;
        }
      }

      if (placeIn == null) {
        placeIn = primary;
        needsRecheckConfigUpdate = true;
      }
    }

    // If we didn't find an active node, queue it in the primary node
    // and wait for it to come back online.
    if (needsRecheckConfigUpdate) {
      getLogger().warn(
        "Node expected to receive data is inactive. This could be due to "
          + "a failure within the cluster. Will check for updated "
          + "configuration. Key without a configured node is: %s.", key);
      cf.checkConfigUpdate();
    }

    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

  }

  @Override
  public void addOperations(final Map<MemcachedNode, Operation> ops) {
    for (Map.Entry<MemcachedNode, Operation> me : ops.entrySet()) {
      final MemcachedNode node = me.getKey();

      if (!node.isActive()) {
        cf.checkConfigUpdate();
      }

      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);
          }
        }
      }
      o.setHandlingNode(node);
      o.initialize();
      node.addOp(o);
      addedQueue.offer(node);
    }
    updateLastWrite();
    Selector s = selector.wakeup();
    assert s == selector : "Wakeup returned the wrong selector.";
View Full Code Here

    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

      }

      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();
        ObserveResponse observeResponse = r.getValue();

        boolean isMaster = node == master ? true : false;
        if (isMaster && observeResponse == ObserveResponse.MODIFIED) {
          throw new ObservedModifiedException("Key was modified");
View Full Code Here

    }
  }

  @Override
  protected void addOperation(final String key, final Operation o) {
    MemcachedNode placeIn = null;
    MemcachedNode primary = locator.getPrimary(key);

    if (primary == null) {
      o.cancel();
      cf.checkConfigUpdate();
      return;
    }

    if(!primary.isActive()) {
      cf.checkConfigUpdate();
    }

    if (primary.isActive() || failureMode == FailureMode.Retry) {
      placeIn = primary;
    } else if (failureMode == FailureMode.Cancel) {
      o.cancel();
    } else {
      // Look for another node in sequence that is ready.
      for (Iterator<MemcachedNode> i = locator.getSequence(key); placeIn == null
          && i.hasNext();) {
        MemcachedNode n = i.next();
        if (n.isActive()) {
          placeIn = n;
        }
      }

      // If we didn't find an active node, queue it in the primary node
View Full Code Here

   * @param key the key the operation is operating upon
   * @param o the operation
   */
  @Override
  public void addOperation(final String key, final Operation o) {
    MemcachedNode placeIn = null;

    MemcachedNode primary;
    if(o instanceof ReplicaGetOperation
      && locator instanceof VBucketNodeLocator) {
      primary = ((VBucketNodeLocator)locator).getReplica(key,
        ((ReplicaGetOperation)o).getReplicaIndex());
    } else {
      primary = locator.getPrimary(key);
    }

    if (primary == null) {
      o.cancel();
      cf.checkConfigUpdate();
      return;
    }

    if (primary.isActive() || failureMode == FailureMode.Retry) {
      placeIn = primary;
    } else if (failureMode == FailureMode.Cancel) {
      o.cancel();
    } else {
      // Look for another node in sequence that is ready.
      for (Iterator<MemcachedNode> i = locator.getSequence(key); placeIn == null
          && i.hasNext();) {
        MemcachedNode n = i.next();
        if (n.isActive()) {
          placeIn = n;
        }
      }
      // If we didn't find an active node, queue it in the primary node
      // and wait for it to come back online.
      if (placeIn == null) {
        placeIn = primary;
        getLogger().warn(
            "Node expected to receive data is inactive. This could be due to "
            + "a failure within the cluster. Will check for updated "
            + "configuration. Key without a configured node is: %s.", key);
        cf.checkConfigUpdate();
      }
    }

    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

  }

  @Override
  public void addOperations(final Map<MemcachedNode, Operation> ops) {
    for (Map.Entry<MemcachedNode, Operation> me : ops.entrySet()) {
      final MemcachedNode node = me.getKey();

      if (!node.isActive()) {
        cf.checkConfigUpdate();
      }

      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);
          }
        }
      }
      o.setHandlingNode(node);
      o.initialize();
      node.addOp(o);
      addedQueue.offer(node);
    }
    Selector s = selector.wakeup();
    assert s == selector : "Wakeup returned the wrong selector.";
  }
View Full Code Here

    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

Related Classes of net.spy.memcached.MemcachedNode

Copyright © 2018 www.massapicom. 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.