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) {
}
}
}
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);
}
}
}
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");
}
}
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);
}
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();
}
}
Aggregations