Search in sources :

Example 71 with StaticBuffer

use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.

the class StandardScannerExecutor method run.

@Override
public void run() {
    BlockingQueue<Row> processorQueue;
    try {
        job.workerIterationStart(jobConfiguration, graphConfiguration, metrics);
        List<SliceQuery> queries = job.getQueries();
        int numQueries = queries.size();
        processorQueue = new LinkedBlockingQueue<>(this.graphConfiguration.get(GraphDatabaseConfiguration.PAGE_SIZE) * numProcessors * numQueries);
        Preconditions.checkArgument(numQueries > 0, "Must at least specify one query for job: %s", job);
        if (numQueries > 1) {
            // It is assumed that the first query is the grounding query if multiple queries exist
            SliceQuery ground = queries.get(0);
            StaticBuffer start = ground.getSliceStart();
            Preconditions.checkArgument(start.equals(BufferUtil.zeroBuffer(1)), "Expected start of first query to be a single 0s: %s", start);
            StaticBuffer end = ground.getSliceEnd();
            Preconditions.checkArgument(end.equals(BufferUtil.oneBuffer(end.length())), "Expected end of first query to be all 1s: %s", end);
        }
        rowsCollector = buildScanner(processorQueue, queries);
    } catch (Throwable e) {
        log.error("Exception trying to setup the job:", e);
        cleanupSilent();
        job.workerIterationEnd(metrics);
        setException(e);
        return;
    }
    Processor[] processors = new Processor[numProcessors];
    for (int i = 0; i < processors.length; i++) {
        processors[i] = new Processor(job.clone(), processorQueue);
        processors[i].start();
    }
    try {
        rowsCollector.run();
        rowsCollector.join();
        for (Processor processor : processors) {
            processor.finish();
        }
        if (!Threads.waitForCompletion(processors, TIMEOUT_MS))
            log.error("Processor did not terminate in time");
        cleanup();
        try {
            job.workerIterationEnd(metrics);
        } catch (IllegalArgumentException e) {
            // https://github.com/JanusGraph/janusgraph/pull/891
            log.warn("Exception occurred processing worker iteration end. See PR 891.", e);
        }
        if (interrupted) {
            setException(new InterruptedException("Scanner got interrupted"));
        } else {
            finishJob.accept(metrics);
            set(metrics);
        }
    } catch (Throwable e) {
        log.error("Exception occurred during job execution:", e);
        job.workerIterationEnd(metrics);
        setException(e);
    } finally {
        Threads.terminate(processors);
        cleanupSilent();
    }
}
Also used : StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) SliceQuery(org.janusgraph.diskstorage.keycolumnvalue.SliceQuery)

Example 72 with StaticBuffer

use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.

the class CacheTransaction method convert.

private KCVMutation convert(KCVEntryMutation mutation) {
    assert !mutation.isEmpty();
    if (mutation.hasDeletions()) {
        return new KCVMutation(() -> new ArrayList<>(mutation.getAdditions()), () -> {
            List<Entry> deletions = mutation.getDeletions();
            ArrayList<StaticBuffer> convertedDeletions = new ArrayList<>(deletions.size());
            for (Entry entry : deletions) {
                convertedDeletions.add(KCVEntryMutation.ENTRY2COLUMN_FCT.apply(entry));
            }
            return convertedDeletions;
        });
    }
    return new KCVMutation(mutation.getAdditions(), KeyColumnValueStore.NO_DELETIONS);
}
Also used : Entry(org.janusgraph.diskstorage.Entry) ArrayList(java.util.ArrayList) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) KCVMutation(org.janusgraph.diskstorage.keycolumnvalue.KCVMutation)

Example 73 with StaticBuffer

use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.

the class CQLResultSetKeyIteratorTest method testNoIterateColumns.

@Test
public void testNoIterateColumns() throws IOException {
    final Array<Tuple2<ByteBuffer, Array<Tuple2<ByteBuffer, ByteBuffer>>>> keysMap = generateRandomKeysMap();
    final ResultSet resultSet = generateMockedResultSet(keysMap);
    final CQLColValGetter getter = new CQLColValGetter(new EntryMetaData[0]);
    try (final CQLResultSetKeyIterator resultSetKeyIterator = new CQLResultSetKeyIterator(ALL_COLUMNS, getter, resultSet)) {
        final Iterator<Tuple2<ByteBuffer, Array<Tuple2<ByteBuffer, ByteBuffer>>>> iterator = keysMap.iterator();
        while (resultSetKeyIterator.hasNext()) {
            final StaticBuffer next = resultSetKeyIterator.next();
            assertEquals(iterator.next()._1, next.asByteBuffer());
        }
    }
}
Also used : Tuple2(io.vavr.Tuple2) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) Test(org.junit.jupiter.api.Test)

Example 74 with StaticBuffer

use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.

the class CQLResultSetKeyIteratorTest method testUneven.

@Test
public void testUneven() throws IOException {
    final Array<Tuple2<ByteBuffer, Array<Tuple2<ByteBuffer, ByteBuffer>>>> keysMap = generateRandomKeysMap();
    final ResultSet resultSet = generateMockedResultSet(keysMap);
    final CQLColValGetter getter = new CQLColValGetter(new EntryMetaData[0]);
    try (final CQLResultSetKeyIterator resultSetKeyIterator = new CQLResultSetKeyIterator(ALL_COLUMNS, getter, resultSet)) {
        final Iterator<Tuple2<ByteBuffer, Array<Tuple2<ByteBuffer, ByteBuffer>>>> iterator = keysMap.iterator();
        while (resultSetKeyIterator.hasNext()) {
            final StaticBuffer next = resultSetKeyIterator.next();
            try (final RecordIterator<Entry> entries = resultSetKeyIterator.getEntries()) {
                final Tuple2<ByteBuffer, Array<Tuple2<ByteBuffer, ByteBuffer>>> current = iterator.next();
                final ByteBuffer currentKey = current._1;
                final Array<Tuple2<ByteBuffer, ByteBuffer>> columnValues = current._2;
                final Iterator<Tuple2<ByteBuffer, ByteBuffer>> columnIterator = columnValues.iterator();
                while (entries.hasNext()) {
                    final Entry entry = entries.next();
                    final Tuple2<ByteBuffer, ByteBuffer> columnAndValue = columnIterator.next();
                    assertEquals(currentKey, next.asByteBuffer());
                    assertEquals(columnAndValue._1, entry.getColumn().asByteBuffer());
                    assertEquals(columnAndValue._2, entry.getValue().asByteBuffer());
                    assertEquals(columnIterator.hasNext(), entries.hasNext());
                }
            }
        }
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) Array(io.vavr.collection.Array) Entry(org.janusgraph.diskstorage.Entry) Tuple2(io.vavr.Tuple2) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) Test(org.junit.jupiter.api.Test)

Example 75 with StaticBuffer

use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.

the class CqlBinaryRecordReader method completeNextKV.

private KV completeNextKV() throws IOException {
    KV completedKV = null;
    boolean hasNext;
    do {
        hasNext = reader.nextKeyValue();
        if (!hasNext) {
            completedKV = incompleteKV;
            incompleteKV = null;
        } else {
            Row row = reader.getCurrentValue();
            StaticArrayBuffer key = StaticArrayBuffer.of(row.getBytesUnsafe(CQLKeyColumnValueStore.KEY_COLUMN_NAME));
            StaticBuffer column1 = StaticArrayBuffer.of(row.getBytesUnsafe(CQLKeyColumnValueStore.COLUMN_COLUMN_NAME));
            StaticBuffer value = StaticArrayBuffer.of(row.getBytesUnsafe(CQLKeyColumnValueStore.VALUE_COLUMN_NAME));
            Entry entry = StaticArrayEntry.of(column1, value);
            if (null == incompleteKV) {
                // Initialization; this should happen just once in an instance's lifetime
                incompleteKV = new KV(key);
            } else if (!incompleteKV.key.equals(key)) {
                // The underlying Cassandra reader has just changed to a key we haven't seen yet
                // This implies that there will be no more entries for the prior key
                completedKV = incompleteKV;
                incompleteKV = new KV(key);
            }
            incompleteKV.addEntry(entry);
        }
    /* Loop ends when either
             * A) the cassandra reader ran out of data
             * or
             * B) the cassandra reader switched keys, thereby completing a KV */
    } while (hasNext && null == completedKV);
    return completedKV;
}
Also used : Entry(org.janusgraph.diskstorage.Entry) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) StaticArrayBuffer(org.janusgraph.diskstorage.util.StaticArrayBuffer) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) Row(com.datastax.driver.core.Row)

Aggregations

StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)101 Entry (org.janusgraph.diskstorage.Entry)36 Test (org.junit.jupiter.api.Test)36 ArrayList (java.util.ArrayList)27 HashMap (java.util.HashMap)20 Map (java.util.Map)19 StoreTransaction (org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction)17 KeySliceQuery (org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)16 StaticArrayEntry (org.janusgraph.diskstorage.util.StaticArrayEntry)16 BackendException (org.janusgraph.diskstorage.BackendException)15 List (java.util.List)14 EntryList (org.janusgraph.diskstorage.EntryList)14 TemporaryBackendException (org.janusgraph.diskstorage.TemporaryBackendException)14 KCVMutation (org.janusgraph.diskstorage.keycolumnvalue.KCVMutation)13 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)12 Instant (java.time.Instant)11 DataOutput (org.janusgraph.graphdb.database.serialize.DataOutput)10 ReadBuffer (org.janusgraph.diskstorage.ReadBuffer)8 ConsistentKeyLockStatus (org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus)7 BackendOperation (org.janusgraph.diskstorage.util.BackendOperation)7