Search in sources :

Example 51 with Entry

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

the class KCVSConfiguration method set.

public <O> void set(String key, O value, O expectedValue, final boolean checkExpectedValue) {
    final StaticBuffer column = string2StaticBuffer(key);
    final List<Entry> additions;
    final List<StaticBuffer> deletions;
    if (value != null) {
        // Addition
        additions = new ArrayList<>(1);
        deletions = KeyColumnValueStore.NO_DELETIONS;
        StaticBuffer val = object2StaticBuffer(value);
        additions.add(StaticArrayEntry.of(column, val));
    } else {
        // Deletion
        additions = KeyColumnValueStore.NO_ADDITIONS;
        deletions = new ArrayList<>(1);
        deletions.add(column);
    }
    final StaticBuffer expectedValueBuffer;
    if (checkExpectedValue && expectedValue != null) {
        expectedValueBuffer = object2StaticBuffer(expectedValue);
    } else {
        expectedValueBuffer = null;
    }
    BackendOperation.execute(new BackendOperation.Transactional<Boolean>() {

        @Override
        public Boolean call(StoreTransaction txh) throws BackendException {
            if (checkExpectedValue)
                store.acquireLock(rowKey, column, expectedValueBuffer, txh);
            store.mutate(rowKey, additions, deletions, txh);
            return true;
        }

        @Override
        public String toString() {
            return "setConfiguration";
        }
    }, txProvider, times, maxOperationWaitTime);
}
Also used : StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) Entry(org.janusgraph.diskstorage.Entry) StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) BackendOperation(org.janusgraph.diskstorage.util.BackendOperation) BackendException(org.janusgraph.diskstorage.BackendException)

Example 52 with Entry

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

the class SliceQuery method getSubset.

// TODO: make this more efficient by using reuseIterator() on otherResult
public EntryList getSubset(final SliceQuery otherQuery, final EntryList otherResult) {
    assert otherQuery.subsumes(this);
    int pos = Collections.binarySearch(otherResult, sliceStart);
    if (pos < 0)
        pos = -pos - 1;
    final List<Entry> result = new ArrayList<>();
    for (; pos < otherResult.size() && result.size() < getLimit(); pos++) {
        Entry e = otherResult.get(pos);
        if (e.getColumnAs(StaticBuffer.STATIC_FACTORY).compareTo(sliceEnd) < 0)
            result.add(e);
        else
            break;
    }
    return EntryArrayList.of(result);
}
Also used : Entry(org.janusgraph.diskstorage.Entry) EntryArrayList(org.janusgraph.diskstorage.util.EntryArrayList) ArrayList(java.util.ArrayList)

Example 53 with Entry

use of org.janusgraph.diskstorage.Entry 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 54 with Entry

use of org.janusgraph.diskstorage.Entry 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 55 with Entry

use of org.janusgraph.diskstorage.Entry 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

Entry (org.janusgraph.diskstorage.Entry)62 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)36 StaticArrayEntry (org.janusgraph.diskstorage.util.StaticArrayEntry)29 Test (org.junit.jupiter.api.Test)23 ArrayList (java.util.ArrayList)22 StoreTransaction (org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction)19 KeySliceQuery (org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)16 EntryList (org.janusgraph.diskstorage.EntryList)15 HashMap (java.util.HashMap)12 Map (java.util.Map)11 BackendException (org.janusgraph.diskstorage.BackendException)10 List (java.util.List)9 KCVMutation (org.janusgraph.diskstorage.keycolumnvalue.KCVMutation)9 BaseTransactionConfig (org.janusgraph.diskstorage.BaseTransactionConfig)8 BufferPageTest.makeEntry (org.janusgraph.diskstorage.inmemory.BufferPageTest.makeEntry)8 Instant (java.time.Instant)7 BackendOperation (org.janusgraph.diskstorage.util.BackendOperation)6 BufferPageTest.makeStaticBuffer (org.janusgraph.diskstorage.inmemory.BufferPageTest.makeStaticBuffer)5 StaticArrayBuffer (org.janusgraph.diskstorage.util.StaticArrayBuffer)5 StaticArrayEntryList (org.janusgraph.diskstorage.util.StaticArrayEntryList)5