Search in sources :

Example 1 with Trace

use of org.apache.accumulo.core.trace.Trace in project vertexium by visallo.

the class AccumuloFindPathStrategy method getConnectedVertexIds.

private Map<String, Set<String>> getConnectedVertexIds(Set<String> vertexIds) {
    Span trace = Trace.start("getConnectedVertexIds");
    try {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("getConnectedVertexIds:\n  %s", IterableUtils.join(vertexIds, "\n  "));
        }
        if (vertexIds.size() == 0) {
            return new HashMap<>();
        }
        List<org.apache.accumulo.core.data.Range> ranges = new ArrayList<>();
        for (String vertexId : vertexIds) {
            ranges.add(RangeUtils.createRangeFromString(vertexId));
        }
        int maxVersions = 1;
        Long startTime = null;
        Long endTime = null;
        ScannerBase scanner = graph.createElementScanner(FetchHints.EDGE_REFS, ElementType.VERTEX, maxVersions, startTime, endTime, ranges, false, authorizations);
        IteratorSetting connectedVertexIdsIteratorSettings = new IteratorSetting(1000, ConnectedVertexIdsIterator.class.getSimpleName(), ConnectedVertexIdsIterator.class);
        ConnectedVertexIdsIterator.setLabels(connectedVertexIdsIteratorSettings, deflatedLabels);
        ConnectedVertexIdsIterator.setExcludedLabels(connectedVertexIdsIteratorSettings, deflatedExcludedLabels);
        scanner.addScanIterator(connectedVertexIdsIteratorSettings);
        final long timerStartTime = System.currentTimeMillis();
        try {
            Map<String, Set<String>> results = new HashMap<>();
            for (Map.Entry<Key, Value> row : scanner) {
                try {
                    Map<String, Boolean> verticesExist = graph.doVerticesExist(ConnectedVertexIdsIterator.decodeValue(row.getValue()), authorizations);
                    Set<String> rowVertexIds = stream(verticesExist.keySet()).filter(key -> verticesExist.getOrDefault(key, false)).collect(Collectors.toSet());
                    results.put(row.getKey().getRow().toString(), rowVertexIds);
                } catch (IOException e) {
                    throw new VertexiumException("Could not decode vertex ids for row: " + row.getKey().toString(), e);
                }
            }
            return results;
        } finally {
            scanner.close();
            AccumuloGraph.GRAPH_LOGGER.logEndIterator(System.currentTimeMillis() - timerStartTime);
        }
    } finally {
        trace.stop();
    }
}
Also used : java.util(java.util) Trace(org.apache.accumulo.core.trace.Trace) ConnectedVertexIdsIterator(org.vertexium.accumulo.iterator.ConnectedVertexIdsIterator) VertexiumLogger(org.vertexium.util.VertexiumLogger) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) VertexiumLoggerFactory(org.vertexium.util.VertexiumLoggerFactory) ScannerBase(org.apache.accumulo.core.client.ScannerBase) org.vertexium(org.vertexium) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) IterableUtils(org.vertexium.util.IterableUtils) StreamUtils.stream(org.vertexium.util.StreamUtils.stream) Key(org.apache.accumulo.core.data.Key) Value(org.apache.accumulo.core.data.Value) Span(org.apache.accumulo.core.trace.Span) RangeUtils(org.vertexium.accumulo.util.RangeUtils) Span(org.apache.accumulo.core.trace.Span) ConnectedVertexIdsIterator(org.vertexium.accumulo.iterator.ConnectedVertexIdsIterator) ScannerBase(org.apache.accumulo.core.client.ScannerBase) IOException(java.io.IOException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key)

Aggregations

IOException (java.io.IOException)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)1 ScannerBase (org.apache.accumulo.core.client.ScannerBase)1 Key (org.apache.accumulo.core.data.Key)1 Value (org.apache.accumulo.core.data.Value)1 Span (org.apache.accumulo.core.trace.Span)1 Trace (org.apache.accumulo.core.trace.Trace)1 org.vertexium (org.vertexium)1 ConnectedVertexIdsIterator (org.vertexium.accumulo.iterator.ConnectedVertexIdsIterator)1 RangeUtils (org.vertexium.accumulo.util.RangeUtils)1 IterableUtils (org.vertexium.util.IterableUtils)1 StreamUtils.stream (org.vertexium.util.StreamUtils.stream)1 VertexiumLogger (org.vertexium.util.VertexiumLogger)1 VertexiumLoggerFactory (org.vertexium.util.VertexiumLoggerFactory)1