Skip to content

Commit

Permalink
bug fixes in coordinator
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongjiewu committed Jun 24, 2013
1 parent 93b9495 commit 33ea454
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 17 deletions.
14 changes: 7 additions & 7 deletions src/java/voldemort/coordinator/DynamicTimeoutStoreClient.java
Expand Up @@ -138,13 +138,14 @@ public Version putWithCustomTimeout(CompositeVoldemortRequest<K, V> requestWrapp

// This should not happen unless there's a bug in the
// getWithCustomTimeout
if((endTime - startTime) > requestWrapper.getRoutingTimeoutInMs()) {
long timeLeft = requestWrapper.getRoutingTimeoutInMs() - (endTime - startTime);
if(timeLeft <= 0) {
throw new StoreTimeoutException("PUT request timed out");
}

return putVersionedWithCustomTimeout(new CompositeVersionedPutVoldemortRequest<K, V>(requestWrapper.getKey(),
versioned,
(requestWrapper.getRoutingTimeoutInMs() - (endTime - startTime))));
timeLeft));
}

/**
Expand Down Expand Up @@ -227,19 +228,18 @@ public boolean deleteWithCustomTimeout(CompositeVoldemortRequest<K, V> deleteReq
return false;
}

long endTimeInMs = System.currentTimeMillis();
long diffInMs = endTimeInMs - startTimeInMs;
long timeLeft = deleteRequestObject.getRoutingTimeoutInMs()
- (System.currentTimeMillis() - startTimeInMs);

// This should not happen unless there's a bug in the
// getWithCustomTimeout
if(diffInMs > deleteRequestObject.getRoutingTimeoutInMs()) {
if(timeLeft < 0) {
throw new StoreTimeoutException("DELETE request timed out");
}

// Update the version and the new timeout
deleteRequestObject.setVersion(versioned.getVersion());
deleteRequestObject.setRoutingTimeoutInMs(deleteRequestObject.getRoutingTimeoutInMs()
- diffInMs);
deleteRequestObject.setRoutingTimeoutInMs(timeLeft);

}

Expand Down
21 changes: 21 additions & 0 deletions src/java/voldemort/coordinator/HttpDeleteRequestExecutor.java
Expand Up @@ -23,17 +23,20 @@
import static org.jboss.netty.handler.codec.http.HttpResponseStatus.REQUEST_TIMEOUT;
import static org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
import org.jboss.netty.handler.codec.http.HttpResponse;

import voldemort.VoldemortException;
import voldemort.store.CompositeVoldemortRequest;
import voldemort.store.InsufficientOperationalNodesException;
import voldemort.store.StoreTimeoutException;
import voldemort.store.stats.StoreStats;
import voldemort.store.stats.Tracked;
import voldemort.utils.ByteArray;
import voldemort.utils.Time;

/**
* A Runnable class that uses the specified Fat client to perform a Voldemort
Expand Down Expand Up @@ -109,6 +112,24 @@ public void run() {
RESTErrorHandler.handleError(REQUEST_TIMEOUT,
this.deleteRequestMessageEvent,
errorDescription);
} catch(InsufficientOperationalNodesException exception) {
long currentTimeInNs = System.nanoTime();
if(currentTimeInNs - startTimestampInNs > deleteRequestObject.getRoutingTimeoutInMs()
* Time.NS_PER_MS) {
String errorDescription = "DELETE Request timed out: " + exception.getMessage();
if(logger.isEnabledFor(Level.ERROR)) {
logger.error(errorDescription);
}
RESTErrorHandler.handleError(REQUEST_TIMEOUT,
this.deleteRequestMessageEvent,
errorDescription);
} else {
String errorDescription = "Voldemort Exception: " + exception.getMessage();
RESTErrorHandler.handleError(INTERNAL_SERVER_ERROR,
this.deleteRequestMessageEvent,
errorDescription);
}

} catch(VoldemortException ve) {
ve.printStackTrace();
String errorDescription = "Voldemort Exception: " + ve.getMessage();
Expand Down
18 changes: 18 additions & 0 deletions src/java/voldemort/coordinator/HttpGetAllRequestExecutor.java
Expand Up @@ -50,10 +50,12 @@

import voldemort.VoldemortException;
import voldemort.store.CompositeVoldemortRequest;
import voldemort.store.InsufficientOperationalNodesException;
import voldemort.store.StoreTimeoutException;
import voldemort.store.stats.StoreStats;
import voldemort.store.stats.Tracked;
import voldemort.utils.ByteArray;
import voldemort.utils.Time;
import voldemort.versioning.VectorClock;
import voldemort.versioning.Versioned;

Expand Down Expand Up @@ -202,6 +204,22 @@ public void run() {
RESTErrorHandler.handleError(REQUEST_TIMEOUT,
this.getRequestMessageEvent,
errorDescription);
} catch(InsufficientOperationalNodesException exception) {
long nowInNs = System.nanoTime();
if(nowInNs - startTimestampInNs > getAllRequestObject.getRoutingTimeoutInMs()
* Time.NS_PER_MS) {
String errorDescription = "GET Request timed out: " + exception.getMessage();
logger.error(errorDescription);
RESTErrorHandler.handleError(REQUEST_TIMEOUT,
this.getRequestMessageEvent,
errorDescription);
} else {
String errorDescription = "Voldemort Exception: " + exception.getMessage();
RESTErrorHandler.handleError(INTERNAL_SERVER_ERROR,
this.getRequestMessageEvent,
errorDescription);
}

} catch(VoldemortException ve) {
String errorDescription = "Voldemort Exception: " + ve.getMessage();
RESTErrorHandler.handleError(INTERNAL_SERVER_ERROR,
Expand Down
18 changes: 18 additions & 0 deletions src/java/voldemort/coordinator/HttpGetRequestExecutor.java
Expand Up @@ -36,10 +36,12 @@

import voldemort.VoldemortException;
import voldemort.store.CompositeVoldemortRequest;
import voldemort.store.InsufficientOperationalNodesException;
import voldemort.store.StoreTimeoutException;
import voldemort.store.stats.StoreStats;
import voldemort.store.stats.Tracked;
import voldemort.utils.ByteArray;
import voldemort.utils.Time;
import voldemort.versioning.VectorClock;
import voldemort.versioning.Versioned;

Expand Down Expand Up @@ -165,6 +167,22 @@ public void run() {
RESTErrorHandler.handleError(REQUEST_TIMEOUT,
this.getRequestMessageEvent,
errorDescription);
} catch(InsufficientOperationalNodesException exception) {
long nowInNs = System.nanoTime();
if(nowInNs - startTimestampInNs > getRequestObject.getRoutingTimeoutInMs()
* Time.NS_PER_MS) {
String errorDescription = "GET Request timed out: " + exception.getMessage();
logger.error(errorDescription);
RESTErrorHandler.handleError(REQUEST_TIMEOUT,
this.getRequestMessageEvent,
errorDescription);
} else {
String errorDescription = "Voldemort Exception: " + exception.getMessage();
RESTErrorHandler.handleError(INTERNAL_SERVER_ERROR,
this.getRequestMessageEvent,
errorDescription);
}

} catch(VoldemortException ve) {
String errorDescription = "Voldemort Exception: " + ve.getMessage();
RESTErrorHandler.handleError(INTERNAL_SERVER_ERROR,
Expand Down
18 changes: 18 additions & 0 deletions src/java/voldemort/coordinator/HttpPutRequestExecutor.java
Expand Up @@ -32,10 +32,12 @@

import voldemort.VoldemortException;
import voldemort.store.CompositeVoldemortRequest;
import voldemort.store.InsufficientOperationalNodesException;
import voldemort.store.StoreTimeoutException;
import voldemort.store.stats.StoreStats;
import voldemort.store.stats.Tracked;
import voldemort.utils.ByteArray;
import voldemort.utils.Time;
import voldemort.versioning.ObsoleteVersionException;
import voldemort.versioning.VectorClock;

Expand Down Expand Up @@ -150,6 +152,22 @@ public void run() {
this.putRequestMessageEvent,
errorDescription);

} catch(InsufficientOperationalNodesException exception) {
long nowInNs = System.nanoTime();
if(nowInNs - startTimestampInNs > putRequestObject.getRoutingTimeoutInMs()
* Time.NS_PER_MS) {
String errorDescription = "GET Request timed out: " + exception.getMessage();
logger.error(errorDescription);
RESTErrorHandler.handleError(REQUEST_TIMEOUT,
this.putRequestMessageEvent,
errorDescription);
} else {
String errorDescription = "Voldemort Exception: " + exception.getMessage();
RESTErrorHandler.handleError(INTERNAL_SERVER_ERROR,
this.putRequestMessageEvent,
errorDescription);
}

} catch(VoldemortException ve) {
String errorDescription = "Voldemort Exception: " + ve.getMessage();
RESTErrorHandler.handleError(INTERNAL_SERVER_ERROR,
Expand Down
Expand Up @@ -100,7 +100,7 @@ private CompositeVoldemortRequest<ByteArray, byte[]> parseRequest(String request
String timeoutValStr = this.request.getHeader(X_VOLD_REQUEST_TIMEOUT_MS);
if(timeoutValStr != null) {
try {
Long.parseLong(timeoutValStr);
operationTimeoutInMs = Long.parseLong(timeoutValStr);
} catch(NumberFormatException nfe) {
handleBadRequest(e, "Incorrect timeout parameter. Cannot parse this to long: "
+ timeoutValStr + ". Details: " + nfe.getMessage());
Expand Down

0 comments on commit 33ea454

Please sign in to comment.