Search in sources :

Example 11 with ByteArray

use of voldemort.utils.ByteArray in project voldemort by voldemort.

the class PartitionPrefixedRocksDbStorageEngine method validateAndConstructKey.

private ByteArray validateAndConstructKey(ByteArray key) {
    StoreUtils.assertValidKey(key);
    int partition = routingStrategy.getMasterPartition(key.get());
    ByteArray prefixedKey = new ByteArray(StoreBinaryFormat.makePrefixedKey(key.get(), partition));
    return prefixedKey;
}
Also used : ByteArray(voldemort.utils.ByteArray)

Example 12 with ByteArray

use of voldemort.utils.ByteArray in project voldemort by voldemort.

the class RocksDbStorageEngine method getAll.

@Override
public Map<ByteArray, List<Versioned<byte[]>>> getAll(Iterable<ByteArray> keys, Map<ByteArray, byte[]> transforms) throws VoldemortException {
    // TODO Does RocksDB multiget supports atomicity ?
    StoreUtils.assertValidKeys(keys);
    long startTimeNs = -1;
    if (logger.isTraceEnabled())
        startTimeNs = System.nanoTime();
    Map<ByteArray, List<Versioned<byte[]>>> results = null;
    try {
        results = StoreUtils.getAll(this, keys, transforms);
    } catch (PersistenceFailureException e) {
        logger.error(e);
        throw new PersistenceFailureException(e);
    } finally {
        if (logger.isTraceEnabled()) {
            String keyStr = "";
            for (ByteArray key : keys) keyStr += key + " ";
            logger.trace("Completed GETALL (" + getName() + ") from keys " + keyStr + " in " + (System.nanoTime() - startTimeNs) + " ns at " + System.currentTimeMillis());
        }
    }
    return results;
}
Also used : ByteArray(voldemort.utils.ByteArray) ArrayList(java.util.ArrayList) List(java.util.List) PersistenceFailureException(voldemort.store.PersistenceFailureException)

Example 13 with ByteArray

use of voldemort.utils.ByteArray in project voldemort by voldemort.

the class RedirectingStore method redirectingGetAll.

/**
     * If needed, satisfies the getAll request by redirecting calls to the
     * remote proxy node. Also updates local storage accordingly.
     * 
     * 
     * @param keys
     * @param transforms
     * @return
     * @throws VoldemortException
     */
private Map<ByteArray, List<Versioned<byte[]>>> redirectingGetAll(Iterable<ByteArray> keys, Map<ByteArray, byte[]> transforms) throws VoldemortException {
    // first determine how many keys are already present locally.
    Map<ByteArray, List<Versioned<byte[]>>> localVals = getInnerStore().getAll(keys, transforms);
    Map<ByteArray, Integer> keyToProxyNodeMap = Maps.newHashMapWithExpectedSize(Iterables.size(keys));
    for (ByteArray key : keys) {
        // the result hashmap, in case the key does not exist on storage
        if (localVals.containsKey(key)) {
            // if you have it locally, move to next key
            continue;
        }
        Integer redirectNode = getProxyNode(key.get());
        /*
             * Else check if we are rebalancing for the key.. Intuitively, if we
             * don't have the key, then we must be rebalancing for that key,
             * right? Otherwise the key should have been here? Wrong, what if
             * this is a non-existent key. We can't really confirm key does not
             * exist, without going to the proxy node..
             */
        if (redirectNode != null) {
            /*
                 * If we are indeed rebalancing for the key, then a proxy fetch
                 * will make things certain.
                 */
            keyToProxyNodeMap.put(key, redirectNode);
        }
    }
    // If all keys were present locally, return. If not, do proxy fetch
    if (!keyToProxyNodeMap.isEmpty()) {
        if (logger.isTraceEnabled()) {
            String keyStr = "";
            for (ByteArray key : keys) keyStr += key + " ";
            logger.trace("Proxying GETALL on stealer:" + metadata.getNodeId() + " for  keys " + keyStr);
        }
        // Issue proxy fetches for non-rebalancing keys that did not exist
        // locally
        proxyGetAllAndLocalPut(keyToProxyNodeMap, transforms);
        // Now, issue a getAll for those keys alone
        Map<ByteArray, List<Versioned<byte[]>>> proxyFetchedVals = getInnerStore().getAll(keyToProxyNodeMap.keySet(), transforms);
        // Merge the results
        for (Map.Entry<ByteArray, List<Versioned<byte[]>>> entry : proxyFetchedVals.entrySet()) {
            localVals.put(entry.getKey(), entry.getValue());
        }
    }
    return localVals;
}
Also used : ByteArray(voldemort.utils.ByteArray) List(java.util.List) Map(java.util.Map)

Example 14 with ByteArray

use of voldemort.utils.ByteArray in project voldemort by voldemort.

the class RedirectingStore method proxyGetAll.

/**
     * Performs a back-door proxy getAll
     * 
     * @param keyToProxyNodeMap Map of keys to corresponding proxy nodes housing
     *        the keys in source cluster
     * @param transforms Map of keys to their corresponding transforms
     * @throws ProxyUnreachableException if proxy node can't be reached
     */
private Map<ByteArray, List<Versioned<byte[]>>> proxyGetAll(Map<ByteArray, Integer> keyToProxyNodeMap, Map<ByteArray, byte[]> transforms) throws VoldemortException {
    Multimap<Integer, ByteArray> proxyNodeToKeys = HashMultimap.create();
    int numKeys = 0;
    // Transform the map of key to plan to a map of proxy node id to keys
    for (Map.Entry<ByteArray, Integer> entry : keyToProxyNodeMap.entrySet()) {
        numKeys++;
        proxyNodeToKeys.put(entry.getValue(), entry.getKey());
    }
    Map<ByteArray, List<Versioned<byte[]>>> gatherMap = Maps.newHashMapWithExpectedSize(numKeys);
    for (int proxyNodeId : proxyNodeToKeys.keySet()) {
        Node proxyNode = metadata.getCluster().getNodeById(proxyNodeId);
        checkNodeAvailable(proxyNode);
        long startNs = System.nanoTime();
        try {
            Map<ByteArray, List<Versioned<byte[]>>> resultsForNode = getRedirectingSocketStore(getName(), proxyNodeId).getAll(proxyNodeToKeys.get(proxyNodeId), transforms);
            recordSuccess(proxyNode, startNs);
            for (Map.Entry<ByteArray, List<Versioned<byte[]>>> entry : resultsForNode.entrySet()) {
                gatherMap.put(entry.getKey(), entry.getValue());
            }
        } catch (UnreachableStoreException e) {
            recordException(proxyNode, startNs, e);
            throw new ProxyUnreachableException("Failed to reach proxy node " + proxyNode, e);
        }
    }
    return gatherMap;
}
Also used : Node(voldemort.cluster.Node) ByteArray(voldemort.utils.ByteArray) List(java.util.List) UnreachableStoreException(voldemort.store.UnreachableStoreException) Map(java.util.Map)

Example 15 with ByteArray

use of voldemort.utils.ByteArray in project voldemort by voldemort.

the class RetentionEnforcingStore method getAll.

@Override
public Map<ByteArray, List<Versioned<byte[]>>> getAll(Iterable<ByteArray> keys, Map<ByteArray, byte[]> transforms) throws VoldemortException {
    StoreUtils.assertValidKeys(keys);
    Map<ByteArray, List<Versioned<byte[]>>> results = getInnerStore().getAll(keys, transforms);
    if (!storeDef.hasRetentionPeriod())
        return results;
    for (ByteArray key : results.keySet()) {
        List<Versioned<byte[]>> filteredVals = filterExpiredEntries(key, results.get(key));
        // filtered
        if (!filteredVals.isEmpty())
            results.put(key, filteredVals);
        else
            results.remove(key);
    }
    return results;
}
Also used : Versioned(voldemort.versioning.Versioned) ByteArray(voldemort.utils.ByteArray) List(java.util.List)

Aggregations

ByteArray (voldemort.utils.ByteArray)309 Versioned (voldemort.versioning.Versioned)130 Test (org.junit.Test)125 VoldemortException (voldemort.VoldemortException)67 VectorClock (voldemort.versioning.VectorClock)65 ArrayList (java.util.ArrayList)61 Node (voldemort.cluster.Node)61 List (java.util.List)58 HashMap (java.util.HashMap)53 StoreDefinition (voldemort.store.StoreDefinition)49 Cluster (voldemort.cluster.Cluster)33 AbstractByteArrayStoreTest (voldemort.store.AbstractByteArrayStoreTest)31 Store (voldemort.store.Store)31 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)31 IOException (java.io.IOException)30 Slop (voldemort.store.slop.Slop)29 Map (java.util.Map)28 Pair (voldemort.utils.Pair)28 UnreachableStoreException (voldemort.store.UnreachableStoreException)26 StatTrackingStore (voldemort.store.stats.StatTrackingStore)25