Search in sources :

Example 6 with MutableInt

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());
}
Also used : MutableInt(org.apache.commons.lang.mutable.MutableInt)

Example 7 with MutableInt

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);
}
Also used : MutableInt(org.apache.commons.lang.mutable.MutableInt)

Example 8 with MutableInt

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);
}
Also used : MutableInt(org.apache.commons.lang.mutable.MutableInt)

Example 9 with MutableInt

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));
}
Also used : MutableInt(org.apache.commons.lang.mutable.MutableInt)

Example 10 with MutableInt

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);
}
Also used : Versioned(voldemort.versioning.Versioned) Node(voldemort.cluster.Node) InvalidMetadataException(voldemort.store.InvalidMetadataException) NonblockingStoreCallback(voldemort.store.nonblockingstore.NonblockingStoreCallback) ByteArray(voldemort.utils.ByteArray) List(java.util.List) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NonblockingStore(voldemort.store.nonblockingstore.NonblockingStore) CountDownLatch(java.util.concurrent.CountDownLatch) InvalidMetadataException(voldemort.store.InvalidMetadataException) Response(voldemort.store.routed.Response) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MutableInt(org.apache.commons.lang.mutable.MutableInt) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map)

Aggregations

MutableInt (org.apache.commons.lang.mutable.MutableInt)35 List (java.util.List)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)5 ArrayList (java.util.ArrayList)5 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)4 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 Map (java.util.Map)4 Test (org.junit.Test)4 Versioned (voldemort.versioning.Versioned)4 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)3 MutableObject (org.apache.commons.lang.mutable.MutableObject)3 DateTime (org.joda.time.DateTime)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Random (java.util.Random)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 CompositeName (javax.naming.CompositeName)2