Search in sources :

Example 21 with MutableInt

use of org.apache.commons.lang.mutable.MutableInt in project hbase by apache.

the class ZkSplitLogWorkerCoordination method submitTask.

/**
   * Submit a log split task to executor service
   * @param curTask task to submit
   * @param curTaskZKVersion current version of task
   */
void submitTask(final String curTask, final RecoveryMode mode, final int curTaskZKVersion, final int reportPeriod) {
    final MutableInt zkVersion = new MutableInt(curTaskZKVersion);
    CancelableProgressable reporter = new CancelableProgressable() {

        private long last_report_at = 0;

        @Override
        public boolean progress() {
            long t = EnvironmentEdgeManager.currentTime();
            if ((t - last_report_at) > reportPeriod) {
                last_report_at = t;
                int latestZKVersion = attemptToOwnTask(false, watcher, server.getServerName(), curTask, mode, zkVersion.intValue());
                if (latestZKVersion < 0) {
                    LOG.warn("Failed to heartbeat the task" + curTask);
                    return false;
                }
                zkVersion.setValue(latestZKVersion);
            }
            return true;
        }
    };
    ZkSplitLogWorkerCoordination.ZkSplitTaskDetails splitTaskDetails = new ZkSplitLogWorkerCoordination.ZkSplitTaskDetails();
    splitTaskDetails.setTaskNode(curTask);
    splitTaskDetails.setCurTaskZKVersion(zkVersion);
    WALSplitterHandler hsh = new WALSplitterHandler(server, this, splitTaskDetails, reporter, this.tasksInProgress, splitTaskExecutor, mode);
    server.getExecutorService().submit(hsh);
}
Also used : WALSplitterHandler(org.apache.hadoop.hbase.regionserver.handler.WALSplitterHandler) MutableInt(org.apache.commons.lang.mutable.MutableInt) CancelableProgressable(org.apache.hadoop.hbase.util.CancelableProgressable)

Example 22 with MutableInt

use of org.apache.commons.lang.mutable.MutableInt in project hive by apache.

the class LlapTaskSchedulerService method unregisterPendingPreemption.

private void unregisterPendingPreemption(String host) {
    writeLock.lock();
    try {
        pendingPreemptions.decrementAndGet();
        if (metrics != null) {
            metrics.decrPendingPreemptionTasksCount();
        }
        MutableInt val = pendingPreemptionsPerHost.get(host);
        Preconditions.checkNotNull(val);
        val.decrement();
    // Not bothering with removing the entry. There's a limited number of hosts, and a good
    // chance that the entry will make it back in when the AM is used for a long duration.
    } finally {
        writeLock.unlock();
    }
}
Also used : MutableInt(org.apache.commons.lang.mutable.MutableInt)

Example 23 with MutableInt

use of org.apache.commons.lang.mutable.MutableInt in project voldemort by voldemort.

the class PerformSerialGetAllRequests method execute.

public void execute(Pipeline pipeline) {
    Map<ByteArray, List<Versioned<byte[]>>> result = pipelineData.getResult();
    for (ByteArray key : keys) {
        boolean zoneRequirement = false;
        MutableInt successCount = pipelineData.getSuccessCount(key);
        if (logger.isDebugEnabled())
            logger.debug("GETALL for key " + ByteUtils.toHexString(key.get()) + " (keyRef: " + System.identityHashCode(key) + ") successes: " + successCount.intValue() + " preferred: " + preferred + " required: " + required);
        if (successCount.intValue() >= preferred) {
            if (pipelineData.getZonesRequired() != null && pipelineData.getZonesRequired() > 0) {
                if (pipelineData.getKeyToZoneResponse().containsKey(key)) {
                    int zonesSatisfied = pipelineData.getKeyToZoneResponse().get(key).size();
                    if (zonesSatisfied >= (pipelineData.getZonesRequired() + 1)) {
                        continue;
                    } else {
                        zoneRequirement = true;
                    }
                } else {
                    zoneRequirement = true;
                }
            } else {
                continue;
            }
        }
        List<Node> extraNodes = pipelineData.getKeyToExtraNodesMap().get(key);
        Map<ByteArray, byte[]> transforms = pipelineData.getTransforms();
        if (extraNodes == null)
            continue;
        for (Node node : extraNodes) {
            long start = System.nanoTime();
            try {
                Store<ByteArray, byte[], byte[]> store = stores.get(node.getId());
                List<Versioned<byte[]>> values;
                if (transforms == null)
                    values = store.get(key, null);
                else
                    values = store.get(key, transforms.get(key));
                if (values.size() != 0) {
                    if (result.get(key) == null)
                        result.put(key, Lists.newArrayList(values));
                    else
                        result.get(key).addAll(values);
                }
                Map<ByteArray, List<Versioned<byte[]>>> map = new HashMap<ByteArray, List<Versioned<byte[]>>>();
                map.put(key, values);
                Response<Iterable<ByteArray>, Map<ByteArray, List<Versioned<byte[]>>>> response = new Response<Iterable<ByteArray>, Map<ByteArray, List<Versioned<byte[]>>>>(node, Arrays.asList(key), map, ((System.nanoTime() - start) / Time.NS_PER_MS));
                successCount.increment();
                pipelineData.getResponses().add(response);
                failureDetector.recordSuccess(response.getNode(), response.getRequestTime());
                if (logger.isDebugEnabled())
                    logger.debug("GET for key " + ByteUtils.toHexString(key.get()) + " (keyRef: " + System.identityHashCode(key) + ") successes: " + successCount.intValue() + " preferred: " + preferred + " required: " + required + " new GET success on node " + node.getId());
                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());
                if (zoneRequirement) {
                    if (zoneResponses.size() >= pipelineData.getZonesRequired())
                        break;
                } else {
                    if (successCount.intValue() >= preferred)
                        break;
                }
            } catch (Exception e) {
                long requestTime = (System.nanoTime() - start) / Time.NS_PER_MS;
                if (handleResponseError(e, node, requestTime, pipeline, failureDetector))
                    return;
            }
        }
    }
    for (ByteArray key : keys) {
        MutableInt successCount = pipelineData.getSuccessCount(key);
        if (successCount.intValue() < required) {
            // not meet 'required' guarantee; else raise error
            if (allowPartial) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Excluding Key " + ByteUtils.toHexString(key.get()) + " from partial get_all result");
                }
                result.remove(key);
            } else {
                pipelineData.setFatalError(new InsufficientOperationalNodesException(required + " " + pipeline.getOperation().getSimpleName() + "s required, but " + successCount.intValue() + " succeeded. Failing nodes : " + pipelineData.getFailedNodes(), pipelineData.getFailures()));
                pipeline.addEvent(Event.ERROR);
                return;
            }
        }
    }
    pipeline.addEvent(completeEvent);
}
Also used : Versioned(voldemort.versioning.Versioned) HashMap(java.util.HashMap) Node(voldemort.cluster.Node) InsufficientOperationalNodesException(voldemort.store.InsufficientOperationalNodesException) Response(voldemort.store.routed.Response) MutableInt(org.apache.commons.lang.mutable.MutableInt) InsufficientOperationalNodesException(voldemort.store.InsufficientOperationalNodesException) ByteArray(voldemort.utils.ByteArray) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with MutableInt

use of org.apache.commons.lang.mutable.MutableInt in project voldemort by voldemort.

the class GetAllPipelineData method getSuccessCount.

public MutableInt getSuccessCount(ByteArray key) {
    MutableInt value = keyToSuccessCount.get(key);
    if (value == null) {
        value = new MutableInt(0);
        keyToSuccessCount.put(key, value);
    }
    return value;
}
Also used : MutableInt(org.apache.commons.lang.mutable.MutableInt)

Example 25 with MutableInt

use of org.apache.commons.lang.mutable.MutableInt in project voldemort by voldemort.

the class VoldemortClientShell method processGetAll.

/**
     *
     * @param getAllArgStr space separated list of key strings
     */
protected void processGetAll(String getAllArgStr) {
    List<Object> keys = new ArrayList<Object>();
    MutableInt parsePos = new MutableInt(0);
    while (true) {
        Object key = parseKey(getAllArgStr, parsePos);
        if (key == null) {
            break;
        }
        keys.add(key);
        getAllArgStr = getAllArgStr.substring(parsePos.intValue());
    }
    Map<Object, Versioned<Object>> vals = client.getAll(keys);
    if (vals.size() > 0) {
        for (Map.Entry<Object, Versioned<Object>> entry : vals.entrySet()) {
            commandOutput.print(entry.getKey());
            commandOutput.print(" => ");
            printVersioned(entry.getValue());
        }
    } else {
        commandOutput.println("null");
    }
}
Also used : Versioned(voldemort.versioning.Versioned) MutableInt(org.apache.commons.lang.mutable.MutableInt) ArrayList(java.util.ArrayList) 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