Search in sources :

Example 16 with Entry

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

the class OrderedKeyValueStoreManagerAdapter method mutateMany.

@Override
public void mutateMany(Map<String, Map<StaticBuffer, KCVMutation>> mutations, StoreTransaction txh) throws BackendException {
    final Map<String, KVMutation> converted = new HashMap<>(mutations.size());
    for (Map.Entry<String, Map<StaticBuffer, KCVMutation>> storeEntry : mutations.entrySet()) {
        OrderedKeyValueStoreAdapter store = openDatabase(storeEntry.getKey());
        Preconditions.checkNotNull(store);
        KVMutation mut = new KVMutation();
        for (Map.Entry<StaticBuffer, KCVMutation> entry : storeEntry.getValue().entrySet()) {
            StaticBuffer key = entry.getKey();
            KCVMutation mutation = entry.getValue();
            if (mutation.hasAdditions()) {
                for (Entry addition : mutation.getAdditions()) {
                    mut.addition(store.concatenate(key, addition));
                }
            }
            if (mutation.hasDeletions()) {
                for (StaticBuffer del : mutation.getDeletions()) {
                    mut.deletion(store.concatenate(key, del));
                }
            }
        }
        converted.put(storeEntry.getKey(), mut);
    }
    manager.mutateMany(converted, txh);
}
Also used : Entry(org.janusgraph.diskstorage.Entry) HashMap(java.util.HashMap) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 17 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 = Lists.newArrayList(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) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) BackendOperation(org.janusgraph.diskstorage.util.BackendOperation) BackendException(org.janusgraph.diskstorage.BackendException)

Example 18 with Entry

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

the class KCVSConfiguration method toMap.

private Map<String, Object> toMap() {
    Map<String, Object> entries = Maps.newHashMap();
    List<Entry> result = BackendOperation.execute(new BackendOperation.Transactional<List<Entry>>() {

        @Override
        public List<Entry> call(StoreTransaction txh) throws BackendException {
            return store.getSlice(new KeySliceQuery(rowKey, BufferUtil.zeroBuffer(1), BufferUtil.oneBuffer(128)), txh);
        }

        @Override
        public String toString() {
            return "setConfiguration";
        }
    }, txProvider, times, maxOperationWaitTime);
    for (Entry entry : result) {
        String key = staticBuffer2String(entry.getColumnAs(StaticBuffer.STATIC_FACTORY));
        Object value = staticBuffer2Object(entry.getValueAs(StaticBuffer.STATIC_FACTORY), Object.class);
        entries.put(key, value);
    }
    return entries;
}
Also used : StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) Entry(org.janusgraph.diskstorage.Entry) ArrayList(java.util.ArrayList) List(java.util.List) BackendOperation(org.janusgraph.diskstorage.util.BackendOperation) BackendException(org.janusgraph.diskstorage.BackendException)

Example 19 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 StaticArrayEntryList.of(result);
}
Also used : Entry(org.janusgraph.diskstorage.Entry) ArrayList(java.util.ArrayList)

Example 20 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 Random random = new Random();
    final Function1<Integer, ByteBuffer> randomLong = idx -> {
        final ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES).putLong(random.nextLong());
        buffer.flip();
        return buffer;
    };
    final Array<Tuple2<ByteBuffer, Array<Tuple2<ByteBuffer, ByteBuffer>>>> keysMap = Array.range(0, random.nextInt(100) + 100).map(randomLong).map(key -> Tuple.of(key, Array.rangeClosed(0, random.nextInt(100) + 1).map(idx -> Tuple.of(randomLong.apply(idx), randomLong.apply(idx)))));
    final Seq<Row> rows = keysMap.flatMap(tuple -> tuple._2.map(columnAndValue -> {
        final Row row = mock(Row.class);
        when(row.getBytes("key")).thenReturn(tuple._1);
        when(row.getBytes("column1")).thenReturn(columnAndValue._1);
        when(row.getBytes("value")).thenReturn(columnAndValue._2);
        return row;
    }));
    final ResultSet resultSet = mock(ResultSet.class);
    when(resultSet.iterator()).thenReturn(rows.iterator());
    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 : Tuple(io.vavr.Tuple) EntryMetaData(org.janusgraph.diskstorage.EntryMetaData) Row(com.datastax.driver.core.Row) SliceQuery(org.janusgraph.diskstorage.keycolumnvalue.SliceQuery) Array(io.vavr.collection.Array) IOException(java.io.IOException) Random(java.util.Random) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Function1(io.vavr.Function1) ByteBuffer(java.nio.ByteBuffer) RecordIterator(org.janusgraph.diskstorage.util.RecordIterator) ResultSet(com.datastax.driver.core.ResultSet) Tuple2(io.vavr.Tuple2) Assert.assertFalse(org.junit.Assert.assertFalse) Entry(org.janusgraph.diskstorage.Entry) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) BufferUtil(org.janusgraph.diskstorage.util.BufferUtil) Iterator(io.vavr.collection.Iterator) Seq(io.vavr.collection.Seq) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) ByteBuffer(java.nio.ByteBuffer) Array(io.vavr.collection.Array) Entry(org.janusgraph.diskstorage.Entry) Random(java.util.Random) Tuple2(io.vavr.Tuple2) ResultSet(com.datastax.driver.core.ResultSet) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) Row(com.datastax.driver.core.Row) Test(org.junit.Test)

Aggregations

Entry (org.janusgraph.diskstorage.Entry)24 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)13 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)6 Map (java.util.Map)5 StaticArrayEntry (org.janusgraph.diskstorage.util.StaticArrayEntry)5 ByteBuffer (java.nio.ByteBuffer)4 HashMap (java.util.HashMap)4 ResultSet (com.datastax.driver.core.ResultSet)3 Row (com.datastax.driver.core.Row)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Instant (java.time.Instant)3 List (java.util.List)3 EntryList (org.janusgraph.diskstorage.EntryList)3 Function1 (io.vavr.Function1)2 Tuple (io.vavr.Tuple)2 Tuple2 (io.vavr.Tuple2)2 Array (io.vavr.collection.Array)2 Iterator (io.vavr.collection.Iterator)2