Search in sources :

Example 16 with ReadBuffer

use of com.thinkaurelius.titan.diskstorage.ReadBuffer in project titan by thinkaurelius.

the class SerializerTest method largeWriteTest.

@Test
public void largeWriteTest() {
    //26 chars
    String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    String str = "";
    for (int i = 0; i < 100; i++) str += base;
    DataOutput out = serialize.getDataOutput(128);
    out.writeObjectNotNull(str);
    ReadBuffer b = out.getStaticBuffer().asReadBuffer();
    if (printStats)
        log.debug(bufferStats(b));
    assertEquals(str, serialize.readObjectNotNull(b, String.class));
    assertFalse(b.hasRemaining());
}
Also used : DataOutput(com.thinkaurelius.titan.graphdb.database.serialize.DataOutput) ReadBuffer(com.thinkaurelius.titan.diskstorage.ReadBuffer) Test(org.junit.Test)

Example 17 with ReadBuffer

use of com.thinkaurelius.titan.diskstorage.ReadBuffer in project titan by thinkaurelius.

the class SerializerTestCommon method objectWriteRead.

protected void objectWriteRead() {
    TClass1 t1 = new TClass1(3245234223423433123l, 0.333f);
    TClass2 t2 = new TClass2("This is a test", 4234234);
    TEnum t3 = TEnum.THREE;
    TEnum t4 = TEnum.TWO;
    DataOutput out = serialize.getDataOutput(128);
    out.writeObjectNotNull(t1);
    out.writeClassAndObject(t2);
    out.writeObject(t3, TEnum.class);
    out.writeClassAndObject(t4);
    ReadBuffer b = out.getStaticBuffer().asReadBuffer();
    assertEquals(t1, serialize.readObjectNotNull(b, TClass1.class));
    assertEquals(t2, (TClass2) serialize.readClassAndObject(b));
    assertEquals(t3, serialize.readObject(b, TEnum.class));
    assertEquals(t4, serialize.readClassAndObject(b));
    assertFalse(b.hasRemaining());
}
Also used : DataOutput(com.thinkaurelius.titan.graphdb.database.serialize.DataOutput) ReadBuffer(com.thinkaurelius.titan.diskstorage.ReadBuffer)

Example 18 with ReadBuffer

use of com.thinkaurelius.titan.diskstorage.ReadBuffer in project titan by thinkaurelius.

the class EdgeSerializer method parseRelation.

@Override
public RelationCache parseRelation(Entry data, boolean excludeProperties, TypeInspector tx) {
    ReadBuffer in = data.asReadBuffer();
    LongObjectHashMap properties = excludeProperties ? null : new LongObjectHashMap(4);
    RelationTypeParse typeAndDir = IDHandler.readRelationType(in);
    long typeId = typeAndDir.typeId;
    Direction dir = typeAndDir.dirID.getDirection();
    RelationCategory rtype = typeAndDir.dirID.getRelationCategory();
    RelationType relationType = tx.getExistingRelationType(typeId);
    InternalRelationType def = (InternalRelationType) relationType;
    Multiplicity multiplicity = def.multiplicity();
    long[] keysig = def.getSortKey();
    long relationId;
    Object other;
    int startKeyPos = in.getPosition();
    int endKeyPos = 0;
    if (relationType.isEdgeLabel()) {
        long otherVertexId;
        if (multiplicity.isConstrained()) {
            if (multiplicity.isUnique(dir)) {
                otherVertexId = VariableLong.readPositive(in);
            } else {
                in.movePositionTo(data.getValuePosition());
                otherVertexId = VariableLong.readPositiveBackward(in);
                in.movePositionTo(data.getValuePosition());
            }
            relationId = VariableLong.readPositive(in);
        } else {
            in.movePositionTo(data.getValuePosition());
            relationId = VariableLong.readPositiveBackward(in);
            otherVertexId = VariableLong.readPositiveBackward(in);
            endKeyPos = in.getPosition();
            in.movePositionTo(data.getValuePosition());
        }
        other = otherVertexId;
    } else {
        assert relationType.isPropertyKey();
        PropertyKey key = (PropertyKey) relationType;
        if (multiplicity.isConstrained()) {
            other = readPropertyValue(in, key);
            relationId = VariableLong.readPositive(in);
        } else {
            in.movePositionTo(data.getValuePosition());
            relationId = VariableLong.readPositiveBackward(in);
            endKeyPos = in.getPosition();
            in.movePositionTo(data.getValuePosition());
            other = readPropertyValue(in, key);
        }
        Preconditions.checkState(other != null, "Encountered error in deserializer [null value returned]. Check serializer compatibility.");
    }
    assert other != null;
    if (!excludeProperties && !multiplicity.isConstrained() && keysig.length > 0) {
        int currentPos = in.getPosition();
        //Read sort key which only exists if type is not unique in this direction
        assert endKeyPos > startKeyPos;
        //after reading the ids, we are on the last byte of the key
        int keyLength = endKeyPos - startKeyPos;
        in.movePositionTo(startKeyPos);
        ReadBuffer inkey = in;
        if (def.getSortOrder() == Order.DESC)
            inkey = in.subrange(keyLength, true);
        readInlineTypes(keysig, properties, inkey, tx, InlineType.KEY);
        in.movePositionTo(currentPos);
    }
    if (!excludeProperties) {
        //read value signature
        readInlineTypes(def.getSignature(), properties, in, tx, InlineType.SIGNATURE);
        //Third: read rest
        while (in.hasRemaining()) {
            PropertyKey type = tx.getExistingPropertyKey(IDHandler.readInlineRelationType(in));
            Object pvalue = readInline(in, type, InlineType.NORMAL);
            assert pvalue != null;
            properties.put(type.longId(), pvalue);
        }
        if (data.hasMetaData()) {
            for (Map.Entry<EntryMetaData, Object> metas : data.getMetaData().entrySet()) {
                ImplicitKey key = ImplicitKey.MetaData2ImplicitKey.get(metas.getKey());
                if (key != null) {
                    assert metas.getValue() != null;
                    properties.put(key.longId(), metas.getValue());
                }
            }
        }
    }
    return new RelationCache(dir, typeId, relationId, other, properties);
}
Also used : LongObjectHashMap(com.carrotsearch.hppc.LongObjectHashMap) RelationCache(com.thinkaurelius.titan.graphdb.relations.RelationCache) EdgeDirection(com.thinkaurelius.titan.graphdb.relations.EdgeDirection) Direction(org.apache.tinkerpop.gremlin.structure.Direction) EntryMetaData(com.thinkaurelius.titan.diskstorage.EntryMetaData) ReadBuffer(com.thinkaurelius.titan.diskstorage.ReadBuffer) RelationTypeParse(com.thinkaurelius.titan.graphdb.database.idhandling.IDHandler.RelationTypeParse) Map(java.util.Map) LongObjectHashMap(com.carrotsearch.hppc.LongObjectHashMap) ImplicitKey(com.thinkaurelius.titan.graphdb.types.system.ImplicitKey)

Example 19 with ReadBuffer

use of com.thinkaurelius.titan.diskstorage.ReadBuffer in project titan by thinkaurelius.

the class TransactionLogHeader method parse.

public static Entry parse(StaticBuffer buffer, Serializer serializer, TimestampProvider times) {
    ReadBuffer read = buffer.asReadBuffer();
    Instant txTimestamp = times.getTime(read.getLong());
    TransactionLogHeader header = new TransactionLogHeader(VariableLong.readPositive(read), txTimestamp, times);
    LogTxStatus status = serializer.readObjectNotNull(read, LogTxStatus.class);
    EnumMap<LogTxMeta, Object> metadata = new EnumMap<LogTxMeta, Object>(LogTxMeta.class);
    int metaSize = VariableLong.unsignedByte(read.getByte());
    for (int i = 0; i < metaSize; i++) {
        LogTxMeta meta = LogTxMeta.values()[VariableLong.unsignedByte(read.getByte())];
        metadata.put(meta, serializer.readObjectNotNull(read, meta.dataType()));
    }
    if (read.hasRemaining()) {
        StaticBuffer content = read.subrange(read.getPosition(), read.length() - read.getPosition());
        return new Entry(header, content, status, metadata);
    } else {
        return new Entry(header, null, status, metadata);
    }
}
Also used : ReadBuffer(com.thinkaurelius.titan.diskstorage.ReadBuffer) Instant(java.time.Instant) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer)

Aggregations

ReadBuffer (com.thinkaurelius.titan.diskstorage.ReadBuffer)19 DataOutput (com.thinkaurelius.titan.graphdb.database.serialize.DataOutput)12 Test (org.junit.Test)12 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)8 WriteBuffer (com.thinkaurelius.titan.diskstorage.WriteBuffer)4 WriteByteBuffer (com.thinkaurelius.titan.diskstorage.util.WriteByteBuffer)4 Serializer (com.thinkaurelius.titan.graphdb.database.serialize.Serializer)2 Instant (java.time.Instant)2 LongObjectHashMap (com.carrotsearch.hppc.LongObjectHashMap)1 EntryMetaData (com.thinkaurelius.titan.diskstorage.EntryMetaData)1 StaticArrayBuffer (com.thinkaurelius.titan.diskstorage.util.StaticArrayBuffer)1 IDHandler (com.thinkaurelius.titan.graphdb.database.idhandling.IDHandler)1 RelationTypeParse (com.thinkaurelius.titan.graphdb.database.idhandling.IDHandler.RelationTypeParse)1 StandardSerializer (com.thinkaurelius.titan.graphdb.database.serialize.StandardSerializer)1 RelationCategory (com.thinkaurelius.titan.graphdb.internal.RelationCategory)1 EdgeDirection (com.thinkaurelius.titan.graphdb.relations.EdgeDirection)1 RelationCache (com.thinkaurelius.titan.graphdb.relations.RelationCache)1 ImplicitKey (com.thinkaurelius.titan.graphdb.types.system.ImplicitKey)1 Map (java.util.Map)1 StopWatch (org.apache.commons.lang.time.StopWatch)1