Skip to content

Commit

Permalink
Changed both serial (sync) operations and parallel (async) operations…
Browse files Browse the repository at this point in the history
… to deduct the elapsed checkout time from the operation (routing) timeout for specific requests.
  • Loading branch information
jayjwylie committed Oct 11, 2012
1 parent bb73de1 commit a34e62a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/java/voldemort/store/socket/SocketStore.java
Expand Up @@ -263,22 +263,24 @@ public void close() throws VoldemortException {
*/

private <T> T request(ClientRequest<T> delegate, String operationName) {
ClientRequestExecutor clientRequestExecutor = pool.checkout(destination);

long startTimeMs = -1;
long startTimeNs = -1;

if(logger.isDebugEnabled()) {
startTimeMs = System.currentTimeMillis();
startTimeNs = System.nanoTime();
}
startTimeNs = System.nanoTime();

ClientRequestExecutor clientRequestExecutor = pool.checkout(destination);

String debugMsgStr = "";

BlockingClientRequest<T> blockingClientRequest = null;
try {
blockingClientRequest = new BlockingClientRequest<T>(delegate, timeoutMs);
clientRequestExecutor.addClientRequest(blockingClientRequest, timeoutMs);
clientRequestExecutor.addClientRequest(blockingClientRequest,
timeoutMs,
System.nanoTime() - startTimeNs);
blockingClientRequest.await();

if(logger.isDebugEnabled())
Expand Down
Expand Up @@ -92,6 +92,12 @@ public synchronized void addClientRequest(ClientRequest<?> clientRequest) {
}

public synchronized void addClientRequest(ClientRequest<?> clientRequest, long timeoutMs) {
addClientRequest(clientRequest, timeoutMs, 0);
}

public synchronized void addClientRequest(ClientRequest<?> clientRequest,
long timeoutMs,
long elapsedNs) {
if(logger.isTraceEnabled())
logger.trace("Associating client with " + socketChannel.socket());

Expand All @@ -100,7 +106,11 @@ public synchronized void addClientRequest(ClientRequest<?> clientRequest, long t
if(timeoutMs == -1) {
this.expiration = -1;
} else {
this.expiration = System.nanoTime() + (Time.NS_PER_MS * timeoutMs);
if (elapsedNs > (Time.NS_PER_MS * timeoutMs)) {
this.expiration = System.nanoTime();
} else {
this.expiration = System.nanoTime() + (Time.NS_PER_MS * timeoutMs) - elapsedNs;
}

if(this.expiration < System.nanoTime())
throw new IllegalArgumentException("timeout " + timeoutMs + " not valid");
Expand Down
Expand Up @@ -298,7 +298,8 @@ public void useResource(ClientRequestExecutor clientRequestExecutor) {
delegate,
clientRequestExecutor,
callback);
clientRequestExecutor.addClientRequest(clientRequest, timeoutMs);
clientRequestExecutor.addClientRequest(clientRequest, timeoutMs, System.nanoTime()
- startTimeNs);
}

@Override
Expand Down

0 comments on commit a34e62a

Please sign in to comment.