Search in sources :

Example 1 with WriteBuffer

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

the class ConsistentKeyLockerSerializer method toLockKey.

public StaticBuffer toLockKey(StaticBuffer key, StaticBuffer column) {
    WriteBuffer b = new WriteByteBuffer(key.length() + column.length() + 4);
    b.putInt(key.length());
    WriteBufferUtil.put(b, key);
    WriteBufferUtil.put(b, column);
    return b.getStaticBuffer();
}
Also used : WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer)

Example 2 with WriteBuffer

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

the class IDManagementTest method getBufferOf.

private static StaticBuffer getBufferOf(int s, long l) {
    WriteBuffer out = new WriteByteBuffer(4 + 8);
    out.putInt(s);
    out.putLong(l);
    return out.getStaticBuffer();
}
Also used : WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer)

Example 3 with WriteBuffer

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

the class VariableLongTest method byteOrderPreservingPositiveBackward.

@Test
public void byteOrderPreservingPositiveBackward() {
    long[] scalingFactors = { Long.MAX_VALUE, 1000, 1000000000L };
    for (int t = 0; t < 10000000; t++) {
        StaticBuffer[] b = new StaticBuffer[2];
        long[] l = new long[2];
        for (int i = 0; i < 2; i++) {
            l[i] = randomPosLong(scalingFactors[random.nextInt(scalingFactors.length)]);
            WriteBuffer out = new WriteByteBuffer(11);
            VariableLong.writePositiveBackward(out, l[i]);
            b[i] = out.getStaticBuffer();
            ReadBuffer res = b[i].asReadBuffer();
            res.movePositionTo(res.length());
            assertEquals(l[i], VariableLong.readPositiveBackward(res));
        }
        // System.out.println(l[0] + " vs " + l[1]);
        assertEquals(Math.signum(Long.compare(l[0], l[1])), Math.signum(b[0].compareTo(b[1])), 0.01);
    }
}
Also used : ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) Test(org.junit.Test)

Example 4 with WriteBuffer

use of org.janusgraph.diskstorage.WriteBuffer 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 5 with WriteBuffer

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

the class IDManagementTest method writingInlineEdgeTypes.

@Test
public void writingInlineEdgeTypes() {
    int numTries = 100;
    WriteBuffer out = new WriteByteBuffer(8 * numTries);
    for (SystemRelationType t : SYSTEM_TYPES) {
        IDHandler.writeInlineRelationType(out, t.longId());
    }
    for (long i = 1; i <= numTries; i++) {
        IDHandler.writeInlineRelationType(out, IDManager.getSchemaId(IDManager.VertexIDType.UserEdgeLabel, i * 1000));
    }
    ReadBuffer in = out.getStaticBuffer().asReadBuffer();
    for (SystemRelationType t : SYSTEM_TYPES) {
        assertEquals(t, SystemTypeManager.getSystemType(IDHandler.readInlineRelationType(in)));
    }
    for (long i = 1; i <= numTries; i++) {
        assertEquals(i * 1000, IDManager.stripEntireRelationTypePadding(IDHandler.readInlineRelationType(in)));
    }
}
Also used : ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) WriteBuffer(org.janusgraph.diskstorage.WriteBuffer) WriteByteBuffer(org.janusgraph.diskstorage.util.WriteByteBuffer) Test(org.junit.Test)

Aggregations

WriteBuffer (org.janusgraph.diskstorage.WriteBuffer)10 WriteByteBuffer (org.janusgraph.diskstorage.util.WriteByteBuffer)10 ReadBuffer (org.janusgraph.diskstorage.ReadBuffer)4 Test (org.junit.Test)4 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)3 Preconditions (com.google.common.base.Preconditions)1 Random (java.util.Random)1 StopWatch (org.apache.commons.lang.time.StopWatch)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