Search in sources :

Example 51 with ByteArray

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();
}
Also used : ByteArray(voldemort.utils.ByteArray) VoldemortException(voldemort.VoldemortException)

Example 52 with ByteArray

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;
}
Also used : Message(com.google.protobuf.Message) RequestRoutingType(voldemort.server.RequestRoutingType) ByteArray(voldemort.utils.ByteArray) ByteString(com.google.protobuf.ByteString) VoldemortRequest(voldemort.client.protocol.pb.VProto.VoldemortRequest) VoldemortException(voldemort.VoldemortException)

Example 53 with ByteArray

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();
}
Also used : ByteArray(voldemort.utils.ByteArray) VoldemortException(voldemort.VoldemortException)

Example 54 with ByteArray

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;
}
Also used : ObsoleteVersionException(voldemort.versioning.ObsoleteVersionException) RequestRoutingType(voldemort.server.RequestRoutingType) ByteArray(voldemort.utils.ByteArray) VoldemortException(voldemort.VoldemortException)

Example 55 with ByteArray

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");
}
Also used : Message(com.google.protobuf.Message) ByteArray(voldemort.utils.ByteArray)

Aggregations

ByteArray (voldemort.utils.ByteArray)309 Versioned (voldemort.versioning.Versioned)130 Test (org.junit.Test)125 VoldemortException (voldemort.VoldemortException)67 VectorClock (voldemort.versioning.VectorClock)65 ArrayList (java.util.ArrayList)61 Node (voldemort.cluster.Node)61 List (java.util.List)58 HashMap (java.util.HashMap)53 StoreDefinition (voldemort.store.StoreDefinition)49 Cluster (voldemort.cluster.Cluster)33 AbstractByteArrayStoreTest (voldemort.store.AbstractByteArrayStoreTest)31 Store (voldemort.store.Store)31 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)31 IOException (java.io.IOException)30 Slop (voldemort.store.slop.Slop)29 Map (java.util.Map)28 Pair (voldemort.utils.Pair)28 UnreachableStoreException (voldemort.store.UnreachableStoreException)26 StatTrackingStore (voldemort.store.stats.StatTrackingStore)25