use of org.apache.commons.lang.mutable.MutableInt in project voldemort by voldemort.
the class VoldemortClientShell method processPreflist.
protected void processPreflist(String preflistArgStr) {
MutableInt parsePos = new MutableInt(0);
Object key = parseKey(preflistArgStr, parsePos);
byte[] serializedKey = serializeKey(key);
printPartitionList(routingStrategy.getPartitionList(serializedKey));
printNodeList(routingStrategy.routeRequest(serializedKey), factory.getFailureDetector());
}
use of org.apache.commons.lang.mutable.MutableInt in project voldemort by voldemort.
the class VoldemortClientShell method processDelete.
protected void processDelete(String deleteArgStr) {
MutableInt parsePos = new MutableInt(0);
Object key = parseKey(deleteArgStr, parsePos);
client.delete(key);
}
use of org.apache.commons.lang.mutable.MutableInt in project voldemort by voldemort.
the class VoldemortClientShell method processPut.
protected void processPut(String putArgStr) {
MutableInt parsePos = new MutableInt(0);
Object key = parseKey(putArgStr, parsePos);
putArgStr = putArgStr.substring(parsePos.intValue());
Object value = parseValue(putArgStr, parsePos);
client.put(key, value);
}
use of org.apache.commons.lang.mutable.MutableInt in project voldemort by voldemort.
the class VoldemortClientShell method processGet.
protected void processGet(String getArgStr) {
MutableInt parsePos = new MutableInt(0);
Object key = parseKey(getArgStr, parsePos);
printVersioned(client.get(key));
}
use of org.apache.commons.lang.mutable.MutableInt in project voldemort by voldemort.
the class PerformParallelGetAllRequests method execute.
@SuppressWarnings("unchecked")
public void execute(final Pipeline pipeline) {
int attempts = pipelineData.getNodeToKeysMap().size();
final Map<Integer, Response<Iterable<ByteArray>, Object>> responses = new ConcurrentHashMap<Integer, Response<Iterable<ByteArray>, Object>>();
final CountDownLatch latch = new CountDownLatch(attempts);
if (logger.isTraceEnabled())
logger.trace("Attempting " + attempts + " " + pipeline.getOperation().getSimpleName() + " operations in parallel");
Map<ByteArray, byte[]> transforms = pipelineData.getTransforms();
final AtomicBoolean isResponseProcessed = new AtomicBoolean(false);
for (Map.Entry<Node, List<ByteArray>> entry : pipelineData.getNodeToKeysMap().entrySet()) {
final Node node = entry.getKey();
final Collection<ByteArray> keys = entry.getValue();
NonblockingStoreCallback callback = new NonblockingStoreCallback() {
public void requestComplete(Object result, long requestTime) {
if (logger.isTraceEnabled())
logger.trace(pipeline.getOperation().getSimpleName() + " response received (" + requestTime + " ms.) from node " + node.getId());
Response<Iterable<ByteArray>, Object> response = new Response<Iterable<ByteArray>, Object>(node, keys, result, requestTime);
responses.put(node.getId(), response);
latch.countDown();
// This reduces the window where an exception is lost
if (isResponseProcessed.get() && response.getValue() instanceof Exception)
if (response.getValue() instanceof InvalidMetadataException) {
pipelineData.reportException((InvalidMetadataException) response.getValue());
logger.warn("Received invalid metadata problem after a successful " + pipeline.getOperation().getSimpleName() + " call on node " + node.getId() + ", store '" + pipelineData.getStoreName() + "'");
} else {
handleResponseError(response, pipeline, failureDetector);
}
}
};
if (logger.isTraceEnabled())
logger.trace("Submitting " + pipeline.getOperation().getSimpleName() + " request on node " + node.getId());
NonblockingStore store = nonblockingStores.get(node.getId());
store.submitGetAllRequest(keys, transforms, callback, timeoutMs);
}
try {
latch.await(timeoutMs, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
if (logger.isEnabledFor(Level.WARN))
logger.warn(e, e);
}
for (Response<Iterable<ByteArray>, Object> response : responses.values()) {
if (response.getValue() instanceof Exception) {
if (handleResponseError(response, pipeline, failureDetector))
return;
} else {
Map<ByteArray, List<Versioned<byte[]>>> values = (Map<ByteArray, List<Versioned<byte[]>>>) response.getValue();
for (ByteArray key : response.getKey()) {
MutableInt successCount = pipelineData.getSuccessCount(key);
successCount.increment();
List<Versioned<byte[]>> retrieved = values.get(key);
/*
* retrieved can be null if there are no values for the key
* provided
*/
if (retrieved != null) {
List<Versioned<byte[]>> existing = pipelineData.getResult().get(key);
if (existing == null)
pipelineData.getResult().put(key, Lists.newArrayList(retrieved));
else
existing.addAll(retrieved);
}
HashSet<Integer> zoneResponses = null;
if (pipelineData.getKeyToZoneResponse().containsKey(key)) {
zoneResponses = pipelineData.getKeyToZoneResponse().get(key);
} else {
zoneResponses = new HashSet<Integer>();
pipelineData.getKeyToZoneResponse().put(key, zoneResponses);
}
zoneResponses.add(response.getNode().getZoneId());
}
pipelineData.getResponses().add(new Response<Iterable<ByteArray>, Map<ByteArray, List<Versioned<byte[]>>>>(response.getNode(), response.getKey(), values, response.getRequestTime()));
failureDetector.recordSuccess(response.getNode(), response.getRequestTime());
}
}
isResponseProcessed.set(true);
pipeline.addEvent(completeEvent);
}
Aggregations