Search in sources :

Example 41 with ClusterMapper

use of voldemort.xml.ClusterMapper in project voldemort by voldemort.

the class AdminServiceRequestHandler method handleDeletePartitionEntries.

// TODO : Add ability to use partition scans
public VAdminProto.DeletePartitionEntriesResponse handleDeletePartitionEntries(VAdminProto.DeletePartitionEntriesRequest request) {
    VAdminProto.DeletePartitionEntriesResponse.Builder response = VAdminProto.DeletePartitionEntriesResponse.newBuilder();
    ClosableIterator<Pair<ByteArray, Versioned<byte[]>>> iterator = null;
    try {
        String storeName = request.getStore();
        final List<Integer> partitionsIds = request.getPartitionIdsList();
        final boolean isReadWriteStore = metadataStore.getStoreDef(storeName).getType().compareTo(ReadOnlyStorageConfiguration.TYPE_NAME) != 0;
        if (!isReadWriteStore) {
            throw new VoldemortException("Cannot delete partitions for store " + storeName + " on node " + metadataStore.getNodeId() + " since it is not a RW store");
        }
        StorageEngine<ByteArray, byte[], byte[]> storageEngine = getStorageEngine(storeRepository, storeName);
        VoldemortFilter filter = (request.hasFilter()) ? getFilterFromRequest(request.getFilter(), voldemortConfig, networkClassLoader) : new DefaultVoldemortFilter();
        EventThrottler throttler = new EventThrottler(voldemortConfig.getStreamMaxReadBytesPerSec());
        iterator = storageEngine.entries();
        long deleteSuccess = 0;
        logger.info("Deleting entries for RW store " + storeName + " from node " + metadataStore.getNodeId() + " ( " + storeName + " )");
        while (iterator.hasNext()) {
            Pair<ByteArray, Versioned<byte[]>> entry = iterator.next();
            ByteArray key = entry.getFirst();
            Versioned<byte[]> value = entry.getSecond();
            throttler.maybeThrottle(key.length() + valueSize(value));
            if (StoreRoutingPlan.checkKeyBelongsToNode(key.get(), metadataStore.getNodeId(), request.hasInitialCluster() ? new ClusterMapper().readCluster(new StringReader(request.getInitialCluster())) : metadataStore.getCluster(), metadataStore.getStoreDef(storeName)) && filter.accept(key, value)) {
                if (storageEngine.delete(key, value.getVersion())) {
                    deleteSuccess++;
                    if ((deleteSuccess % 10000) == 0) {
                        logger.info(deleteSuccess + " entries deleted from node " + metadataStore.getNodeId() + " for store " + storeName);
                    }
                }
            }
        }
        logger.info("Completed deletion of entries for RW store " + storeName + " from node " + metadataStore.getNodeId() + " ( " + partitionsIds + " )");
        response.setCount(deleteSuccess);
    } catch (VoldemortException e) {
        response.setError(ProtoUtils.encodeError(errorCodeMapper, e));
        logger.error("handleDeletePartitionEntries failed for request(" + request.toString() + ")", e);
    } finally {
        if (null != iterator)
            iterator.close();
    }
    return response.build();
}
Also used : Versioned(voldemort.versioning.Versioned) EventThrottler(voldemort.utils.EventThrottler) ClusterMapper(voldemort.xml.ClusterMapper) VoldemortException(voldemort.VoldemortException) DefaultVoldemortFilter(voldemort.client.protocol.admin.filter.DefaultVoldemortFilter) VoldemortFilter(voldemort.client.protocol.VoldemortFilter) StringReader(java.io.StringReader) ByteArray(voldemort.utils.ByteArray) DefaultVoldemortFilter(voldemort.client.protocol.admin.filter.DefaultVoldemortFilter) Pair(voldemort.utils.Pair)

Aggregations

ClusterMapper (voldemort.xml.ClusterMapper)41 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)26 Cluster (voldemort.cluster.Cluster)23 File (java.io.File)18 StoreDefinition (voldemort.store.StoreDefinition)18 StringReader (java.io.StringReader)13 OptionSet (joptsimple.OptionSet)10 Node (voldemort.cluster.Node)10 AdminClient (voldemort.client.protocol.admin.AdminClient)9 VoldemortException (voldemort.VoldemortException)8 Test (org.junit.Test)6 ByteArray (voldemort.utils.ByteArray)6 Versioned (voldemort.versioning.Versioned)6 OptionParser (joptsimple.OptionParser)5 IOException (java.io.IOException)4 InMemoryStorageEngine (voldemort.store.memory.InMemoryStorageEngine)4 FileNotFoundException (java.io.FileNotFoundException)3 ClientConfig (voldemort.client.ClientConfig)3 SocketStoreClientFactory (voldemort.client.SocketStoreClientFactory)3 BufferedReader (java.io.BufferedReader)2