Search in sources :

Example 6 with ReadBuffer

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

the class SerializerTest method largeWriteTest.

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

Example 7 with ReadBuffer

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

the class SerializerTestCommon method multipleStringWrite.

protected void multipleStringWrite() {
    // 26 chars
    String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int no = 100;
    DataOutput out = serialize.getDataOutput(128);
    for (int i = 0; i < no; i++) {
        String str = base + (i + 1);
        out.writeObjectNotNull(str);
    }
    ReadBuffer b = out.getStaticBuffer().asReadBuffer();
    if (printStats)
        log.debug(bufferStats(b));
    for (int i = 0; i < no; i++) {
        String str = base + (i + 1);
        String read = serialize.readObjectNotNull(b, String.class);
        assertEquals(str, read);
    }
    assertFalse(b.hasRemaining());
}
Also used : DataOutput(org.janusgraph.graphdb.database.serialize.DataOutput) ReadBuffer(org.janusgraph.diskstorage.ReadBuffer)

Example 8 with ReadBuffer

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

the class ManagementLogger method read.

@Override
public void read(Message message) {
    ReadBuffer in = message.getContent().asReadBuffer();
    String senderId = message.getSenderId();
    Serializer serializer = graph.getDataSerializer();
    MgmtLogType logType = serializer.readObjectNotNull(in, MgmtLogType.class);
    Preconditions.checkNotNull(logType);
    switch(logType) {
        case CACHED_TYPE_EVICTION:
            {
                long evictionId = VariableLong.readPositive(in);
                long numEvictions = VariableLong.readPositive(in);
                for (int i = 0; i < numEvictions; i++) {
                    long typeId = VariableLong.readPositive(in);
                    schemaCache.expireSchemaElement(typeId);
                }
                final GraphCacheEvictionAction action = serializer.readObjectNotNull(in, GraphCacheEvictionAction.class);
                Preconditions.checkNotNull(action);
                final Thread ack = new Thread(new SendAckOnTxClose(evictionId, senderId, graph.getOpenTransactions(), action, graph.getGraphName()));
                ack.setDaemon(true);
                ack.start();
                break;
            }
        case CACHED_TYPE_EVICTION_ACK:
            {
                String receiverId = serializer.readObjectNotNull(in, String.class);
                long evictionId = VariableLong.readPositive(in);
                if (receiverId.equals(graph.getConfiguration().getUniqueGraphId())) {
                    // Acknowledgements targeted at this instance
                    EvictionTrigger evictTrigger = evictionTriggerMap.get(evictionId);
                    if (evictTrigger != null) {
                        evictTrigger.receivedAcknowledgement(senderId);
                    } else
                        log.error("Could not find eviction trigger for {} from {}", evictionId, senderId);
                }
                break;
            }
        default:
            assert logType == MgmtLogType.CONFIG_MUTATION;
            break;
    }
}
Also used : ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) Serializer(org.janusgraph.graphdb.database.serialize.Serializer)

Example 9 with ReadBuffer

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

the class ConsistentKeyLockerSerializer method fromLockColumn.

public TimestampRid fromLockColumn(StaticBuffer lockKey, TimestampProvider provider) {
    ReadBuffer r = lockKey.asReadBuffer();
    int len = r.length();
    long tsNS = r.getLong();
    len -= 8;
    byte[] curRid = new byte[len];
    for (int i = 0; r.hasRemaining(); i++) {
        curRid[i] = r.getByte();
    }
    StaticBuffer rid = new StaticArrayBuffer(curRid);
    Instant time = provider.getTime(tsNS);
    return new TimestampRid(time, rid);
}
Also used : ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) Instant(java.time.Instant) StaticArrayBuffer(org.janusgraph.diskstorage.util.StaticArrayBuffer) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer)

Example 10 with ReadBuffer

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

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();
    RelationType relationType = tx.getExistingRelationType(typeId);
    InternalRelationType def = (InternalRelationType) relationType;
    Multiplicity multiplicity = def.multiplicity();
    long[] keySignature = 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() && keySignature.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(keySignature, 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 propertyValue = readInline(in, type, InlineType.NORMAL);
            assert propertyValue != null;
            properties.put(type.longId(), propertyValue);
        }
        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(org.janusgraph.graphdb.relations.RelationCache) EdgeDirection(org.janusgraph.graphdb.relations.EdgeDirection) Direction(org.apache.tinkerpop.gremlin.structure.Direction) EntryMetaData(org.janusgraph.diskstorage.EntryMetaData) ReadBuffer(org.janusgraph.diskstorage.ReadBuffer) RelationTypeParse(org.janusgraph.graphdb.database.idhandling.IDHandler.RelationTypeParse) Map(java.util.Map) LongObjectHashMap(com.carrotsearch.hppc.LongObjectHashMap) ImplicitKey(org.janusgraph.graphdb.types.system.ImplicitKey)

Aggregations

ReadBuffer (org.janusgraph.diskstorage.ReadBuffer)21 Test (org.junit.Test)15 DataOutput (org.janusgraph.graphdb.database.serialize.DataOutput)14 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)9 WriteBuffer (org.janusgraph.diskstorage.WriteBuffer)4 WriteByteBuffer (org.janusgraph.diskstorage.util.WriteByteBuffer)4 Instant (java.time.Instant)2 Serializer (org.janusgraph.graphdb.database.serialize.Serializer)2 LoggerFactory (org.slf4j.LoggerFactory)2 LongObjectHashMap (com.carrotsearch.hppc.LongObjectHashMap)1 Preconditions (com.google.common.base.Preconditions)1 Map (java.util.Map)1 Random (java.util.Random)1 StopWatch (org.apache.commons.lang.time.StopWatch)1 Direction (org.apache.tinkerpop.gremlin.structure.Direction)1 EntryMetaData (org.janusgraph.diskstorage.EntryMetaData)1 StaticArrayBuffer (org.janusgraph.diskstorage.util.StaticArrayBuffer)1 IDHandler (org.janusgraph.graphdb.database.idhandling.IDHandler)1 RelationTypeParse (org.janusgraph.graphdb.database.idhandling.IDHandler.RelationTypeParse)1 VariableLong (org.janusgraph.graphdb.database.idhandling.VariableLong)1