Search in sources :

Example 61 with VoldemortException

use of voldemort.VoldemortException 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 62 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class AdminServiceRequestHandler method handleDeleteStoreRebalanceState.

private VAdminProto.DeleteStoreRebalanceStateResponse handleDeleteStoreRebalanceState(VAdminProto.DeleteStoreRebalanceStateRequest request) {
    VAdminProto.DeleteStoreRebalanceStateResponse.Builder response = VAdminProto.DeleteStoreRebalanceStateResponse.newBuilder();
    synchronized (rebalancer) {
        try {
            int nodeId = request.getNodeId();
            String storeName = request.getStoreName();
            logger.info("Removing rebalancing state for donor node " + nodeId + " and store " + storeName + " from stealer node " + metadataStore.getNodeId());
            RebalanceTaskInfo info = metadataStore.getRebalancerState().find(nodeId);
            if (info == null) {
                throw new VoldemortException("Could not find state for donor node " + nodeId);
            }
            List<Integer> partitionIds = info.getPartitionIds(storeName);
            if (partitionIds.size() == 0) {
                throw new VoldemortException("Could not find state for donor node " + nodeId + " and store " + storeName);
            }
            info.removeStore(storeName);
            logger.info("Removed rebalancing state for donor node " + nodeId + " and store " + storeName + " from stealer node " + metadataStore.getNodeId());
            if (info.getPartitionStores().isEmpty()) {
                metadataStore.deleteRebalancingState(info);
                logger.info("Removed entire rebalancing state for donor node " + nodeId + " from stealer node " + metadataStore.getNodeId());
            }
        } catch (VoldemortException e) {
            response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
            logger.error("handleDeleteStoreRebalanceState failed for request(" + request.toString() + ")", e);
        }
    }
    return response.build();
}
Also used : VoldemortException(voldemort.VoldemortException) RebalanceTaskInfo(voldemort.client.rebalance.RebalanceTaskInfo)

Example 63 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class AdminServiceRequestHandler method handleGetROStorageFileList.

public VAdminProto.GetROStorageFileListResponse handleGetROStorageFileList(VAdminProto.GetROStorageFileListRequest request) {
    String storeName = request.getStoreName();
    VAdminProto.GetROStorageFileListResponse.Builder response = VAdminProto.GetROStorageFileListResponse.newBuilder();
    try {
        ReadOnlyStorageEngine store = getReadOnlyStorageEngine(metadataStore, storeRepository, storeName);
        ChunkedFileSet chunkedFileSet = store.getChunkedFileSet();
        response.addAllFileName(chunkedFileSet.getFileNames());
        response.addAllIndexFileSize(chunkedFileSet.getIndexFileSizes());
        response.addAllDataFileSize(chunkedFileSet.getDataFileSizes());
    } catch (VoldemortException e) {
        response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
        logger.error("handleGetROStorageFileList failed for request(" + request.toString() + ")", e);
    }
    return response.build();
}
Also used : ReadOnlyStorageEngine(voldemort.store.readonly.ReadOnlyStorageEngine) VoldemortException(voldemort.VoldemortException) ChunkedFileSet(voldemort.store.readonly.chunk.ChunkedFileSet)

Example 64 with VoldemortException

use of voldemort.VoldemortException 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 65 with VoldemortException

use of voldemort.VoldemortException 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)

Aggregations

VoldemortException (voldemort.VoldemortException)247 IOException (java.io.IOException)63 ByteArray (voldemort.utils.ByteArray)52 File (java.io.File)46 Node (voldemort.cluster.Node)42 StoreDefinition (voldemort.store.StoreDefinition)39 Versioned (voldemort.versioning.Versioned)38 ArrayList (java.util.ArrayList)34 Test (org.junit.Test)30 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)26 List (java.util.List)21 HashMap (java.util.HashMap)20 Cluster (voldemort.cluster.Cluster)20 VectorClock (voldemort.versioning.VectorClock)16 NoSuchCapabilityException (voldemort.store.NoSuchCapabilityException)15 ReadOnlyStorageEngine (voldemort.store.readonly.ReadOnlyStorageEngine)14 ExecutionException (java.util.concurrent.ExecutionException)13 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)13 Map (java.util.Map)12 Path (org.apache.hadoop.fs.Path)12