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