Search in sources :

Example 56 with Entry

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

the class KCVSLog method writeSetting.

private void writeSetting(String identifier, final StaticBuffer column, long value) {
    final StaticBuffer key = getSettingKey(identifier);
    final Entry add = StaticArrayEntry.of(column, BufferUtil.getLongBuffer(value));
    Boolean status = BackendOperation.execute(new BackendOperation.Transactional<Boolean>() {

        @Override
        public Boolean call(StoreTransaction txh) throws BackendException {
            store.mutate(key, Collections.singletonList(add), KeyColumnValueStore.NO_DELETIONS, txh);
            return Boolean.TRUE;
        }

        @Override
        public String toString() {
            return "writingLogSetting";
        }
    }, this, times, maxWriteTime);
    Preconditions.checkState(status);
}
Also used : Entry(org.janusgraph.diskstorage.Entry) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) BackendOperation(org.janusgraph.diskstorage.util.BackendOperation) BackendException(org.janusgraph.diskstorage.BackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException)

Example 57 with Entry

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

the class StaticArrayEntryTest method testEntryListWithMetaSchema.

/**
 * Copied from above - the only difference is using schema instances and checking the schema
 */
@Test
public void testEntryListWithMetaSchema() {
    final Map<Integer, Long> entries = generateRandomEntries();
    EntryList[] el = generateEntryListArray(entries, "SCHEMA_INSTANCE");
    for (final EntryList anEl : el) {
        // System.out.println("Iteration: " + i);
        assertEquals(entries.size(), anEl.size());
        int num = 0;
        for (final Entry e : anEl) {
            checkEntry(e, entries);
            assertTrue(e.hasMetaData());
            assertFalse(e.getMetaData().isEmpty());
            assertEquals(metaData, e.getMetaData());
            assertNull(e.getCache());
            e.setCache(cache);
            num++;
        }
        assertEquals(entries.size(), num);
        final Iterator<Entry> iter = anEl.reuseIterator();
        num = 0;
        while (iter.hasNext()) {
            final Entry e = iter.next();
            assertTrue(e.hasMetaData());
            assertFalse(e.getMetaData().isEmpty());
            assertEquals(metaData, e.getMetaData());
            assertEquals(cache, e.getCache());
            checkEntry(e, entries);
            num++;
        }
        assertEquals(entries.size(), num);
    }
}
Also used : StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) Entry(org.janusgraph.diskstorage.Entry) StaticArrayEntryList(org.janusgraph.diskstorage.util.StaticArrayEntryList) EntryList(org.janusgraph.diskstorage.EntryList) Test(org.junit.jupiter.api.Test)

Example 58 with Entry

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

the class StaticArrayEntryTest method testEntryList.

@Test
public void testEntryList() {
    final Map<Integer, Long> entries = generateRandomEntries();
    EntryList[] el = generateEntryListArray(entries, "INSTANCE");
    for (final EntryList anEl : el) {
        assertEquals(entries.size(), anEl.size());
        int num = 0;
        for (final Entry e : anEl) {
            checkEntry(e, entries);
            assertFalse(e.hasMetaData());
            assertTrue(e.getMetaData().isEmpty());
            assertNull(e.getCache());
            e.setCache(cache);
            num++;
        }
        assertEquals(entries.size(), num);
        final Iterator<Entry> iterator = anEl.reuseIterator();
        num = 0;
        while (iterator.hasNext()) {
            final Entry e = iterator.next();
            checkEntry(e, entries);
            assertFalse(e.hasMetaData());
            assertTrue(e.getMetaData().isEmpty());
            assertEquals(cache, e.getCache());
            num++;
        }
        assertEquals(entries.size(), num);
    }
}
Also used : StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) Entry(org.janusgraph.diskstorage.Entry) StaticArrayEntryList(org.janusgraph.diskstorage.util.StaticArrayEntryList) EntryList(org.janusgraph.diskstorage.EntryList) Test(org.junit.jupiter.api.Test)

Example 59 with Entry

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

the class ConsistentKeyLockerTest method recordSuccessfulLockWrite.

private LockInfo recordSuccessfulLockWrite(StoreTransaction tx, long duration, TemporalUnit tu, StaticBuffer del) throws BackendException {
    currentTimeNS = currentTimeNS.plusNanos(1);
    expect(times.getTime()).andReturn(currentTimeNS);
    final Instant lockNS = currentTimeNS;
    StaticBuffer lockCol = codec.toLockCol(lockNS, defaultLockRid, times);
    Entry add = StaticArrayEntry.of(lockCol, defaultLockVal);
    StaticBuffer k = eq(defaultLockKey);
    final List<Entry> adds = eq(Collections.singletonList(add));
    final List<StaticBuffer> deletions;
    if (null != del) {
        deletions = eq(Collections.singletonList(del));
    } else {
        deletions = eq(ImmutableList.of());
    }
    store.mutate(k, adds, deletions, eq(tx));
    expectLastCall().once();
    currentTimeNS = currentTimeNS.plus(duration, tu);
    expect(times.getTime()).andReturn(currentTimeNS);
    ConsistentKeyLockStatus status = new ConsistentKeyLockStatus(lockNS, lockNS.plus(defaultExpireNS));
    return new LockInfo(lockNS, status, lockCol);
}
Also used : Entry(org.janusgraph.diskstorage.Entry) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) Instant(java.time.Instant) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) ConsistentKeyLockStatus(org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus)

Example 60 with Entry

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

the class LockCleanerRunnableTest method testPreservesLocksAtOrAfterCutoff.

/**
 * Locks with timestamps equal to or numerically greater than the cleaner
 * cutoff timestamp must be preserved. Test that the cleaner reads locks by
 * slicing the store and then does <b>not</b> attempt to write.
 */
@Test
public void testPreservesLocksAtOrAfterCutoff() throws BackendException {
    final Instant cutoff = Instant.ofEpochMilli(10L);
    Entry currentLock = StaticArrayEntry.of(codec.toLockCol(cutoff, defaultLockRid, TimestampProviders.MILLI), BufferUtil.getIntBuffer(0));
    Entry futureLock = StaticArrayEntry.of(codec.toLockCol(cutoff.plusMillis(1), defaultLockRid, TimestampProviders.MILLI), BufferUtil.getIntBuffer(0));
    EntryList locks = StaticArrayEntryList.of(currentLock, futureLock);
    // Don't increment cutoff: lockCol is exactly at the cutoff timestamp
    del = new StandardLockCleanerRunnable(store, kc, tx, codec, cutoff, TimestampProviders.MILLI);
    expect(store.getSlice(eq(ksq), eq(tx))).andReturn(locks);
    ctrl.replay();
    del.run();
}
Also used : StandardLockCleanerRunnable(org.janusgraph.diskstorage.locking.consistentkey.StandardLockCleanerRunnable) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) Entry(org.janusgraph.diskstorage.Entry) Instant(java.time.Instant) StaticArrayEntryList(org.janusgraph.diskstorage.util.StaticArrayEntryList) EntryList(org.janusgraph.diskstorage.EntryList) Test(org.junit.jupiter.api.Test)

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