use of voldemort.server.RequestRoutingType in project voldemort by voldemort.
the class ProtoBuffRequestHandler method handleRequest.
@Override
public StreamRequestHandler handleRequest(final DataInputStream inputStream, final DataOutputStream outputStream, final ByteBufferContainer outputContainer) throws IOException {
VoldemortRequest.Builder request = ProtoUtils.readToBuilder(inputStream, VoldemortRequest.newBuilder());
boolean shouldRoute = request.getShouldRoute();
RequestRoutingType type = RequestRoutingType.getRequestRoutingType(shouldRoute, false);
if (request.hasRequestRouteType()) {
type = RequestRoutingType.getRequestRoutingType(request.getRequestRouteType());
}
String storeName = request.getStore();
Store<ByteArray, byte[], byte[]> store = getStore(storeName, type);
Message response;
if (store == null) {
response = unknownStore(storeName, request.getType());
} else {
switch(request.getType()) {
case GET:
response = handleGet(request.getGet(), store);
break;
case GET_ALL:
response = handleGetAll(request.getGetAll(), store);
break;
case PUT:
response = handlePut(request.getPut(), store);
break;
case DELETE:
response = handleDelete(request.getDelete(), store);
break;
case GET_VERSION:
response = handleGetVersion(request.getGet(), store);
break;
default:
throw new VoldemortException("Unknown operation " + request.getType());
}
}
if (outputContainer != null) {
outputContainer.getBuffer().clear();
outputContainer.ensureSpace(response.getSerializedSize());
}
ProtoUtils.writeMessage(outputStream, response);
return null;
}
use of voldemort.server.RequestRoutingType in project voldemort by voldemort.
the class VoldemortNativeRequestHandler method handleRequest.
@Override
public StreamRequestHandler handleRequest(final DataInputStream inputStream, final DataOutputStream outputStream, final ByteBufferContainer outputContainer) throws IOException {
long startTimeMs = -1;
long startTimeNs = -1;
if (logger.isDebugEnabled()) {
startTimeMs = System.currentTimeMillis();
startTimeNs = System.nanoTime();
}
byte opCode = inputStream.readByte();
String storeName = inputStream.readUTF();
RequestRoutingType routingType = getRoutingType(inputStream);
Store<ByteArray, byte[], byte[]> store = getStore(storeName, routingType);
if (store == null) {
clearBuffer(outputContainer);
writeException(outputStream, new VoldemortException("No store named: '" + storeName + "'."));
return null;
}
ClientRequestHandler requestHandler = getClientRequestHandler(opCode, store);
try {
requestHandler.parseRequest(inputStream);
requestHandler.processRequest();
} catch (VoldemortException e) {
// they are harmless and indicates normal mode of operation.
if (!(e instanceof ObsoleteVersionException)) {
logger.error("Store: " + storeName + ". Error: " + e.getMessage());
}
clearBuffer(outputContainer);
writeException(outputStream, e);
return null;
}
// We are done with Input, clear the buffers
clearBuffer(outputContainer);
int size = requestHandler.getResponseSize();
if (outputContainer != null) {
outputContainer.growBuffer(size);
}
requestHandler.writeResponse(outputStream);
outputStream.flush();
if (logger.isDebugEnabled()) {
String debugPrefix = "OpCode: " + opCode + ", started at: " + startTimeMs + ", handlerRef: " + System.identityHashCode(inputStream) + ", Elapsed : " + (System.nanoTime() - startTimeNs) + " ns, ";
logger.debug(debugPrefix + requestHandler.getDebugMessage());
}
return null;
}
use of voldemort.server.RequestRoutingType in project voldemort by voldemort.
the class VoldemortNativeRequestHandler method getRoutingType.
private RequestRoutingType getRoutingType(DataInputStream inputStream) throws IOException {
RequestRoutingType routingType = RequestRoutingType.NORMAL;
if (protocolVersion > 0) {
boolean isRouted = inputStream.readBoolean();
routingType = RequestRoutingType.getRequestRoutingType(isRouted, false);
}
if (protocolVersion > 1) {
int routingTypeCode = inputStream.readByte();
routingType = RequestRoutingType.getRequestRoutingType(routingTypeCode);
}
return routingType;
}
Aggregations