Search in sources :

Example 46 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class StorageService method openStore.

public StorageEngine<ByteArray, byte[], byte[]> openStore(StoreDefinition storeDef) {
    logger.info("Opening store '" + storeDef.getName() + "' (" + storeDef.getType() + ").");
    StorageConfiguration config = storageConfigs.get(storeDef.getType());
    if (config == null)
        throw new ConfigurationException("Attempt to open store " + storeDef.getName() + " but " + storeDef.getType() + " storage engine has not been enabled.");
    boolean isReadOnly = storeDef.getType().compareTo(ReadOnlyStorageConfiguration.TYPE_NAME) == 0;
    final RoutingStrategy routingStrategy = new RoutingStrategyFactory().updateRoutingStrategy(storeDef, metadata.getCluster());
    final StorageEngine<ByteArray, byte[], byte[]> engine = config.getStore(storeDef, routingStrategy);
    // Update the routing strategy + add listener to metadata
    if (storeDef.getType().compareTo(ReadOnlyStorageConfiguration.TYPE_NAME) == 0) {
        metadata.addMetadataStoreListener(storeDef.getName(), new MetadataStoreListener() {

            public void updateRoutingStrategy(RoutingStrategy updatedRoutingStrategy) {
                ((ReadOnlyStorageEngine) engine).setRoutingStrategy(updatedRoutingStrategy);
            }

            public void updateStoreDefinition(StoreDefinition storeDef) {
                return;
            }
        });
    }
    // openStore() should have atomic semantics
    try {
        registerEngine(engine, isReadOnly, storeDef.getType(), storeDef);
        if (voldemortConfig.isServerRoutingEnabled())
            registerNodeStores(storeDef, metadata.getCluster(), voldemortConfig.getNodeId());
        if (storeDef.hasRetentionPeriod())
            scheduleCleanupJob(storeDef, engine);
    } catch (Exception e) {
        removeEngine(engine, isReadOnly, storeDef.getType(), false);
        throw new VoldemortException(e);
    }
    return engine;
}
Also used : ConfigurationException(voldemort.utils.ConfigurationException) RoutingStrategyFactory(voldemort.routing.RoutingStrategyFactory) StoreDefinition(voldemort.store.StoreDefinition) RoutingStrategy(voldemort.routing.RoutingStrategy) StorageConfiguration(voldemort.store.StorageConfiguration) FileBackedCachingStorageConfiguration(voldemort.store.configuration.FileBackedCachingStorageConfiguration) InMemoryStorageConfiguration(voldemort.store.memory.InMemoryStorageConfiguration) ViewStorageConfiguration(voldemort.store.views.ViewStorageConfiguration) ReadOnlyStorageConfiguration(voldemort.store.readonly.ReadOnlyStorageConfiguration) ByteArray(voldemort.utils.ByteArray) MetadataStoreListener(voldemort.store.metadata.MetadataStoreListener) VoldemortException(voldemort.VoldemortException) ConfigurationException(voldemort.utils.ConfigurationException) NoSuchCapabilityException(voldemort.store.NoSuchCapabilityException) DisabledStoreException(voldemort.store.DisabledStoreException) VoldemortException(voldemort.VoldemortException)

Example 47 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class AsyncRequestHandler method handleStreamRequestInternal.

private StreamRequestHandlerState handleStreamRequestInternal(SelectionKey selectionKey, DataInputStream dataInputStream, DataOutputStream dataOutputStream) throws IOException {
    StreamRequestHandlerState state = null;
    try {
        if (logger.isTraceEnabled())
            traceInputBufferState("Before streaming request handler");
        // this is the lowest level in the NioSocketServer stack at which we
        // still have a reference to the client IP address and port
        long startNs = -1;
        if (logger.isDebugEnabled())
            startNs = System.nanoTime();
        state = streamRequestHandler.handleRequest(dataInputStream, dataOutputStream);
        if (logger.isDebugEnabled()) {
            logger.debug("Handled request from " + socketChannel.socket().getRemoteSocketAddress() + " handlerRef: " + System.identityHashCode(dataInputStream) + " at time: " + System.currentTimeMillis() + " elapsed time: " + (System.nanoTime() - startNs) + " ns");
        }
        if (logger.isTraceEnabled())
            traceInputBufferState("After streaming request handler");
    } catch (Exception e) {
        if (logger.isEnabledFor(Level.WARN))
            logger.warn(e.getMessage(), e);
        VoldemortException error = e instanceof VoldemortException ? (VoldemortException) e : new VoldemortException(e);
        streamRequestHandler.handleError(dataOutputStream, error);
        closeStreamRequestHandler(dataOutputStream);
        streamRequestHandler = null;
        prepForWrite(selectionKey);
        close();
    }
    return state;
}
Also used : VoldemortException(voldemort.VoldemortException) VoldemortException(voldemort.VoldemortException) VoldemortApplicationException(voldemort.VoldemortApplicationException) IOException(java.io.IOException) EOFException(java.io.EOFException) StreamRequestHandlerState(voldemort.server.protocol.StreamRequestHandler.StreamRequestHandlerState)

Example 48 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class NioSocketService method startInner.

@Override
protected void startInner() {
    if (logger.isEnabledFor(Level.INFO))
        logger.info("Starting Voldemort NIO socket server (" + serviceName + ") on port " + port);
    try {
        for (int i = 0; i < selectorManagers.length; i++) {
            selectorManagers[i] = new NioSelectorManager(endpoint, requestHandlerFactory, socketBufferSize, socketKeepAlive, selectorMaxHeartBeatTimeMs);
            selectorManagerThreadPool.execute(selectorManagers[i]);
        }
        serverSocketChannel.socket().bind(endpoint, acceptorBacklog);
        serverSocketChannel.socket().setReceiveBufferSize(socketBufferSize);
        serverSocketChannel.socket().setReuseAddress(true);
        acceptorThread.start();
    } catch (Exception e) {
        throw new VoldemortException(e);
    }
    enableJmx(this);
}
Also used : VoldemortException(voldemort.VoldemortException) VoldemortException(voldemort.VoldemortException) IOException(java.io.IOException) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException)

Example 49 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class AdminServiceRequestHandler method handleGetROCurrentVersionDir.

public VAdminProto.GetROCurrentVersionDirResponse handleGetROCurrentVersionDir(VAdminProto.GetROCurrentVersionDirRequest request) {
    final List<String> storeNames = request.getStoreNameList();
    VAdminProto.GetROCurrentVersionDirResponse.Builder response = VAdminProto.GetROCurrentVersionDirResponse.newBuilder();
    try {
        for (String storeName : storeNames) {
            ReadOnlyStorageEngine store = getReadOnlyStorageEngine(metadataStore, storeRepository, storeName);
            VAdminProto.ROStoreVersionDirMap storeResponse = VAdminProto.ROStoreVersionDirMap.newBuilder().setStoreName(storeName).setStoreDir(store.getCurrentDirPath()).build();
            response.addRoStoreVersions(storeResponse);
        }
    } catch (VoldemortException e) {
        response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
        logger.error("handleGetROCurrentVersion failed for request(" + request.toString() + ")", e);
    }
    return response.build();
}
Also used : ReadOnlyStorageEngine(voldemort.store.readonly.ReadOnlyStorageEngine) VAdminProto(voldemort.client.protocol.pb.VAdminProto) VoldemortException(voldemort.VoldemortException)

Example 50 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class AdminServiceRequestHandler method handleRequest.

@Override
public StreamRequestHandler handleRequest(final DataInputStream inputStream, final DataOutputStream outputStream, final ByteBufferContainer container) throws IOException {
    // Another protocol buffers bug here, temp. work around
    VoldemortAdminRequest.Builder request = VoldemortAdminRequest.newBuilder();
    int size = inputStream.readInt();
    if (logger.isTraceEnabled())
        logger.trace("In handleRequest, request specified size of " + size + " bytes");
    if (size < 0)
        throw new IOException("In handleRequest, request specified size of " + size + " bytes");
    byte[] input = new byte[size];
    ByteUtils.read(inputStream, input);
    request.mergeFrom(input);
    switch(request.getType()) {
        case GET_METADATA:
            ProtoUtils.writeMessage(outputStream, handleGetMetadata(request.getGetMetadata()));
            break;
        case UPDATE_METADATA:
            ProtoUtils.writeMessage(outputStream, handleSetMetadata(request.getUpdateMetadata()));
            break;
        case UPDATE_STORE_DEFINITIONS:
            ProtoUtils.writeMessage(outputStream, handleUpdateStoreDefinitions(request.getUpdateMetadata()));
            break;
        case UPDATE_METADATA_PAIR:
            ProtoUtils.writeMessage(outputStream, handleUpdateMetadataPair(request.getUpdateMetadataPair()));
            break;
        case DELETE_PARTITION_ENTRIES:
            ProtoUtils.writeMessage(outputStream, handleDeletePartitionEntries(request.getDeletePartitionEntries()));
            break;
        case FETCH_PARTITION_ENTRIES:
            return handleFetchPartitionEntries(request.getFetchPartitionEntries());
        case UPDATE_PARTITION_ENTRIES:
            return handleUpdatePartitionEntries(request.getUpdatePartitionEntries());
        case INITIATE_FETCH_AND_UPDATE:
            ProtoUtils.writeMessage(outputStream, handleFetchAndUpdate(request.getInitiateFetchAndUpdate()));
            break;
        case ASYNC_OPERATION_STATUS:
            ProtoUtils.writeMessage(outputStream, handleAsyncStatus(request.getAsyncOperationStatus()));
            break;
        case INITIATE_REBALANCE_NODE:
            ProtoUtils.writeMessage(outputStream, handleRebalanceNode(request.getInitiateRebalanceNode()));
            break;
        case ASYNC_OPERATION_LIST:
            ProtoUtils.writeMessage(outputStream, handleAsyncOperationList(request.getAsyncOperationList()));
            break;
        case ASYNC_OPERATION_STOP:
            ProtoUtils.writeMessage(outputStream, handleAsyncOperationStop(request.getAsyncOperationStop()));
            break;
        case LIST_SCHEDULED_JOBS:
            ProtoUtils.writeMessage(outputStream, handleListScheduledJobs(request.getListScheduledJobs()));
            break;
        case GET_SCHEDULED_JOB_STATUS:
            ProtoUtils.writeMessage(outputStream, handleGetScheduledJobStatus(request.getGetScheduledJobStatus()));
            break;
        case STOP_SCHEDULED_JOB:
            ProtoUtils.writeMessage(outputStream, handleStopScheduledJob(request.getStopScheduledJob()));
            break;
        case ENABLE_SCHEDULED_JOB:
            ProtoUtils.writeMessage(outputStream, handleEnableScheduledJob(request.getEnableScheduledJob()));
            break;
        case TRUNCATE_ENTRIES:
            ProtoUtils.writeMessage(outputStream, handleTruncateEntries(request.getTruncateEntries()));
            break;
        case ADD_STORE:
            ProtoUtils.writeMessage(outputStream, handleAddStore(request.getAddStore()));
            break;
        case DELETE_STORE:
            ProtoUtils.writeMessage(outputStream, handleDeleteStore(request.getDeleteStore()));
            break;
        case FETCH_STORE:
            ProtoUtils.writeMessage(outputStream, handleFetchROStore(request.getFetchStore()));
            break;
        case SWAP_STORE:
            ProtoUtils.writeMessage(outputStream, handleSwapROStore(request.getSwapStore()));
            break;
        case ROLLBACK_STORE:
            ProtoUtils.writeMessage(outputStream, handleRollbackStore(request.getRollbackStore()));
            break;
        case GET_RO_MAX_VERSION_DIR:
            ProtoUtils.writeMessage(outputStream, handleGetROMaxVersionDir(request.getGetRoMaxVersionDir()));
            break;
        case GET_RO_CURRENT_VERSION_DIR:
            ProtoUtils.writeMessage(outputStream, handleGetROCurrentVersionDir(request.getGetRoCurrentVersionDir()));
            break;
        case GET_RO_STORAGE_FORMAT:
            ProtoUtils.writeMessage(outputStream, handleGetROStorageFormat(request.getGetRoStorageFormat()));
            break;
        case GET_RO_STORAGE_FILE_LIST:
            ProtoUtils.writeMessage(outputStream, handleGetROStorageFileList(request.getGetRoStorageFileList()));
            break;
        case GET_RO_COMPRESSION_CODEC_LIST:
            ProtoUtils.writeMessage(outputStream, handleGetROCompressionCodecList(request.getGetRoCompressionCodecList()));
            break;
        case FETCH_PARTITION_FILES:
            return handleFetchROPartitionFiles(request.getFetchPartitionFiles());
        case UPDATE_SLOP_ENTRIES:
            return handleUpdateSlopEntries(request.getUpdateSlopEntries());
        case FAILED_FETCH_STORE:
            ProtoUtils.writeMessage(outputStream, handleFailedROFetch(request.getFailedFetchStore()));
            break;
        case REBALANCE_STATE_CHANGE:
            ProtoUtils.writeMessage(outputStream, handleRebalanceStateChange(request.getRebalanceStateChange()));
            break;
        case DELETE_STORE_REBALANCE_STATE:
            ProtoUtils.writeMessage(outputStream, handleDeleteStoreRebalanceState(request.getDeleteStoreRebalanceState()));
            break;
        case SET_OFFLINE_STATE:
            ProtoUtils.writeMessage(outputStream, handleSetOfflineState(request.getSetOfflineState()));
            break;
        case REPAIR_JOB:
            ProtoUtils.writeMessage(outputStream, handleRepairJob(request.getRepairJob()));
            break;
        case PRUNE_JOB:
            ProtoUtils.writeMessage(outputStream, handlePruneJob(request.getPruneJob()));
            break;
        case SLOP_PURGE_JOB:
            ProtoUtils.writeMessage(outputStream, handleSlopPurgeJob(request.getSlopPurgeJob()));
            break;
        case NATIVE_BACKUP:
            ProtoUtils.writeMessage(outputStream, handleNativeBackup(request.getNativeBackup()));
            break;
        case RESERVE_MEMORY:
            ProtoUtils.writeMessage(outputStream, handleReserveMemory(request.getReserveMemory()));
            break;
        case GET_HA_SETTINGS:
            ProtoUtils.writeMessage(outputStream, handleGetHighAvailabilitySettings(request.getGetHaSettings()));
            break;
        case DISABLE_STORE_VERSION:
            ProtoUtils.writeMessage(outputStream, handleDisableStoreVersion(request.getDisableStoreVersion()));
            break;
        case HANDLE_FETCH_FAILURE:
            ProtoUtils.writeMessage(outputStream, handleFetchFailure(request.getHandleFetchFailure()));
            break;
        case GET_CONFIG:
            ProtoUtils.writeMessage(outputStream, handleGetConfigRequest(request.getGetConfig()));
            break;
        default:
            throw new VoldemortException("Unknown operation: " + request.getType());
    }
    return null;
}
Also used : VoldemortAdminRequest(voldemort.client.protocol.pb.VAdminProto.VoldemortAdminRequest) IOException(java.io.IOException) 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