Search in sources :

Example 56 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class AdminServiceRequestHandler method handleUpdateStoreDefinitions.

public VAdminProto.UpdateMetadataResponse handleUpdateStoreDefinitions(VAdminProto.UpdateMetadataRequest request) {
    VAdminProto.UpdateMetadataResponse.Builder response = VAdminProto.UpdateMetadataResponse.newBuilder();
    try {
        ByteArray key = ProtoUtils.decodeBytes(request.getKey());
        String keyString = ByteUtils.getString(key.get(), "UTF-8");
        if (MetadataStore.METADATA_KEYS.contains(keyString)) {
            Versioned<byte[]> versionedValue = ProtoUtils.decodeVersioned(request.getVersioned());
            // corresponding put
            if (keyString.equals(MetadataStore.STORES_KEY)) {
                metadataStore.updateStoreDefinitions(versionedValue);
            }
            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 57 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class AdminServiceRequestHandler method handleAddStore.

public VAdminProto.AddStoreResponse handleAddStore(VAdminProto.AddStoreRequest request) {
    VAdminProto.AddStoreResponse.Builder response = VAdminProto.AddStoreResponse.newBuilder();
    // don't try to add a store when not in normal or offline state
    if (!metadataStore.getServerStateUnlocked().equals(MetadataStore.VoldemortState.NORMAL_SERVER) && !metadataStore.getServerStateUnlocked().equals(MetadataStore.VoldemortState.OFFLINE_SERVER)) {
        response.setError(ProtoUtils.encodeError(errorCodeMapper, new VoldemortException("Voldemort server is neither in normal state nor in offline state")));
        return response.build();
    }
    AdminClient adminClient = null;
    try {
        // adding a store requires decoding the passed in store string
        StoreDefinitionsMapper mapper = new StoreDefinitionsMapper();
        StoreDefinition def = mapper.readStore(new StringReader(request.getStoreDefinition()));
        adminClient = new AdminClient(metadataStore.getCluster());
        synchronized (lock) {
            if (!storeRepository.hasLocalStore(def.getName())) {
                if (def.getReplicationFactor() > metadataStore.getCluster().getNumberOfNodes()) {
                    throw new StoreOperationFailureException("Cannot add a store whose replication factor ( " + def.getReplicationFactor() + " ) is greater than the number of nodes ( " + metadataStore.getCluster().getNumberOfNodes() + " )");
                }
                logger.info("Adding new store '" + def.getName() + "'");
                // open the store
                StorageEngine<ByteArray, byte[], byte[]> engine = storageService.openStore(def);
                // effect of updating the stores.xml file)
                try {
                    metadataStore.addStoreDefinition(def);
                    long defaultQuota = voldemortConfig.getDefaultStorageSpaceQuotaInKB();
                    QuotaUtils.setQuota(def.getName(), QuotaType.STORAGE_SPACE, storeRepository, metadataStore.getCluster().getNodeIds(), defaultQuota);
                } catch (Exception e) {
                    // rollback open store operation
                    boolean isReadOnly = ReadOnlyStorageConfiguration.TYPE_NAME.equals(def.getType());
                    storageService.removeEngine(engine, isReadOnly, def.getType(), true);
                    throw new VoldemortException(e);
                }
                logger.info("Successfully added new store '" + def.getName() + "'");
            } else {
                logger.error("Failure to add a store with the same name '" + def.getName() + "'");
                throw new StoreOperationFailureException(String.format("Store '%s' already exists on this server", def.getName()));
            }
        }
    } catch (VoldemortException e) {
        response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
        logger.error("handleAddStore failed for request(" + request.toString() + ")", e);
    } finally {
        if (adminClient != null) {
            IOUtils.closeQuietly(adminClient);
        }
    }
    return response.build();
}
Also used : StoreDefinition(voldemort.store.StoreDefinition) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) StringReader(java.io.StringReader) ByteArray(voldemort.utils.ByteArray) StoreOperationFailureException(voldemort.store.StoreOperationFailureException) 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) AdminClient(voldemort.client.protocol.admin.AdminClient)

Example 58 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class AdminServiceRequestHandler method handleRollbackStore.

public VAdminProto.RollbackStoreResponse handleRollbackStore(VAdminProto.RollbackStoreRequest request) {
    final String storeName = request.getStoreName();
    final long pushVersion = request.getPushVersion();
    VAdminProto.RollbackStoreResponse.Builder response = VAdminProto.RollbackStoreResponse.newBuilder();
    try {
        ReadOnlyStorageEngine store = getReadOnlyStorageEngine(metadataStore, storeRepository, storeName);
        File rollbackVersionDir = new File(store.getStoreDirPath(), "version-" + pushVersion);
        logger.info("Rolling back data for RO store '" + storeName + "' to version directory '" + rollbackVersionDir + "'");
        store.rollback(rollbackVersionDir);
        logger.info("Successfully rolled back data for RO store '" + storeName + "' to version directory '" + rollbackVersionDir + "'");
    } catch (VoldemortException e) {
        response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
        logger.error("handleRollbackStore failed for request(" + request.toString() + ")", e);
    }
    return response.build();
}
Also used : ReadOnlyStorageEngine(voldemort.store.readonly.ReadOnlyStorageEngine) File(java.io.File) VoldemortException(voldemort.VoldemortException)

Example 59 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class AdminServiceRequestHandler method handleRebalanceStateChange.

public VAdminProto.RebalanceStateChangeResponse handleRebalanceStateChange(VAdminProto.RebalanceStateChangeRequest request) {
    VAdminProto.RebalanceStateChangeResponse.Builder response = VAdminProto.RebalanceStateChangeResponse.newBuilder();
    synchronized (rebalancer) {
        try {
            // Retrieve all values first
            List<RebalanceTaskInfo> rebalanceTaskInfo = Lists.newArrayList();
            for (RebalanceTaskInfoMap map : request.getRebalanceTaskListList()) {
                rebalanceTaskInfo.add(ProtoUtils.decodeRebalanceTaskInfoMap(map));
            }
            Cluster cluster = new ClusterMapper().readCluster(new StringReader(request.getClusterString()));
            List<StoreDefinition> storeDefs = new StoreDefinitionsMapper().readStoreList(new StringReader(request.getStoresString()));
            boolean swapRO = request.getSwapRo();
            boolean changeClusterMetadata = request.getChangeClusterMetadata();
            boolean changeRebalanceState = request.getChangeRebalanceState();
            boolean rollback = request.getRollback();
            rebalancer.rebalanceStateChange(cluster, storeDefs, rebalanceTaskInfo, swapRO, changeClusterMetadata, changeRebalanceState, rollback);
        } catch (VoldemortException e) {
            response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
            logger.error("handleRebalanceStateChange failed for request(" + request.toString() + ")", e);
        }
    }
    return response.build();
}
Also used : RebalanceTaskInfoMap(voldemort.client.protocol.pb.VAdminProto.RebalanceTaskInfoMap) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) Cluster(voldemort.cluster.Cluster) ClusterMapper(voldemort.xml.ClusterMapper) VoldemortException(voldemort.VoldemortException) StoreDefinition(voldemort.store.StoreDefinition) StringReader(java.io.StringReader) RebalanceTaskInfo(voldemort.client.rebalance.RebalanceTaskInfo)

Example 60 with VoldemortException

use of voldemort.VoldemortException in project voldemort by voldemort.

the class AdminServiceRequestHandler method handleSetOfflineState.

public VAdminProto.SetOfflineStateResponse handleSetOfflineState(VAdminProto.SetOfflineStateRequest request) {
    VAdminProto.SetOfflineStateResponse.Builder response = VAdminProto.SetOfflineStateResponse.newBuilder();
    try {
        Boolean setToOffline = request.getOfflineMode();
        logger.info("Setting OFFLINE_SERVER state to " + setToOffline.toString());
        if (setToOffline) {
            server.goOffline();
        } else {
            server.goOnline();
        }
    // TODO: deal with slop pushing here
    } catch (VoldemortException e) {
        response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
        logger.error("handleSetOfflineState failed for request(" + request.toString() + ")", e);
    }
    return response.build();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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