} else {
keyExists = true;
}
if(keyExists) {
GetResponseSender responseConstructor = new GetResponseSender(messageEvent,
requestObject.getKey(),
versionedValues,
this.storeClient.getStoreName());
responseConstructor.sendResponse(this.coordinatorPerfStats,
true,
this.requestObject.getRequestOriginTimeInMs());
if(logger.isDebugEnabled()) {
logger.debug("GET successful !");
}
} else {
RestErrorHandler.writeErrorResponse(this.messageEvent,
NOT_FOUND,
"Requested Key does not exist");
}
} catch(Exception e) {
/*
* We might get InsufficientOperationalNodes
* exception due to a timeout, thus creating
* confusion in the root cause. Hence explicitly
* check for timeout.
*/
if(System.currentTimeMillis() >= (this.requestObject.getRequestOriginTimeInMs() + this.requestObject.getRoutingTimeoutInMs())) {
RestErrorHandler.writeErrorResponse(this.messageEvent,
REQUEST_TIMEOUT,
"GET request timed out: "
+ e.getMessage());
} else {
getErrorHandler.handleExceptions(messageEvent, e);
}
}
break;
case VoldemortOpCode.GET_ALL_OP_CODE:
if(logger.isDebugEnabled()) {
logger.debug("GET ALL request received.");
}
try {
Map<ByteArray, List<Versioned<byte[]>>> versionedResponses = this.storeClient.getAllWithCustomTimeout(this.requestObject);
if(versionedResponses == null
|| versionedResponses.values().size() == 0) {
logger.error("Error when doing getall. Keys do not exist.");
RestErrorHandler.writeErrorResponse(this.messageEvent,
NOT_FOUND,
"Error when doing getall. Keys do not exist.");
} else {
GetAllResponseSender responseConstructor = new GetAllResponseSender(messageEvent,
versionedResponses,
this.storeClient.getStoreName());
responseConstructor.sendResponse(this.coordinatorPerfStats,
true,
this.requestObject.getRequestOriginTimeInMs());
if(logger.isDebugEnabled()) {
logger.debug("GET ALL successful !");
}
}
} catch(Exception e) {
/*
* We might get InsufficientOperationalNodes
* exception due to a timeout, thus creating
* confusion in the root cause. Hence explicitly
* check for timeout.
*/
if(System.currentTimeMillis() >= (this.requestObject.getRequestOriginTimeInMs() + this.requestObject.getRoutingTimeoutInMs())) {
RestErrorHandler.writeErrorResponse(this.messageEvent,
REQUEST_TIMEOUT,
"GET ALL request timed out: "
+ e.getMessage());
} else {
getErrorHandler.handleExceptions(messageEvent, e);
}
}
break;
// TODO: Implement this in the next pass
case VoldemortOpCode.GET_VERSION_OP_CODE:
if(logger.isDebugEnabled()) {
logger.debug("Incoming get version request");
}
try {
if(logger.isDebugEnabled()) {
logger.debug("GET versions request successful !");
}
} catch(Exception e) {
/*
* We might get InsufficientOperationalNodes
* exception due to a timeout, thus creating
* confusion in the root cause. Hence explicitly
* check for timeout.
*/
if(System.currentTimeMillis() >= (this.requestObject.getRequestOriginTimeInMs() + this.requestObject.getRoutingTimeoutInMs())) {
RestErrorHandler.writeErrorResponse(this.messageEvent,
REQUEST_TIMEOUT,
"GET VERSION request timed out: "
+ e.getMessage());
} else {
getVersionErrorHandler.handleExceptions(messageEvent, e);
}
}
break;
case VoldemortOpCode.PUT_OP_CODE:
if(logger.isDebugEnabled()) {
logger.debug("PUT request received.");
}
try {
VectorClock successfulPutVC = null;
if(this.requestObject.getValue() != null) {
successfulPutVC = ((VectorClock) this.storeClient.putVersionedWithCustomTimeout(this.requestObject)).clone();
} else {
successfulPutVC = ((VectorClock) this.storeClient.putWithCustomTimeout(this.requestObject)).clone();
}
PutResponseSender responseConstructor = new PutResponseSender(messageEvent,
successfulPutVC,
this.storeClient.getStoreName(),
this.requestObject.getKey());
responseConstructor.sendResponse(this.coordinatorPerfStats,
true,
this.requestObject.getRequestOriginTimeInMs());
if(logger.isDebugEnabled()) {
logger.debug("PUT successful !");
}
} catch(Exception e) {
/*
* We might get InsufficientOperationalNodes
* exception due to a timeout, thus creating
* confusion in the root cause. Hence explicitly
* check for timeout.
*/
if(System.currentTimeMillis() >= (this.requestObject.getRequestOriginTimeInMs() + this.requestObject.getRoutingTimeoutInMs())) {
RestErrorHandler.writeErrorResponse(this.messageEvent,
REQUEST_TIMEOUT,
"PUT request timed out: "
+ e.getMessage());
} else {
putErrorHandler.handleExceptions(messageEvent, e);
}
}
break;
case VoldemortOpCode.DELETE_OP_CODE:
if(logger.isDebugEnabled()) {
logger.debug("Incoming delete request");
}
try {
boolean isDeleted = this.storeClient.deleteWithCustomTimeout(this.requestObject);
if(isDeleted) {
DeleteResponseSender responseConstructor = new DeleteResponseSender(messageEvent,
this.storeClient.getStoreName(),
this.requestObject.getKey());
responseConstructor.sendResponse(this.coordinatorPerfStats,
true,
this.requestObject.getRequestOriginTimeInMs());
if(logger.isDebugEnabled()) {
logger.debug("DELETE request successful !");