Search in sources :

Example 6 with WriteByteBuffer

use of org.janusgraph.diskstorage.util.WriteByteBuffer in project janusgraph by JanusGraph.

the class IDHandler method getRelationType.

public static StaticBuffer getRelationType(long relationTypeId, DirectionID dirID, boolean invisible) {
    WriteBuffer b = new WriteByteBuffer(relationTypeLength(relationTypeId));
    IDHandler.writeRelationType(b, relationTypeId, dirID, invisible);
    return b.getStaticBuffer();
}
Also used : WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer)

Example 7 with WriteByteBuffer

use of org.janusgraph.diskstorage.util.WriteByteBuffer in project janusgraph by JanusGraph.

the class ConsistentKeyLockerSerializer method toLockCol.

public StaticBuffer toLockCol(Instant ts, StaticBuffer rid, TimestampProvider provider) {
    WriteBuffer b = new WriteByteBuffer(rid.length() + 8);
    b.putLong(provider.getTime(ts));
    WriteBufferUtil.put(b, rid);
    return b.getStaticBuffer();
}
Also used : WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer)

Example 8 with WriteByteBuffer

use of org.janusgraph.diskstorage.util.WriteByteBuffer in project janusgraph by JanusGraph.

the class VariableLong method positiveBuffer.

public static StaticBuffer positiveBuffer(final long value) {
    WriteBuffer buffer = new WriteByteBuffer(positiveLength(value));
    writePositive(buffer, value);
    return buffer.getStaticBuffer();
}
Also used : WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer)

Example 9 with WriteByteBuffer

use of org.janusgraph.diskstorage.util.WriteByteBuffer in project janusgraph by JanusGraph.

the class VariableLong method positiveBuffer.

public static StaticBuffer positiveBuffer(long[] value) {
    int len = 0;
    for (long aValue : value) len += positiveLength(aValue);
    WriteBuffer buffer = new WriteByteBuffer(len);
    for (long aValue : value) writePositive(buffer, aValue);
    return buffer.getStaticBuffer();
}
Also used : WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer)

Example 10 with WriteByteBuffer

use of org.janusgraph.diskstorage.util.WriteByteBuffer 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)

Aggregations

WriteByteBuffer (org.janusgraph.diskstorage.util.WriteByteBuffer)14 WriteBuffer (org.janusgraph.diskstorage.WriteBuffer)10 Test (org.junit.Test)8 ReadBuffer (org.janusgraph.diskstorage.ReadBuffer)4 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)3 StaticArrayEntry (org.janusgraph.diskstorage.util.StaticArrayEntry)3 Preconditions (com.google.common.base.Preconditions)1 Random (java.util.Random)1 UUID (java.util.UUID)1 StopWatch (org.apache.commons.lang.time.StopWatch)1 ReadArrayBuffer (org.janusgraph.diskstorage.util.ReadArrayBuffer)1 IDHandler (org.janusgraph.graphdb.database.idhandling.IDHandler)1 VariableLong (org.janusgraph.graphdb.database.idhandling.VariableLong)1 DataOutput (org.janusgraph.graphdb.database.serialize.DataOutput)1 Serializer (org.janusgraph.graphdb.database.serialize.Serializer)1 StandardSerializer (org.janusgraph.graphdb.database.serialize.StandardSerializer)1 RelationCategory (org.janusgraph.graphdb.internal.RelationCategory)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1