use of voldemort.utils.ByteArray in project voldemort by voldemort.
the class AdminServiceRequestHandler method handleSetMetadata.
public VAdminProto.UpdateMetadataResponse handleSetMetadata(VAdminProto.UpdateMetadataRequest request) {
VAdminProto.UpdateMetadataResponse.Builder response = VAdminProto.UpdateMetadataResponse.newBuilder();
try {
ByteArray keyBytes = ProtoUtils.decodeBytes(request.getKey());
String keyString = ByteUtils.getString(keyBytes.get(), "UTF-8");
if (MetadataStore.METADATA_KEYS.contains(keyString)) {
Versioned<byte[]> versionedValue = ProtoUtils.decodeVersioned(request.getVersioned());
logger.info("Updating metadata for key '" + keyString + "'");
metadataStore.validate(keyBytes, versionedValue, null);
metadataStore.put(keyBytes, versionedValue, null);
if (MetadataStore.CLUSTER_KEY.equals(keyString)) {
server.handleClusterUpdate();
} else if (MetadataStore.NODE_ID_KEY.endsWith(keyString)) {
server.refreshNodeIdFromMetadata();
}
logger.info("Successfully updated metadata for key '" + keyString + "'");
}
} catch (VoldemortException e) {
response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
logger.error("handleUpdateMetadata failed for request(" + request.toString() + ")", e);
}
return response.build();
}
use of voldemort.utils.ByteArray 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.utils.ByteArray in project voldemort by voldemort.
the class ProtoBuffRequestHandler method handlePut.
private VProto.PutResponse handlePut(VProto.PutRequest request, Store<ByteArray, byte[], byte[]> store) {
VProto.PutResponse.Builder response = VProto.PutResponse.newBuilder();
try {
ByteArray key = ProtoUtils.decodeBytes(request.getKey());
Versioned<byte[]> value = ProtoUtils.decodeVersioned(request.getVersioned());
store.put(key, value, request.hasTransforms() ? ProtoUtils.decodeBytes(request.getTransforms()).get() : null);
} catch (VoldemortException e) {
response.setError(ProtoUtils.encodeError(getErrorMapper(), e));
}
return response.build();
}
use of voldemort.utils.ByteArray 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.utils.ByteArray in project voldemort by voldemort.
the class FullScanFetchKeysRequestHandler method handleRequest.
@Override
public StreamRequestHandlerState handleRequest(DataInputStream inputStream, DataOutputStream outputStream) throws IOException {
if (!keyIterator.hasNext()) {
return StreamRequestHandlerState.COMPLETE;
}
// NOTE: Storage time is accounted for somewhat incorrectly because
// .hasNext() is invoked at end of method for the common case.
long startNs = System.nanoTime();
ByteArray key = keyIterator.next();
reportStorageOpTime(startNs);
throttler.maybeThrottle(key.length());
if (isItemAccepted(key.get())) {
if (filter.accept(key, null)) {
accountForFetchedKey(key.get());
VAdminProto.FetchPartitionEntriesResponse.Builder response = VAdminProto.FetchPartitionEntriesResponse.newBuilder();
response.setKey(ProtoUtils.encodeBytes(key));
Message message = response.build();
sendMessage(outputStream, message);
}
}
accountForScanProgress("keys");
return determineRequestHandlerState("keys");
}
Aggregations