Search in sources :

Example 1 with SocketDestination

use of voldemort.store.socket.SocketDestination in project voldemort by voldemort.

the class ClientSocketStats method close.

/**
 * Unregister all MBeans
 */
public void close() {
    Iterator<SocketDestination> it = getStatsMap().keySet().iterator();
    while (it.hasNext()) {
        try {
            SocketDestination destination = it.next();
            JmxUtils.unregisterMbean(JmxUtils.createObjectName(JmxUtils.getPackageName(ClientRequestExecutor.class), "stats_" + destination.toString().replace(':', '_') + identifierString));
        } catch (Exception e) {
        }
    }
}
Also used : SocketDestination(voldemort.store.socket.SocketDestination)

Example 2 with SocketDestination

use of voldemort.store.socket.SocketDestination in project voldemort by voldemort.

the class BaseStreamingClient method blacklistNode.

/**
 * mark a node as blacklisted
 *
 * @param nodeId Integer node id of the node to be blacklisted
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public void blacklistNode(int nodeId) {
    Collection<Node> nodesInCluster = adminClient.getAdminClientCluster().getNodes();
    if (blackListedNodes == null) {
        blackListedNodes = new ArrayList();
    }
    blackListedNodes.add(nodeId);
    for (Node node : nodesInCluster) {
        if (node.getId() == nodeId) {
            nodesToStream.remove(node);
            break;
        }
    }
    for (String store : storeNames) {
        try {
            SocketAndStreams sands = nodeIdStoreToSocketAndStreams.get(new Pair(store, nodeId));
            close(sands.getSocket());
            SocketDestination destination = nodeIdStoreToSocketRequest.get(new Pair(store, nodeId));
            streamingSocketPool.checkin(destination, sands);
        } catch (Exception ioE) {
            logger.error(ioE);
        }
    }
}
Also used : SocketDestination(voldemort.store.socket.SocketDestination) Node(voldemort.cluster.Node) ArrayList(java.util.ArrayList) InsufficientOperationalNodesException(voldemort.store.InsufficientOperationalNodesException) VoldemortException(voldemort.VoldemortException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Pair(voldemort.utils.Pair)

Example 3 with SocketDestination

use of voldemort.store.socket.SocketDestination in project voldemort by voldemort.

the class BaseStreamingClient method addStoreToSession.

/**
 * Add another store destination to an existing streaming session
 *
 * @param store the name of the store to stream to
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void addStoreToSession(String store) {
    Exception initializationException = null;
    storeNames.add(store);
    for (Node node : nodesToStream) {
        SocketDestination destination = null;
        SocketAndStreams sands = null;
        try {
            destination = new SocketDestination(node.getHost(), node.getAdminPort(), RequestFormatType.ADMIN_PROTOCOL_BUFFERS);
            sands = streamingSocketPool.checkout(destination);
            DataOutputStream outputStream = sands.getOutputStream();
            DataInputStream inputStream = sands.getInputStream();
            nodeIdStoreToSocketRequest.put(new Pair(store, node.getId()), destination);
            nodeIdStoreToOutputStreamRequest.put(new Pair(store, node.getId()), outputStream);
            nodeIdStoreToInputStreamRequest.put(new Pair(store, node.getId()), inputStream);
            nodeIdStoreToSocketAndStreams.put(new Pair(store, node.getId()), sands);
            nodeIdStoreInitialized.put(new Pair(store, node.getId()), false);
            remoteStoreDefs = adminClient.metadataMgmtOps.getRemoteStoreDefList(node.getId()).getValue();
        } catch (Exception e) {
            logger.error(e);
            try {
                close(sands.getSocket());
                streamingSocketPool.checkin(destination, sands);
            } catch (Exception ioE) {
                logger.error(ioE);
            }
            if (!faultyNodes.contains(node.getId()))
                faultyNodes.add(node.getId());
            initializationException = e;
        }
    }
    if (initializationException != null)
        throw new VoldemortException(initializationException);
    if (store.equals("slop"))
        return;
    boolean foundStore = false;
    for (StoreDefinition remoteStoreDef : remoteStoreDefs) {
        if (remoteStoreDef.getName().equals(store)) {
            RoutingStrategyFactory factory = new RoutingStrategyFactory();
            RoutingStrategy storeRoutingStrategy = factory.updateRoutingStrategy(remoteStoreDef, adminClient.getAdminClientCluster());
            storeToRoutingStrategy.put(store, storeRoutingStrategy);
            validateSufficientNodesAvailable(blackListedNodes, remoteStoreDef);
            foundStore = true;
            break;
        }
    }
    if (!foundStore) {
        logger.error("Store Name not found on the cluster");
        throw new VoldemortException("Store Name not found on the cluster");
    }
}
Also used : SocketDestination(voldemort.store.socket.SocketDestination) DataOutputStream(java.io.DataOutputStream) RoutingStrategyFactory(voldemort.routing.RoutingStrategyFactory) Node(voldemort.cluster.Node) StoreDefinition(voldemort.store.StoreDefinition) RoutingStrategy(voldemort.routing.RoutingStrategy) DataInputStream(java.io.DataInputStream) VoldemortException(voldemort.VoldemortException) InsufficientOperationalNodesException(voldemort.store.InsufficientOperationalNodesException) VoldemortException(voldemort.VoldemortException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Pair(voldemort.utils.Pair)

Example 4 with SocketDestination

use of voldemort.store.socket.SocketDestination in project voldemort by voldemort.

the class SocketStoreClientFactory method initFailureDetector.

@Override
protected FailureDetector initFailureDetector(final ClientConfig config, Cluster cluster) {
    failureDetectorListener = new FailureDetectorListener() {

        public void nodeAvailable(Node node) {
        }

        public void nodeUnavailable(Node node) {
            if (logger.isInfoEnabled())
                logger.info(node + " has been marked as unavailable, destroying socket pool");
            // Kill the socket pool for this node...
            SocketDestination destination = new SocketDestination(node.getHost(), node.getSocketPort(), config.getRequestFormatType());
            storeFactory.close(destination);
        }
    };
    ClientStoreConnectionVerifier verifier = new ClientStoreConnectionVerifier() {

        @Override
        protected Store<ByteArray, byte[], byte[]> getStoreInternal(Node node) {
            logger.debug("Returning a new store verifier for node: " + node);
            return SocketStoreClientFactory.this.getStore(MetadataStore.METADATA_STORE_NAME, node.getHost(), node.getSocketPort(), config.getRequestFormatType());
        }
    };
    FailureDetectorConfig failureDetectorConfig = new FailureDetectorConfig(config).setCluster(cluster).setConnectionVerifier(verifier);
    return create(failureDetectorConfig, false, failureDetectorListener);
}
Also used : FailureDetectorListener(voldemort.cluster.failuredetector.FailureDetectorListener) SocketDestination(voldemort.store.socket.SocketDestination) Node(voldemort.cluster.Node) FailureDetectorConfig(voldemort.cluster.failuredetector.FailureDetectorConfig) ClientStoreConnectionVerifier(voldemort.cluster.failuredetector.ClientStoreConnectionVerifier) ByteArray(voldemort.utils.ByteArray)

Example 5 with SocketDestination

use of voldemort.store.socket.SocketDestination in project voldemort by voldemort.

the class SimpleSocketPoolTest method testClientRequestExecutorLimitSomeTimeout.

@Test
public void testClientRequestExecutorLimitSomeTimeout() throws Exception {
    // start a dummy server
    AbstractSocketService server = ServerTestUtils.getSocketService(useNio, new ClientRequestHandlerFactory(null), 7666, 50, 50, 1000);
    server.start();
    final ResourcePoolConfig config = new ResourcePoolConfig().setTimeout(50, TimeUnit.MILLISECONDS).setMaxPoolSize(20);
    ClientRequestExecutorPool clientRequestExecutorPool = new ClientRequestExecutorPool(config.getMaxPoolSize(), (int) config.getTimeout(TimeUnit.MILLISECONDS), 100, 1000);
    try {
        ResourceFactory<SocketDestination, ClientRequestExecutor> factory = clientRequestExecutorPool.getFactory();
        final AbstractSocketPoolTest<SocketDestination, ClientRequestExecutor> test = new AbstractSocketPoolTest<SocketDestination, ClientRequestExecutor>() {

            @Override
            protected void doSomethingWithResource(SocketDestination key, ClientRequestExecutor resource) throws Exception {
                Thread.sleep(100);
                int random = (int) (Math.random() * 10);
                if (random >= 5)
                    resource.close();
            }

            @Override
            protected SocketDestination getRequestKey() throws Exception {
                return new SocketDestination("localhost", 7666, RequestFormatType.VOLDEMORT_V1);
            }
        };
        // borrow timeout >> doSomething() no timeout expected
        TestStats testStats = test.startTest(factory, config, 50, 200);
        assertEquals("We should see some timeoutRequests", true, testStats.timeoutRequests > 0);
        server.stop();
    } finally {
        clientRequestExecutorPool.close();
    }
}
Also used : SocketDestination(voldemort.store.socket.SocketDestination) ClientRequestExecutorPool(voldemort.store.socket.clientrequest.ClientRequestExecutorPool) ClientRequestHandlerFactory(voldemort.server.protocol.ClientRequestHandlerFactory) ClientRequestExecutor(voldemort.store.socket.clientrequest.ClientRequestExecutor) AbstractSocketService(voldemort.server.AbstractSocketService) TestStats(voldemort.socketpool.AbstractSocketPoolTest.TestStats) ResourcePoolConfig(voldemort.utils.pool.ResourcePoolConfig) Test(org.junit.Test)

Aggregations

SocketDestination (voldemort.store.socket.SocketDestination)14 Test (org.junit.Test)5 Before (org.junit.Before)4 Node (voldemort.cluster.Node)4 IOException (java.io.IOException)3 ExecutionException (java.util.concurrent.ExecutionException)3 VoldemortException (voldemort.VoldemortException)3 InsufficientOperationalNodesException (voldemort.store.InsufficientOperationalNodesException)3 ClientRequestExecutorPool (voldemort.store.socket.clientrequest.ClientRequestExecutorPool)3 Pair (voldemort.utils.Pair)3 SocketAndStreams (voldemort.client.protocol.admin.SocketAndStreams)2 AbstractSocketService (voldemort.server.AbstractSocketService)2 StoreRepository (voldemort.server.StoreRepository)2 ClientRequestHandlerFactory (voldemort.server.protocol.ClientRequestHandlerFactory)2 TestStats (voldemort.socketpool.AbstractSocketPoolTest.TestStats)2 ByteArray (voldemort.utils.ByteArray)2 ResourcePoolConfig (voldemort.utils.pool.ResourcePoolConfig)2 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 ArrayList (java.util.ArrayList)1