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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations