Search in sources :

Example 6 with WriteByteBuffer

use of com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer in project titan by thinkaurelius.

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(com.thinkaurelius.titan.diskstorage.WriteBuffer) WriteByteBuffer(com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer)

Example 7 with WriteByteBuffer

use of com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer in project titan by thinkaurelius.

the class IDHandler method getEdgeType.

public static StaticBuffer getEdgeType(long etid, int dirID) {
    WriteBuffer b = new WriteByteBuffer(edgeTypeLength(etid));
    IDHandler.writeEdgeType(b, etid, dirID);
    return b.getStaticBuffer();
}
Also used : WriteBuffer(com.thinkaurelius.titan.diskstorage.WriteBuffer) WriteByteBuffer(com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer)

Example 8 with WriteByteBuffer

use of com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer in project titan by thinkaurelius.

the class ConsistentKeyLockerSerializer method toLockCol.

public StaticBuffer toLockCol(long ts, StaticBuffer rid) {
    WriteBuffer b = new WriteByteBuffer(rid.length() + 8);
    b.putLong(ts);
    WriteBufferUtil.put(b, rid);
    return b.getStaticBuffer();
}
Also used : WriteBuffer(com.thinkaurelius.titan.diskstorage.WriteBuffer) WriteByteBuffer(com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer)

Example 9 with WriteByteBuffer

use of com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer in project titan by thinkaurelius.

the class IDManagementTest method edgeTypeIDTest.

@Test
public void edgeTypeIDTest() {
    int partitionBits = 21;
    IDManager eid = new IDManager(partitionBits);
    int trails = 1000000;
    assertEquals(eid.getMaxPartitionCount(), (1 << partitionBits) - 1);
    KryoSerializer serializer = new KryoSerializer();
    for (int t = 0; t < trails; t++) {
        long count = RandomGenerator.randomLong(1, eid.getMaxTitanTypeCount());
        long id;
        int dirID;
        RelationType type;
        if (Math.random() < 0.5) {
            id = eid.getEdgeLabelID(count);
            assertTrue(eid.isEdgeLabelID(id));
            type = RelationType.EDGE;
            if (Math.random() < 0.5)
                dirID = IDHandler.EDGE_IN_DIR;
            else
                dirID = IDHandler.EDGE_OUT_DIR;
        } else {
            type = RelationType.PROPERTY;
            id = eid.getPropertyKeyID(count);
            assertTrue(eid.isPropertyKeyID(id));
            dirID = IDHandler.PROPERTY_DIR;
        }
        assertTrue(eid.isTypeID(id));
        StaticBuffer b = IDHandler.getEdgeType(id, dirID);
        // System.out.println(dirID);
        // System.out.println(getBinary(id));
        // System.out.println(getBuffer(b.asReadBuffer()));
        ReadBuffer rb = b.asReadBuffer();
        long[] vals = IDHandler.readEdgeType(rb);
        assertEquals(id, vals[0]);
        assertEquals(dirID, vals[1]);
        assertFalse(rb.hasRemaining());
        // Inline edge type
        WriteBuffer wb = new WriteByteBuffer(9);
        IDHandler.writeInlineEdgeType(wb, id);
        long newId = IDHandler.readInlineEdgeType(wb.getStaticBuffer().asReadBuffer());
        assertEquals(id, newId);
        // Compare to Kryo
        DataOutput out = serializer.getDataOutput(10, true);
        IDHandler.writeEdgeType(out, id, dirID);
        assertEquals(b, out.getStaticBuffer());
        // Make sure the bounds are right
        StaticBuffer[] bounds = IDHandler.getBounds(type);
        assertTrue(bounds[0].compareTo(b) < 0);
        assertTrue(bounds[1].compareTo(b) > 0);
        bounds = IDHandler.getBounds(RelationType.RELATION);
        assertTrue(bounds[0].compareTo(b) < 0);
        assertTrue(bounds[1].compareTo(b) > 0);
    }
}
Also used : ReadBuffer(com.thinkaurelius.titan.diskstorage.ReadBuffer) DataOutput(com.thinkaurelius.titan.graphdb.database.serialize.DataOutput) WriteBuffer(com.thinkaurelius.titan.diskstorage.WriteBuffer) WriteByteBuffer(com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer) RelationType(com.thinkaurelius.titan.graphdb.internal.RelationType) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) KryoSerializer(com.thinkaurelius.titan.graphdb.database.serialize.kryo.KryoSerializer) Test(org.junit.Test)

Example 10 with WriteByteBuffer

use of com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer in project titan by thinkaurelius.

the class VariableLongTest method readWriteTest.

private void readWriteTest(final ReadWriteLong impl, long maxValue, long jump, boolean negative, boolean backward) {
    Preconditions.checkArgument(maxValue % jump == 0);
    long allocate = maxValue / jump * 8 * (negative ? 2 : 1);
    Preconditions.checkArgument(allocate < (1 << 28));
    WriteBuffer wb = new WriteByteBuffer((int) allocate);
    int num = 0;
    StopWatch w = new StopWatch();
    w.start();
    for (long i = (negative ? -maxValue : 0); i <= maxValue; i += jump) {
        impl.write(wb, i);
        num++;
    }
    // for (int i=0;i<b.remaining();i++) System.out.print(b.get(i)+"|");
    w.stop();
    ReadBuffer rb = wb.getStaticBuffer().asReadBuffer();
    log.info("Writing " + num + " longs in " + rb.length() + " bytes. in time: " + w.getTime());
    final ReadVerify read = new ReadVerify() {

        @Override
        public void next(ReadBuffer rb, long expected) {
            int beforePos = rb.getPosition();
            long value = impl.read(rb);
            assertEquals(expected, value);
            int length = Math.abs(rb.getPosition() - beforePos);
            assertEquals("On: " + expected, length, impl.length(expected));
        }
    };
    if (backward) {
        rb.movePosition(rb.length() - 1);
        for (long i = maxValue; i != (negative ? -maxValue : 0); i -= jump) {
            read.next(rb, i);
        }
    } else {
        for (long i = (negative ? -maxValue : 0); i <= maxValue; i += jump) {
            read.next(rb, i);
        }
    }
    // Test boundaries
    wb = new WriteByteBuffer(512);
    impl.write(wb, 0);
    impl.write(wb, Long.MAX_VALUE);
    if (negative)
        impl.write(wb, -Long.MAX_VALUE);
    rb = wb.getStaticBuffer().asReadBuffer();
    if (backward) {
        rb.movePosition(rb.length() - 1);
        if (negative)
            assertEquals(-Long.MAX_VALUE, impl.read(rb));
        assertEquals(Long.MAX_VALUE, impl.read(rb));
        assertEquals(0, impl.read(rb));
    } else {
        assertEquals(0, impl.read(rb));
        assertEquals(Long.MAX_VALUE, impl.read(rb));
        if (negative)
            assertEquals(-Long.MAX_VALUE, impl.read(rb));
    }
}
Also used : ReadBuffer(com.thinkaurelius.titan.diskstorage.ReadBuffer) WriteBuffer(com.thinkaurelius.titan.diskstorage.WriteBuffer) WriteByteBuffer(com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer) StopWatch(org.apache.commons.lang.time.StopWatch)

Aggregations

WriteByteBuffer (com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer)18 WriteBuffer (com.thinkaurelius.titan.diskstorage.WriteBuffer)14 Test (org.junit.Test)7 ReadBuffer (com.thinkaurelius.titan.diskstorage.ReadBuffer)4 StaticArrayEntry (com.thinkaurelius.titan.diskstorage.util.StaticArrayEntry)3 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)2 KeyValueEntry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.keyvalue.KeyValueEntry)2 ReadArrayBuffer (com.thinkaurelius.titan.diskstorage.util.ReadArrayBuffer)1 DataOutput (com.thinkaurelius.titan.graphdb.database.serialize.DataOutput)1 KryoSerializer (com.thinkaurelius.titan.graphdb.database.serialize.kryo.KryoSerializer)1 RelationType (com.thinkaurelius.titan.graphdb.internal.RelationType)1 UUID (java.util.UUID)1 StopWatch (org.apache.commons.lang.time.StopWatch)1