Search in sources :

Example 6 with NonblockingStoreCallback

use of voldemort.store.nonblockingstore.NonblockingStoreCallback in project voldemort by voldemort.

the class ClientRequestExecutorPoolTest method testCloseWithOutstandingQueue.

@Test
public void testCloseWithOutstandingQueue() {
    final int MAX_CONNECTIONS = 2;
    ClientRequestExecutorPool execPool = new ClientRequestExecutorPool(2, MAX_CONNECTIONS, CONNECTION_TIMEOUT_MS, SOCKET_TIMEOUT_MS, IDLE_CONNECTION_TIMEOUT_MS, 32 * 1024, false, true, new String());
    // will always wait in the queue.
    for (int i = 0; i < MAX_CONNECTIONS; i++) {
        execPool.checkout(dest1);
    }
    for (int j = 0; j < 2; j++) {
        GetClientRequest clientRequest = new GetClientRequest("sampleStore", new RequestFormatFactory().getRequestFormat(dest1.getRequestFormatType()), RequestRoutingType.ROUTED, new ByteArray(new byte[] { 1, 2, 3 }), null);
        final AtomicInteger cancelledEvents = new AtomicInteger(0);
        NonblockingStoreCallback callback = new NonblockingStoreCallback() {

            @Override
            public void requestComplete(Object result, long requestTime) {
                if (result instanceof UnreachableStoreException)
                    cancelledEvents.incrementAndGet();
                else
                    fail("The request must have failed with UnreachableException" + result);
            }
        };
        int queuedRequestCount = 20;
        for (int i = 0; i < queuedRequestCount; i++) {
            execPool.submitAsync(dest1, clientRequest, callback, 5000, "get");
        }
        int outstandingQueue = execPool.internalGetQueuedPool().getRegisteredResourceRequestCount(dest1);
        assertEquals("Queued request count should match", queuedRequestCount, outstandingQueue);
        // Now reset the queue, the outstanding requests should fail with
        // UnreachableStoreException
        execPool.close(dest1);
        outstandingQueue = execPool.internalGetQueuedPool().getRegisteredResourceRequestCount(dest1);
        assertEquals("Queued request should have been cleared", 0, outstandingQueue);
        // CancelledEvents should be
        assertEquals("All Queuedrequest must have been cancelled.", queuedRequestCount, cancelledEvents.get());
    }
}
Also used : RequestFormatFactory(voldemort.client.protocol.RequestFormatFactory) GetClientRequest(voldemort.store.socket.clientrequest.GetClientRequest) NonblockingStoreCallback(voldemort.store.nonblockingstore.NonblockingStoreCallback) ClientRequestExecutorPool(voldemort.store.socket.clientrequest.ClientRequestExecutorPool) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteArray(voldemort.utils.ByteArray) UnreachableStoreException(voldemort.store.UnreachableStoreException) Test(org.junit.Test)

Example 7 with NonblockingStoreCallback

use of voldemort.store.nonblockingstore.NonblockingStoreCallback in project voldemort by voldemort.

the class NioSelectorManagerTest method getCallBack.

private NonblockingStoreCallback getCallBack() {
    final AtomicInteger cancelledEvents = new AtomicInteger(0);
    NonblockingStoreCallback callback = new NonblockingStoreCallback() {

        @Override
        public void requestComplete(Object result, long requestTime) {
            if (result instanceof UnreachableStoreException)
                cancelledEvents.incrementAndGet();
            else
                fail("The request must have failed with UnreachableException" + result);
        }
    };
    return callback;
}
Also used : NonblockingStoreCallback(voldemort.store.nonblockingstore.NonblockingStoreCallback) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UnreachableStoreException(voldemort.store.UnreachableStoreException)

Example 8 with NonblockingStoreCallback

use of voldemort.store.nonblockingstore.NonblockingStoreCallback 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)

Aggregations

NonblockingStoreCallback (voldemort.store.nonblockingstore.NonblockingStoreCallback)8 ByteArray (voldemort.utils.ByteArray)6 Node (voldemort.cluster.Node)5 UnreachableStoreException (voldemort.store.UnreachableStoreException)5 NonblockingStore (voldemort.store.nonblockingstore.NonblockingStore)5 InvalidMetadataException (voldemort.store.InvalidMetadataException)4 Response (voldemort.store.routed.Response)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 InsufficientOperationalNodesException (voldemort.store.InsufficientOperationalNodesException)3 InsufficientZoneResponsesException (voldemort.store.InsufficientZoneResponsesException)3 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 QuotaExceededException (voldemort.store.quota.QuotaExceededException)2 ConnectException (java.net.ConnectException)1 InetSocketAddress (java.net.InetSocketAddress)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 ClosedSelectorException (java.nio.channels.ClosedSelectorException)1 Selector (java.nio.channels.Selector)1