Search in sources :

Example 51 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class AdminServiceRequestHandler method handleAsyncStatus.

public VAdminProto.AsyncOperationStatusResponse handleAsyncStatus(VAdminProto.AsyncOperationStatusRequest request) {
    VAdminProto.AsyncOperationStatusResponse.Builder response = VAdminProto.AsyncOperationStatusResponse.newBuilder();
    try {
        int requestId = request.getRequestId();
        AsyncOperationStatus operationStatus = asyncService.getOperationStatus(requestId);
        boolean requestComplete = asyncService.isComplete(requestId);
        response.setDescription(operationStatus.getDescription());
        response.setComplete(requestComplete);
        response.setStatus(operationStatus.getStatus());
        response.setRequestId(requestId);
        if (operationStatus.hasException()) {
            String erroMessage = "HandleAsyncStatus received Exception: " + operationStatus.getException().getMessage();
            Exception exception = operationStatus.getException();
            if (exception instanceof VoldemortException) {
                throw (VoldemortException) exception;
            } else {
                throw new VoldemortException(erroMessage, exception);
            }
        }
    } catch (VoldemortException e) {
        response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
        logger.error("handleAsyncStatus failed for request(" + request.toString().trim() + ")", e);
    }
    return response.build();
}
Also used : VoldemortException(voldemort.VoldemortException) NoSuchCapabilityException(voldemort.store.NoSuchCapabilityException) ConfigurationException(voldemort.utils.ConfigurationException) ObsoleteVersionException(voldemort.versioning.ObsoleteVersionException) StoreOperationFailureException(voldemort.store.StoreOperationFailureException) VoldemortException(voldemort.VoldemortException) IOException(java.io.IOException) PersistenceFailureException(voldemort.store.PersistenceFailureException) StoreNotFoundException(voldemort.store.StoreNotFoundException)

Example 52 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class AdminServiceRequestHandler method handleGetROMaxVersionDir.

public VAdminProto.GetROMaxVersionDirResponse handleGetROMaxVersionDir(VAdminProto.GetROMaxVersionDirRequest request) {
    final List<String> storeNames = request.getStoreNameList();
    VAdminProto.GetROMaxVersionDirResponse.Builder response = VAdminProto.GetROMaxVersionDirResponse.newBuilder();
    try {
        for (String storeName : storeNames) {
            ReadOnlyStorageEngine store = getReadOnlyStorageEngine(metadataStore, storeRepository, storeName);
            File storeDirPath = new File(store.getStoreDirPath());
            if (!storeDirPath.exists())
                throw new VoldemortException("Unable to locate the directory of the read-only store " + storeName);
            File[] versionDirs = ReadOnlyUtils.getVersionDirs(storeDirPath);
            File[] kthDir = ReadOnlyUtils.findKthVersionedDir(versionDirs, versionDirs.length - 1, versionDirs.length - 1);
            VAdminProto.ROStoreVersionDirMap storeResponse = VAdminProto.ROStoreVersionDirMap.newBuilder().setStoreName(storeName).setStoreDir(kthDir[0].getAbsolutePath()).build();
            response.addRoStoreVersions(storeResponse);
        }
    } catch (VoldemortException e) {
        response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
        logger.error("handleGetROMaxVersion failed for request(" + request.toString() + ")", e);
    }
    return response.build();
}
Also used : ReadOnlyStorageEngine(voldemort.store.readonly.ReadOnlyStorageEngine) VAdminProto(voldemort.client.protocol.pb.VAdminProto) File(java.io.File) VoldemortException(voldemort.VoldemortException)

Example 53 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class SocketServerSession method run.

public void run() {
    try {
        activeSessions.put(sessionId, this);
        DataInputStream inputStream = new DataInputStream(new BufferedInputStream(socket.getInputStream(), 64000));
        DataOutputStream outputStream = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream(), 64000));
        RequestFormatType protocol = negotiateProtocol(inputStream, outputStream);
        RequestHandler handler = handlerFactory.getRequestHandler(protocol);
        logger.info("Client " + socket.getRemoteSocketAddress() + " connected successfully with protocol " + protocol.getCode());
        while (!isInterrupted() && !socket.isClosed() && !isClosed) {
            StreamRequestHandler srh = handler.handleRequest(inputStream, outputStream);
            if (srh != null) {
                if (logger.isTraceEnabled())
                    logger.trace("Request is streaming");
                StreamRequestHandlerState srhs = null;
                try {
                    do {
                        if (logger.isTraceEnabled())
                            logger.trace("About to enter streaming request handler");
                        srhs = srh.handleRequest(inputStream, outputStream);
                        if (logger.isTraceEnabled())
                            logger.trace("Finished invocation of streaming request handler, result is " + srhs);
                    } while (srhs != StreamRequestHandlerState.COMPLETE);
                } catch (VoldemortException e) {
                    srh.handleError(outputStream, e);
                    outputStream.flush();
                    break;
                } finally {
                    srh.close(outputStream);
                }
            }
            outputStream.flush();
        }
        if (isInterrupted())
            logger.info(Thread.currentThread().getName() + " has been interrupted, closing session.");
    } catch (EOFException e) {
        logger.info("Client " + socket.getRemoteSocketAddress() + " disconnected.");
    } catch (IOException e) {
        // if this is an unexpected
        if (!isClosed)
            logger.error(e);
    } finally {
        try {
            if (!socket.isClosed())
                socket.close();
        } catch (Exception e) {
            logger.error("Error while closing socket", e);
        }
        // now remove ourselves from the set of active sessions
        this.activeSessions.remove(sessionId);
    }
}
Also used : StreamRequestHandler(voldemort.server.protocol.StreamRequestHandler) StreamRequestHandler(voldemort.server.protocol.StreamRequestHandler) RequestHandler(voldemort.server.protocol.RequestHandler) BufferedInputStream(java.io.BufferedInputStream) DataOutputStream(java.io.DataOutputStream) EOFException(java.io.EOFException) RequestFormatType(voldemort.client.protocol.RequestFormatType) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) BufferedOutputStream(java.io.BufferedOutputStream) VoldemortException(voldemort.VoldemortException) VoldemortException(voldemort.VoldemortException) IOException(java.io.IOException) EOFException(java.io.EOFException) StreamRequestHandlerState(voldemort.server.protocol.StreamRequestHandler.StreamRequestHandlerState)

Example 54 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class AdminServiceRequestHandler method handleGetMetadata.

public VAdminProto.GetMetadataResponse handleGetMetadata(VAdminProto.GetMetadataRequest request) {
    VAdminProto.GetMetadataResponse.Builder response = VAdminProto.GetMetadataResponse.newBuilder();
    try {
        ByteArray key = ProtoUtils.decodeBytes(request.getKey());
        String keyString = ByteUtils.getString(key.get(), "UTF-8");
        if (keyString.isEmpty()) {
            // a new instance, with an empty key field.
            throw new VoldemortException("Received admin operation which got interpreted as a " + "GetMetadataRequest with an empty metadata key. This " + "typically means that the requested admin operation is not " + "supported on this version of the Voldemort server.");
        }
        List<Versioned<byte[]>> versionedList = metadataStore.get(key, null);
        if (versionedList.size() > 0) {
            Versioned<byte[]> versioned = versionedList.get(0);
            response.setVersion(ProtoUtils.encodeVersioned(versioned));
        }
    } catch (VoldemortException e) {
        response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
        String errorMessage = "handleGetMetadata failed for request(" + request.toString() + ")";
        if (e instanceof StoreNotFoundException) {
            logger.info(errorMessage + " with " + StoreNotFoundException.class.getSimpleName());
        } else {
            logger.error(errorMessage, e);
        }
    }
    return response.build();
}
Also used : StoreNotFoundException(voldemort.store.StoreNotFoundException) Versioned(voldemort.versioning.Versioned) ByteArray(voldemort.utils.ByteArray) VoldemortException(voldemort.VoldemortException)

Example 55 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class AdminServiceRequestHandler method handleUpdateMetadataPair.

public VAdminProto.UpdateMetadataPairResponse handleUpdateMetadataPair(VAdminProto.UpdateMetadataPairRequest request) {
    VAdminProto.UpdateMetadataPairResponse.Builder response = VAdminProto.UpdateMetadataPairResponse.newBuilder();
    try {
        ByteArray clusterKey = ProtoUtils.decodeBytes(request.getClusterKey());
        ByteArray storesKey = ProtoUtils.decodeBytes(request.getStoresKey());
        String clusterKeyString = ByteUtils.getString(clusterKey.get(), "UTF-8");
        String storesKeyString = ByteUtils.getString(storesKey.get(), "UTF-8");
        if (MetadataStore.METADATA_KEYS.contains(clusterKeyString) && MetadataStore.METADATA_KEYS.contains(storesKeyString)) {
            Versioned<byte[]> clusterVersionedValue = ProtoUtils.decodeVersioned(request.getClusterValue());
            Versioned<byte[]> storesVersionedValue = ProtoUtils.decodeVersioned(request.getStoresValue());
            metadataStore.writeLock.lock();
            try {
                logger.info("Updating metadata for keys '" + clusterKeyString + "'" + " and '" + storesKeyString + "'");
                metadataStore.put(clusterKey, clusterVersionedValue, null);
                // replace this with put
                metadataStore.put(storesKey, storesVersionedValue, null);
                // metadataStore.updateStoreDefinitions(storesVersionedValue);
                logger.info("Successfully updated metadata for keys '" + clusterKeyString + "'" + " and '" + storesKeyString + "'");
            } finally {
                metadataStore.writeLock.unlock();
            }
        }
    } catch (VoldemortException e) {
        response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
        logger.error("handleUpdateMetadataPair failed for request(" + request.toString() + ")", 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