Search in sources :

Example 6 with VoldemortFilter

use of voldemort.client.protocol.VoldemortFilter 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

VoldemortFilter (voldemort.client.protocol.VoldemortFilter)6 ByteArray (voldemort.utils.ByteArray)5 Pair (voldemort.utils.Pair)5 Versioned (voldemort.versioning.Versioned)5 Test (org.junit.Test)3 VoldemortException (voldemort.VoldemortException)3 DefaultVoldemortFilter (voldemort.client.protocol.admin.filter.DefaultVoldemortFilter)3 StringReader (java.io.StringReader)2 RoutingStrategy (voldemort.routing.RoutingStrategy)2 RoutingStrategyFactory (voldemort.routing.RoutingStrategyFactory)2 EventThrottler (voldemort.utils.EventThrottler)2 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)2 ClusterMapper (voldemort.xml.ClusterMapper)2 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AdminClient (voldemort.client.protocol.admin.AdminClient)1 Cluster (voldemort.cluster.Cluster)1 NoSuchCapabilityException (voldemort.store.NoSuchCapabilityException)1 PersistenceFailureException (voldemort.store.PersistenceFailureException)1