Search in sources :

Example 36 with StaticBuffer

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

the class ExpirationCacheTest method testGracePeriod.

private void testGracePeriod(Duration graceWait) throws Exception {
    final int minCleanupTriggerCalls = 5;
    final int numKeys = 100, numCols = 10;
    loadStore(numKeys, numCols);
    // Replace cache with proper times
    cache = getCache(store, Duration.ofDays(200), graceWait);
    final StaticBuffer key = BufferUtil.getIntBuffer(81);
    final List<StaticBuffer> keys = new ArrayList<>();
    keys.add(key);
    keys.add(BufferUtil.getIntBuffer(37));
    keys.add(BufferUtil.getIntBuffer(2));
    SliceQuery query = getQuery(2, 8);
    verifyResults(key, keys, query, 6);
    // If we modify through cache store...
    CacheTransaction tx = getCacheTx();
    cache.mutateEntries(key, KeyColumnValueStore.NO_ADDITIONS, Lists.newArrayList(getEntry(4, 4)), tx);
    tx.commit();
    Instant utime = times.getTime();
    store.resetCounter();
    // ...invalidation should happen and the result set is updated immediately
    verifyResults(key, keys, query, 5);
    assertEquals(2, store.getSliceCalls());
    // however, the key is expired and hence repeated calls need to go through to the store
    verifyResults(key, keys, query, 5);
    assertEquals(4, store.getSliceCalls());
    // however, when we sleep past the grace wait time and trigger a cleanup...
    times.sleepPast(utime.plus(graceWait));
    for (int t = 0; t < minCleanupTriggerCalls; t++) {
        assertEquals(5, cache.getSlice(new KeySliceQuery(key, query), tx).size());
        times.sleepFor(Duration.ofMillis(5));
    }
    // ...the cache should cache results again
    store.resetCounter();
    verifyResults(key, keys, query, 5);
    assertEquals(0, store.getSliceCalls());
    verifyResults(key, keys, query, 5);
    assertEquals(0, store.getSliceCalls());
}
Also used : Instant(java.time.Instant) ArrayList(java.util.ArrayList) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) CacheTransaction(org.janusgraph.diskstorage.keycolumnvalue.cache.CacheTransaction) SliceQuery(org.janusgraph.diskstorage.keycolumnvalue.SliceQuery) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)

Example 37 with StaticBuffer

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

the class ExpirationCacheTest method verifyResults.

private void verifyResults(StaticBuffer key, List<StaticBuffer> keys, SliceQuery query, int expectedResults) throws Exception {
    CacheTransaction tx = getCacheTx();
    assertEquals(expectedResults, cache.getSlice(new KeySliceQuery(key, query), tx).size());
    Map<StaticBuffer, EntryList> results = cache.getSlice(keys, query, tx);
    assertEquals(keys.size(), results.size());
    assertEquals(expectedResults, results.get(key).size());
    tx.commit();
}
Also used : StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) EntryList(org.janusgraph.diskstorage.EntryList) CacheTransaction(org.janusgraph.diskstorage.keycolumnvalue.cache.CacheTransaction) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)

Example 38 with StaticBuffer

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

the class BufferUtilTest method testNextBigger.

@Test
public void testNextBigger() {
    int trials = 100000;
    for (int t = 0; t < trials; t++) {
        long val = random.nextLong() >>> 1;
        assert val >= 0;
        StaticBuffer b = BufferUtil.getLongBuffer(val);
        assertEquals(val, b.getLong(0));
        StaticBuffer bn = BufferUtil.nextBiggerBuffer(b);
        assertEquals(8, bn.length());
        assertEquals(val + 1, bn.getLong(0));
    }
    try {
        StaticBuffer b = BufferUtil.getLongBuffer(-1);
        BufferUtil.nextBiggerBuffer(b);
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    StaticBuffer b = BufferUtil.getLongBuffer(-1);
    StaticBuffer bn = BufferUtil.nextBiggerBufferAllowOverflow(b);
    Assert.assertEquals(8, bn.length());
    Assert.assertTrue(BufferUtil.zeroBuffer(8).equals(bn));
}
Also used : StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) Test(org.junit.Test)

Example 39 with StaticBuffer

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

the class IDManagementTest method edgeTypeIDTest.

@Test
public void edgeTypeIDTest() {
    int partitionBits = 16;
    IDManager eid = new IDManager(partitionBits);
    int trails = 1000000;
    assertEquals(eid.getPartitionBound(), (1L << partitionBits));
    Serializer serializer = new StandardSerializer();
    for (int t = 0; t < trails; t++) {
        long count = RandomGenerator.randomLong(1, IDManager.getSchemaCountBound());
        long id;
        IDHandler.DirectionID dirID;
        RelationCategory type;
        if (Math.random() < 0.5) {
            id = IDManager.getSchemaId(IDManager.VertexIDType.UserEdgeLabel, count);
            assertTrue(eid.isEdgeLabelId(id));
            assertFalse(IDManager.isSystemRelationTypeId(id));
            type = RelationCategory.EDGE;
            if (Math.random() < 0.5)
                dirID = IDHandler.DirectionID.EDGE_IN_DIR;
            else
                dirID = IDHandler.DirectionID.EDGE_OUT_DIR;
        } else {
            type = RelationCategory.PROPERTY;
            id = IDManager.getSchemaId(IDManager.VertexIDType.UserPropertyKey, count);
            assertTrue(eid.isPropertyKeyId(id));
            assertFalse(IDManager.isSystemRelationTypeId(id));
            dirID = IDHandler.DirectionID.PROPERTY_DIR;
        }
        assertTrue(eid.isRelationTypeId(id));
        StaticBuffer b = IDHandler.getRelationType(id, dirID, false);
        // System.out.println(dirID);
        // System.out.println(getBinary(id));
        // System.out.println(getBuffer(b.asReadBuffer()));
        ReadBuffer rb = b.asReadBuffer();
        IDHandler.RelationTypeParse parse = IDHandler.readRelationType(rb);
        assertEquals(id, parse.typeId);
        assertEquals(dirID, parse.dirID);
        assertFalse(rb.hasRemaining());
        // Inline edge type
        WriteBuffer wb = new WriteByteBuffer(9);
        IDHandler.writeInlineRelationType(wb, id);
        long newId = IDHandler.readInlineRelationType(wb.getStaticBuffer().asReadBuffer());
        assertEquals(id, newId);
        // Compare to Kryo
        DataOutput out = serializer.getDataOutput(10);
        IDHandler.writeRelationType(out, id, dirID, false);
        assertEquals(b, out.getStaticBuffer());
        // Make sure the bounds are right
        StaticBuffer[] bounds = IDHandler.getBounds(type, false);
        assertTrue(bounds[0].compareTo(b) < 0);
        assertTrue(bounds[1].compareTo(b) > 0);
        bounds = IDHandler.getBounds(RelationCategory.RELATION, false);
        assertTrue(bounds[0].compareTo(b) < 0);
        assertTrue(bounds[1].compareTo(b) > 0);
    }
}
Also used : DataOutput(org.janusgraph.graphdb.database.serialize.DataOutput) WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) RelationCategory(org.janusgraph.graphdb.internal.RelationCategory) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer) StandardSerializer(org.janusgraph.graphdb.database.serialize.StandardSerializer) IDHandler(org.janusgraph.graphdb.database.idhandling.IDHandler) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) StandardSerializer(org.janusgraph.graphdb.database.serialize.StandardSerializer) Serializer(org.janusgraph.graphdb.database.serialize.Serializer) Test(org.junit.Test)

Example 40 with StaticBuffer

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

the class IDManagementTest method testEdgeTypeWriting.

public void testEdgeTypeWriting(long edgeTypeId) {
    IDHandler.DirectionID[] dir = IDManager.VertexIDType.EdgeLabel.is(edgeTypeId) ? new IDHandler.DirectionID[] { IDHandler.DirectionID.EDGE_IN_DIR, IDHandler.DirectionID.EDGE_OUT_DIR } : new IDHandler.DirectionID[] { IDHandler.DirectionID.PROPERTY_DIR };
    boolean invisible = IDManager.isSystemRelationTypeId(edgeTypeId);
    for (IDHandler.DirectionID d : dir) {
        StaticBuffer b = IDHandler.getRelationType(edgeTypeId, d, invisible);
        IDHandler.RelationTypeParse parse = IDHandler.readRelationType(b.asReadBuffer());
        assertEquals(d, parse.dirID);
        assertEquals(edgeTypeId, parse.typeId);
    }
}
Also used : IDHandler(org.janusgraph.graphdb.database.idhandling.IDHandler) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer)

Aggregations

StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)45 Test (org.junit.Test)17 Entry (org.janusgraph.diskstorage.Entry)14 ArrayList (java.util.ArrayList)10 ReadBuffer (org.janusgraph.diskstorage.ReadBuffer)8 DataOutput (org.janusgraph.graphdb.database.serialize.DataOutput)8 SliceQuery (org.janusgraph.diskstorage.keycolumnvalue.SliceQuery)7 ByteBuffer (java.nio.ByteBuffer)6 List (java.util.List)6 Map (java.util.Map)6 ResultSet (com.datastax.driver.core.ResultSet)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 BackendException (org.janusgraph.diskstorage.BackendException)5 Row (com.datastax.driver.core.Row)4 Tuple (io.vavr.Tuple)4 Array (io.vavr.collection.Array)4 IOException (java.io.IOException)4 Instant (java.time.Instant)4 HashMap (java.util.HashMap)4 Random (java.util.Random)4