Search in sources :

Example 6 with IntCursor

use of com.carrotsearch.hppc.cursors.IntCursor in project crate by crate.

the class BulkShardProcessor method processFailure.

private void processFailure(Throwable e, final ShardId shardId, final Request request, Optional<BulkRetryCoordinator> retryCoordinator) {
    trace("execute failure");
    e = SQLExceptions.unwrap(e);
    // index missing exception on a partition should never bubble, mark all items as failed instead
    if (e instanceof IndexNotFoundException && PartitionName.isPartition(request.index())) {
        indicesDeleted.add(request.index());
        markItemsAsFailedAndReleaseRetryLock(request, retryCoordinator);
        return;
    }
    final BulkRetryCoordinator coordinator;
    if (retryCoordinator.isPresent()) {
        coordinator = retryCoordinator.get();
    } else {
        try {
            coordinator = bulkRetryCoordinatorPool.coordinator(shardId);
        } catch (Throwable coordinatorException) {
            setFailure(coordinatorException);
            return;
        }
    }
    if (e instanceof EsRejectedExecutionException) {
        trace("rejected execution: [%s] - retrying", e.getMessage());
        coordinator.retry(request, requestExecutor, new ActionListener<ShardResponse>() {

            @Override
            public void onResponse(ShardResponse response) {
                processResponse(response);
            }

            @Override
            public void onFailure(Throwable e) {
                processFailure(e, shardId, request, Optional.of(coordinator));
            }
        });
    } else {
        if (retryCoordinator.isPresent()) {
            // release failed retry
            coordinator.releaseWriteLock();
        }
        for (IntCursor intCursor : request.itemIndices()) {
            synchronized (responsesLock) {
                responses.set(intCursor.value, false);
            }
        }
        setFailure(e);
    }
}
Also used : ShardResponse(io.crate.executor.transport.ShardResponse) IntCursor(com.carrotsearch.hppc.cursors.IntCursor) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)

Example 7 with IntCursor

use of com.carrotsearch.hppc.cursors.IntCursor in project crate by crate.

the class NodeFetchRequest method writeTo.

@Override
public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);
    out.writeLong(jobId.getMostSignificantBits());
    out.writeLong(jobId.getLeastSignificantBits());
    out.writeVInt(fetchPhaseId);
    out.writeBoolean(closeContext);
    if (toFetch == null) {
        out.writeVInt(0);
    } else {
        out.writeVInt(toFetch.size());
        for (IntObjectCursor<? extends IntContainer> toFetchCursor : toFetch) {
            out.writeVInt(toFetchCursor.key);
            out.writeVInt(toFetchCursor.value.size());
            for (IntCursor docCursor : toFetchCursor.value) {
                out.writeInt(docCursor.value);
            }
        }
    }
}
Also used : IntCursor(com.carrotsearch.hppc.cursors.IntCursor)

Example 8 with IntCursor

use of com.carrotsearch.hppc.cursors.IntCursor in project graphhopper by graphhopper.

the class ChangeGraphHelper method applyChange.

private long applyChange(JsonFeature jsonFeature, FlagEncoder encoder) {
    long updates = 0;
    EdgeFilter filter = new DefaultEdgeFilter(encoder);
    GHIntHashSet edges = new GHIntHashSet();
    if (jsonFeature.hasGeometry()) {
        graphBrowser.fillEdgeIDs(edges, jsonFeature.getGeometry(), filter);
    } else if (jsonFeature.getBBox() != null) {
        graphBrowser.findEdgesInShape(edges, jsonFeature.getBBox(), filter);
    } else
        throw new IllegalArgumentException("Feature " + jsonFeature.getId() + " has no geometry and no bbox");
    Iterator<IntCursor> iter = edges.iterator();
    Map<String, Object> props = jsonFeature.getProperties();
    while (iter.hasNext()) {
        int edgeId = iter.next().value;
        EdgeIteratorState edge = graph.getEdgeIteratorState(edgeId, Integer.MIN_VALUE);
        if (props.containsKey("access")) {
            boolean value = (boolean) props.get("access");
            updates++;
            if (enableLogging)
                logger.info(encoder.toString() + " - access change via feature " + jsonFeature.getId());
            edge.setFlags(encoder.setAccess(edge.getFlags(), value, value));
        } else if (props.containsKey("speed")) {
            // TODO use different speed for the different directions (see e.g. Bike2WeightFlagEncoder)
            double value = ((Number) props.get("speed")).doubleValue();
            double oldSpeed = encoder.getSpeed(edge.getFlags());
            if (oldSpeed != value) {
                updates++;
                if (enableLogging)
                    logger.info(encoder.toString() + " - speed change via feature " + jsonFeature.getId() + ". Old: " + oldSpeed + ", new:" + value);
                edge.setFlags(encoder.setSpeed(edge.getFlags(), value));
            }
        }
    }
    return updates;
}
Also used : GHIntHashSet(com.graphhopper.coll.GHIntHashSet) DefaultEdgeFilter(com.graphhopper.routing.util.DefaultEdgeFilter) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) EdgeFilter(com.graphhopper.routing.util.EdgeFilter) DefaultEdgeFilter(com.graphhopper.routing.util.DefaultEdgeFilter) IntCursor(com.carrotsearch.hppc.cursors.IntCursor)

Example 9 with IntCursor

use of com.carrotsearch.hppc.cursors.IntCursor in project graphhopper by graphhopper.

the class LocationIndexTree method calcMinDistance.

final double calcMinDistance(double queryLat, double queryLon, GHIntHashSet pointset) {
    double min = Double.MAX_VALUE;
    Iterator<IntCursor> itr = pointset.iterator();
    while (itr.hasNext()) {
        int node = itr.next().value;
        double lat = nodeAccess.getLat(node);
        double lon = nodeAccess.getLon(node);
        double dist = distCalc.calcDist(queryLat, queryLon, lat, lon);
        if (dist < min) {
            min = dist;
        }
    }
    return min;
}
Also used : IntCursor(com.carrotsearch.hppc.cursors.IntCursor) GHPoint(com.graphhopper.util.shapes.GHPoint)

Aggregations

IntCursor (com.carrotsearch.hppc.cursors.IntCursor)9 IntObjectHashMap (com.carrotsearch.hppc.IntObjectHashMap)1 IntObjectMap (com.carrotsearch.hppc.IntObjectMap)1 IntSet (com.carrotsearch.hppc.IntSet)1 GHIntHashSet (com.graphhopper.coll.GHIntHashSet)1 DefaultEdgeFilter (com.graphhopper.routing.util.DefaultEdgeFilter)1 EdgeFilter (com.graphhopper.routing.util.EdgeFilter)1 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)1 GHPoint (com.graphhopper.util.shapes.GHPoint)1 BatchConsumer (io.crate.data.BatchConsumer)1 ShardResponse (io.crate.executor.transport.ShardResponse)1 StreamBucket (io.crate.executor.transport.StreamBucket)1 ProjectingBatchConsumer (io.crate.operation.projectors.ProjectingBatchConsumer)1 ExecutionPhase (io.crate.planner.node.ExecutionPhase)1 FetchSource (io.crate.planner.node.fetch.FetchSource)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 EsRejectedExecutionException (org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)1