Search in sources :

Example 21 with UnreachableStoreException

use of voldemort.store.UnreachableStoreException in project voldemort by voldemort.

the class SocketStore method request.

/**
     * This method handles submitting and then waiting for the request from the
     * server. It uses the ClientRequest API to actually write the request and
     * then read back the response. This implementation will block for a
     * response from the server.
     * 
     * @param <T> Return type
     * 
     * @param clientRequest ClientRequest implementation used to write the
     *        request and read the response
     * @param operationName Simple string representing the type of request
     * 
     * @return Data returned by the individual requests
     */
private <T> T request(ClientRequest<T> delegate, String operationName) {
    long startTimeMs = -1;
    long startTimeNs = -1;
    if (logger.isDebugEnabled()) {
        startTimeMs = System.currentTimeMillis();
    }
    ClientRequestExecutor clientRequestExecutor = pool.checkout(destination);
    String debugMsgStr = "";
    startTimeNs = System.nanoTime();
    BlockingClientRequest<T> blockingClientRequest = null;
    try {
        blockingClientRequest = new BlockingClientRequest<T>(delegate, timeoutMs);
        clientRequestExecutor.addClientRequest(blockingClientRequest, timeoutMs, System.nanoTime() - startTimeNs);
        boolean awaitResult = blockingClientRequest.await();
        if (awaitResult == false) {
            blockingClientRequest.timeOut();
        }
        if (logger.isDebugEnabled())
            debugMsgStr += "success";
        return blockingClientRequest.getResult();
    } catch (InterruptedException e) {
        if (logger.isDebugEnabled())
            debugMsgStr += "unreachable: " + e.getMessage();
        throw new UnreachableStoreException("Failure in " + operationName + " on " + destination + ": " + e.getMessage(), e);
    } catch (UnreachableStoreException e) {
        clientRequestExecutor.close();
        if (logger.isDebugEnabled())
            debugMsgStr += "failure: " + e.getMessage();
        throw new UnreachableStoreException("Failure in " + operationName + " on " + destination + ": " + e.getMessage(), e.getCause());
    } finally {
        if (blockingClientRequest != null && !blockingClientRequest.isComplete()) {
            // close the executor if we timed out
            clientRequestExecutor.close();
        }
        // Record operation time
        long opTimeNs = Utils.elapsedTimeNs(startTimeNs, System.nanoTime());
        if (stats != null) {
            stats.recordSyncOpTimeNs(destination, opTimeNs);
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Sync request end, type: " + operationName + " requestRef: " + System.identityHashCode(delegate) + " totalTimeNs: " + opTimeNs + " start time: " + startTimeMs + " end time: " + System.currentTimeMillis() + " client:" + clientRequestExecutor.getSocketChannel().socket().getLocalAddress() + ":" + clientRequestExecutor.getSocketChannel().socket().getLocalPort() + " server: " + clientRequestExecutor.getSocketChannel().socket().getRemoteSocketAddress() + " outcome: " + debugMsgStr);
        }
        pool.checkin(destination, clientRequestExecutor);
    }
}
Also used : ClientRequestExecutor(voldemort.store.socket.clientrequest.ClientRequestExecutor) UnreachableStoreException(voldemort.store.UnreachableStoreException)

Example 22 with UnreachableStoreException

use of voldemort.store.UnreachableStoreException in project voldemort by voldemort.

the class StreamingSlopPusherTest method replaceOneNode.

private void replaceOneNode(int nodeId) throws IOException {
    Cluster oldCluster = cluster;
    cluster = ServerTestUtils.getLocalClusterWithOneNodeReplaced(cluster, nodeId);
    metadataStore = ServerTestUtils.createMetadataStore(cluster, new StoreDefinitionsMapper().readStoreList(new File(storesXmlfile)));
    String newClusterXml = new ClusterMapper().writeCluster(cluster);
    AdminClient adminClient = ServerTestUtils.getAdminClient(oldCluster);
    for (Integer remoteNodeId : oldCluster.getNodeIds()) {
        try {
            adminClient.metadataMgmtOps.updateRemoteMetadata(remoteNodeId, MetadataStore.CLUSTER_KEY, newClusterXml);
        } catch (UnreachableStoreException e) {
        }
    }
}
Also used : StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) Cluster(voldemort.cluster.Cluster) ClusterMapper(voldemort.xml.ClusterMapper) UnreachableStoreException(voldemort.store.UnreachableStoreException) File(java.io.File) AdminClient(voldemort.client.protocol.admin.AdminClient)

Example 23 with UnreachableStoreException

use of voldemort.store.UnreachableStoreException in project voldemort by voldemort.

the class ClientRequestExecutorPoolTest method testRememberedExceptionsBeyondTime.

@Test
public void testRememberedExceptionsBeyondTime() throws Exception {
    final int CURRENT_CONNECTION_TIMEOUT = 50;
    ClientRequestExecutorPool timeoutPool = new ClientRequestExecutorPool(2, maxConnectionsPerNode, CURRENT_CONNECTION_TIMEOUT, CURRENT_CONNECTION_TIMEOUT, IDLE_CONNECTION_TIMEOUT_MS, 32 * 1024, false, true, new String());
    ConnectException connectEx = new ConnectException("Connect exception");
    UnreachableStoreException unreachableEx = new UnreachableStoreException("test Exception", connectEx);
    final int COUNT = 10;
    for (int i = 0; i < COUNT; i++) {
        timeoutPool.internalGetQueuedPool().reportException(dest1, unreachableEx);
    }
    Thread.sleep(CURRENT_CONNECTION_TIMEOUT);
    // Get all exceptions but 1.
    for (int i = 0; i < COUNT - 1; i++) {
        try {
            timeoutPool.internalGetQueuedPool().checkout(dest1);
            fail("should have thrown an exception");
        } catch (Exception ex) {
        }
    }
    Thread.sleep(CURRENT_CONNECTION_TIMEOUT + 1);
    // should not fail
    timeoutPool.checkout(dest1);
}
Also used : ClientRequestExecutorPool(voldemort.store.socket.clientrequest.ClientRequestExecutorPool) UnreachableStoreException(voldemort.store.UnreachableStoreException) ConnectException(java.net.ConnectException) UnreachableStoreException(voldemort.store.UnreachableStoreException) IOException(java.io.IOException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Example 24 with UnreachableStoreException

use of voldemort.store.UnreachableStoreException 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 25 with UnreachableStoreException

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

Aggregations

UnreachableStoreException (voldemort.store.UnreachableStoreException)45 Node (voldemort.cluster.Node)19 ByteArray (voldemort.utils.ByteArray)13 Test (org.junit.Test)11 IOException (java.io.IOException)10 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)10 VoldemortException (voldemort.VoldemortException)7 InsufficientOperationalNodesException (voldemort.store.InsufficientOperationalNodesException)7 DataInputStream (java.io.DataInputStream)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 DataOutputStream (java.io.DataOutputStream)5 ConnectException (java.net.ConnectException)5 HttpPost (org.apache.http.client.methods.HttpPost)5 Versioned (voldemort.versioning.Versioned)5 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)4 ExecutionException (java.util.concurrent.ExecutionException)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 VoldemortApplicationException (voldemort.VoldemortApplicationException)4 NonblockingStoreCallback (voldemort.store.nonblockingstore.NonblockingStoreCallback)4 UnknownHostException (java.net.UnknownHostException)3