Search in sources :

Example 6 with Response

use of voldemort.store.routed.Response in project voldemort by voldemort.

the class HintedHandoff method sendOneAsyncHint.

/**
     * A callback that handles requestComplete event from NIO selector manager
     * Will try any possible nodes and pass itself as callback util all nodes
     * are exhausted
     * 
     * @param slopKey
     * @param slopVersioned
     * @param nodesToTry List of nodes to try to contact. Will become shorter
     *        after each callback
     */
private void sendOneAsyncHint(final ByteArray slopKey, final Versioned<byte[]> slopVersioned, final List<Node> nodesToTry) {
    Node nodeToHostHint = null;
    boolean foundNode = false;
    while (nodesToTry.size() > 0) {
        nodeToHostHint = nodesToTry.remove(0);
        if (!failedNodes.contains(nodeToHostHint) && failureDetector.isAvailable(nodeToHostHint)) {
            foundNode = true;
            break;
        }
    }
    if (!foundNode) {
        Slop slop = slopSerializer.toObject(slopVersioned.getValue());
        logger.error("Trying to send an async hint but used up all nodes. key: " + slop.getKey() + " version: " + slopVersioned.getVersion().toString());
        return;
    }
    final Node node = nodeToHostHint;
    int nodeId = node.getId();
    NonblockingStore nonblockingStore = nonblockingSlopStores.get(nodeId);
    Utils.notNull(nonblockingStore);
    final Long startNs = System.nanoTime();
    NonblockingStoreCallback callback = new NonblockingStoreCallback() {

        @Override
        public void requestComplete(Object result, long requestTime) {
            Slop slop = null;
            boolean loggerDebugEnabled = logger.isDebugEnabled();
            if (loggerDebugEnabled) {
                slop = slopSerializer.toObject(slopVersioned.getValue());
            }
            Response<ByteArray, Object> response = new Response<ByteArray, Object>(node, slopKey, result, requestTime);
            if (response.getValue() instanceof Exception && !(response.getValue() instanceof ObsoleteVersionException)) {
                if (!failedNodes.contains(node))
                    failedNodes.add(node);
                if (response.getValue() instanceof UnreachableStoreException) {
                    UnreachableStoreException use = (UnreachableStoreException) response.getValue();
                    if (loggerDebugEnabled) {
                        logger.debug("Write of key " + slop.getKey() + " for " + slop.getNodeId() + " to node " + node + " failed due to unreachable: " + use.getMessage());
                    }
                    failureDetector.recordException(node, (System.nanoTime() - startNs) / Time.NS_PER_MS, use);
                }
                sendOneAsyncHint(slopKey, slopVersioned, nodesToTry);
            }
            if (loggerDebugEnabled)
                logger.debug("Slop write of key " + slop.getKey() + " for node " + slop.getNodeId() + " to node " + node + " succeeded in " + (System.nanoTime() - startNs) + " ns");
            failureDetector.recordSuccess(node, (System.nanoTime() - startNs) / Time.NS_PER_MS);
        }
    };
    nonblockingStore.submitPutRequest(slopKey, slopVersioned, null, callback, timeoutMs);
}
Also used : NonblockingStore(voldemort.store.nonblockingstore.NonblockingStore) Node(voldemort.cluster.Node) ObsoleteVersionException(voldemort.versioning.ObsoleteVersionException) UnreachableStoreException(voldemort.store.UnreachableStoreException) Response(voldemort.store.routed.Response) NonblockingStoreCallback(voldemort.store.nonblockingstore.NonblockingStoreCallback) ObsoleteVersionException(voldemort.versioning.ObsoleteVersionException) ByteArray(voldemort.utils.ByteArray) UnreachableStoreException(voldemort.store.UnreachableStoreException)

Example 7 with Response

use of voldemort.store.routed.Response in project voldemort by voldemort.

the class PerformSerialGetAllRequests method execute.

public void execute(Pipeline pipeline) {
    Map<ByteArray, List<Versioned<byte[]>>> result = pipelineData.getResult();
    for (ByteArray key : keys) {
        boolean zoneRequirement = false;
        MutableInt successCount = pipelineData.getSuccessCount(key);
        if (logger.isDebugEnabled())
            logger.debug("GETALL for key " + ByteUtils.toHexString(key.get()) + " (keyRef: " + System.identityHashCode(key) + ") successes: " + successCount.intValue() + " preferred: " + preferred + " required: " + required);
        if (successCount.intValue() >= preferred) {
            if (pipelineData.getZonesRequired() != null && pipelineData.getZonesRequired() > 0) {
                if (pipelineData.getKeyToZoneResponse().containsKey(key)) {
                    int zonesSatisfied = pipelineData.getKeyToZoneResponse().get(key).size();
                    if (zonesSatisfied >= (pipelineData.getZonesRequired() + 1)) {
                        continue;
                    } else {
                        zoneRequirement = true;
                    }
                } else {
                    zoneRequirement = true;
                }
            } else {
                continue;
            }
        }
        List<Node> extraNodes = pipelineData.getKeyToExtraNodesMap().get(key);
        Map<ByteArray, byte[]> transforms = pipelineData.getTransforms();
        if (extraNodes == null)
            continue;
        for (Node node : extraNodes) {
            long start = System.nanoTime();
            try {
                Store<ByteArray, byte[], byte[]> store = stores.get(node.getId());
                List<Versioned<byte[]>> values;
                if (transforms == null)
                    values = store.get(key, null);
                else
                    values = store.get(key, transforms.get(key));
                if (values.size() != 0) {
                    if (result.get(key) == null)
                        result.put(key, Lists.newArrayList(values));
                    else
                        result.get(key).addAll(values);
                }
                Map<ByteArray, List<Versioned<byte[]>>> map = new HashMap<ByteArray, List<Versioned<byte[]>>>();
                map.put(key, values);
                Response<Iterable<ByteArray>, Map<ByteArray, List<Versioned<byte[]>>>> response = new Response<Iterable<ByteArray>, Map<ByteArray, List<Versioned<byte[]>>>>(node, Arrays.asList(key), map, ((System.nanoTime() - start) / Time.NS_PER_MS));
                successCount.increment();
                pipelineData.getResponses().add(response);
                failureDetector.recordSuccess(response.getNode(), response.getRequestTime());
                if (logger.isDebugEnabled())
                    logger.debug("GET for key " + ByteUtils.toHexString(key.get()) + " (keyRef: " + System.identityHashCode(key) + ") successes: " + successCount.intValue() + " preferred: " + preferred + " required: " + required + " new GET success on node " + node.getId());
                HashSet<Integer> zoneResponses = null;
                if (pipelineData.getKeyToZoneResponse().containsKey(key)) {
                    zoneResponses = pipelineData.getKeyToZoneResponse().get(key);
                } else {
                    zoneResponses = new HashSet<Integer>();
                    pipelineData.getKeyToZoneResponse().put(key, zoneResponses);
                }
                zoneResponses.add(response.getNode().getZoneId());
                if (zoneRequirement) {
                    if (zoneResponses.size() >= pipelineData.getZonesRequired())
                        break;
                } else {
                    if (successCount.intValue() >= preferred)
                        break;
                }
            } catch (Exception e) {
                long requestTime = (System.nanoTime() - start) / Time.NS_PER_MS;
                if (handleResponseError(e, node, requestTime, pipeline, failureDetector))
                    return;
            }
        }
    }
    for (ByteArray key : keys) {
        MutableInt successCount = pipelineData.getSuccessCount(key);
        if (successCount.intValue() < required) {
            // not meet 'required' guarantee; else raise error
            if (allowPartial) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Excluding Key " + ByteUtils.toHexString(key.get()) + " from partial get_all result");
                }
                result.remove(key);
            } else {
                pipelineData.setFatalError(new InsufficientOperationalNodesException(required + " " + pipeline.getOperation().getSimpleName() + "s required, but " + successCount.intValue() + " succeeded. Failing nodes : " + pipelineData.getFailedNodes(), pipelineData.getFailures()));
                pipeline.addEvent(Event.ERROR);
                return;
            }
        }
    }
    pipeline.addEvent(completeEvent);
}
Also used : Versioned(voldemort.versioning.Versioned) HashMap(java.util.HashMap) Node(voldemort.cluster.Node) InsufficientOperationalNodesException(voldemort.store.InsufficientOperationalNodesException) Response(voldemort.store.routed.Response) MutableInt(org.apache.commons.lang.mutable.MutableInt) InsufficientOperationalNodesException(voldemort.store.InsufficientOperationalNodesException) ByteArray(voldemort.utils.ByteArray) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Node (voldemort.cluster.Node)7 Response (voldemort.store.routed.Response)7 ByteArray (voldemort.utils.ByteArray)7 InsufficientOperationalNodesException (voldemort.store.InsufficientOperationalNodesException)4 InsufficientZoneResponsesException (voldemort.store.InsufficientZoneResponsesException)4 NonblockingStore (voldemort.store.nonblockingstore.NonblockingStore)4 NonblockingStoreCallback (voldemort.store.nonblockingstore.NonblockingStoreCallback)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 InvalidMetadataException (voldemort.store.InvalidMetadataException)3 List (java.util.List)2 Map (java.util.Map)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 MutableInt (org.apache.commons.lang.mutable.MutableInt)2 UnreachableStoreException (voldemort.store.UnreachableStoreException)2 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)2 Versioned (voldemort.versioning.Versioned)2 HashMap (java.util.HashMap)1 QuotaExceededException (voldemort.store.quota.QuotaExceededException)1