Search in sources :

Example 1 with DataOutput

use of org.janusgraph.graphdb.database.serialize.DataOutput in project janusgraph by JanusGraph.

the class IndexSerializer method getIndexEntry.

private Entry getIndexEntry(CompositeIndexType index, RecordEntry[] record, JanusGraphElement element) {
    final DataOutput out = serializer.getDataOutput(1 + 8 + 8 * record.length + 4 * 8);
    out.putByte(FIRST_INDEX_COLUMN_BYTE);
    if (index.getCardinality() != Cardinality.SINGLE) {
        VariableLong.writePositive(out, element.longId());
        if (index.getCardinality() != Cardinality.SET) {
            for (final RecordEntry re : record) {
                VariableLong.writePositive(out, re.relationId);
            }
        }
    }
    final int valuePosition = out.getPosition();
    if (element instanceof JanusGraphVertex) {
        VariableLong.writePositive(out, element.longId());
    } else {
        assert element instanceof JanusGraphRelation;
        final RelationIdentifier rid = (RelationIdentifier) element.id();
        final long[] longs = rid.getLongRepresentation();
        Preconditions.checkArgument(longs.length == 3 || longs.length == 4);
        for (final long aLong : longs) VariableLong.writePositive(out, aLong);
    }
    return new StaticArrayEntry(out.getStaticBuffer(), valuePosition);
}
Also used : DataOutput(org.janusgraph.graphdb.database.serialize.DataOutput) JanusGraphRelation(org.janusgraph.core.JanusGraphRelation) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) RelationIdentifier(org.janusgraph.graphdb.relations.RelationIdentifier) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry)

Example 2 with DataOutput

use of org.janusgraph.graphdb.database.serialize.DataOutput in project janusgraph by JanusGraph.

the class TransactionLogHeader method serializePrimary.

public StaticBuffer serializePrimary(Serializer serializer, LogTxStatus status) {
    Preconditions.checkArgument(status == LogTxStatus.PRIMARY_SUCCESS || status == LogTxStatus.COMPLETE_SUCCESS);
    final DataOutput out = serializeHeader(serializer, status);
    return out.getStaticBuffer();
}
Also used : DataOutput(org.janusgraph.graphdb.database.serialize.DataOutput)

Example 3 with DataOutput

use of org.janusgraph.graphdb.database.serialize.DataOutput in project janusgraph by JanusGraph.

the class TransactionLogHeader method serializeModifications.

public StaticBuffer serializeModifications(Serializer serializer, LogTxStatus status, StandardJanusGraphTx tx, final Collection<InternalRelation> addedRelations, final Collection<InternalRelation> deletedRelations) {
    Preconditions.checkArgument(status == LogTxStatus.PRECOMMIT || status == LogTxStatus.USER_LOG);
    DataOutput out = serializeHeader(serializer, 256 + (addedRelations.size() + deletedRelations.size()) * 40, status, status == LogTxStatus.PRECOMMIT ? tx.getConfiguration() : null);
    logRelations(out, addedRelations, tx);
    logRelations(out, deletedRelations, tx);
    return out.getStaticBuffer();
}
Also used : DataOutput(org.janusgraph.graphdb.database.serialize.DataOutput)

Example 4 with DataOutput

use of org.janusgraph.graphdb.database.serialize.DataOutput in project janusgraph by JanusGraph.

the class TransactionLogHeader method serializeSecondary.

public StaticBuffer serializeSecondary(Serializer serializer, LogTxStatus status, Map<String, Throwable> indexFailures, boolean userLogSuccess) {
    Preconditions.checkArgument(status == LogTxStatus.SECONDARY_SUCCESS || status == LogTxStatus.SECONDARY_FAILURE);
    final DataOutput out = serializeHeader(serializer, status);
    if (status == LogTxStatus.SECONDARY_FAILURE) {
        out.putBoolean(userLogSuccess);
        out.putInt(indexFailures.size());
        for (String index : indexFailures.keySet()) {
            assert StringUtils.isNotBlank(index);
            out.writeObjectNotNull(index);
        }
    } else
        assert userLogSuccess && indexFailures.isEmpty();
    return out.getStaticBuffer();
}
Also used : DataOutput(org.janusgraph.graphdb.database.serialize.DataOutput)

Example 5 with DataOutput

use of org.janusgraph.graphdb.database.serialize.DataOutput in project janusgraph by JanusGraph.

the class TransactionLogHeader method serializeUserLog.

public StaticBuffer serializeUserLog(Serializer serializer, Entry sourceTxEntry, StandardTransactionId sourceTxId) {
    Preconditions.checkArgument(sourceTxEntry != null && sourceTxEntry.status == LogTxStatus.PRECOMMIT && sourceTxEntry.header.transactionId == sourceTxId.getTransactionId());
    StaticBuffer sourceContent = sourceTxEntry.content;
    Preconditions.checkArgument(sourceContent != null && sourceContent.length() > 0);
    final EnumMap<LogTxMeta, Object> meta = new EnumMap<>(LogTxMeta.class);
    meta.put(LogTxMeta.SOURCE_TRANSACTION, sourceTxId);
    DataOutput out = serializeHeader(serializer, 50 + sourceContent.length(), LogTxStatus.USER_LOG, meta);
    out.putBytes(sourceContent);
    return out.getStaticBuffer();
}
Also used : DataOutput(org.janusgraph.graphdb.database.serialize.DataOutput) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) EnumMap(java.util.EnumMap)

Aggregations

DataOutput (org.janusgraph.graphdb.database.serialize.DataOutput)39 ReadBuffer (org.janusgraph.diskstorage.ReadBuffer)16 Test (org.junit.jupiter.api.Test)14 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)10 HashMap (java.util.HashMap)3 Map (java.util.Map)3 StaticArrayEntry (org.janusgraph.diskstorage.util.StaticArrayEntry)3 TClass1Serializer (org.janusgraph.graphdb.serializer.attributes.TClass1Serializer)3 TClass2 (org.janusgraph.graphdb.serializer.attributes.TClass2)3 SpatialContextFactory (org.locationtech.spatial4j.context.SpatialContextFactory)3 EnumMap (java.util.EnumMap)2 PropertyKey (org.janusgraph.core.PropertyKey)2 Geoshape (org.janusgraph.core.attribute.Geoshape)2 DirectionID (org.janusgraph.graphdb.database.idhandling.IDHandler.DirectionID)2 RelationCategory (org.janusgraph.graphdb.internal.RelationCategory)2 TClass1 (org.janusgraph.graphdb.serializer.attributes.TClass1)2 TEnum (org.janusgraph.graphdb.serializer.attributes.TEnum)2 JanusGraphSchemaVertex (org.janusgraph.graphdb.types.vertices.JanusGraphSchemaVertex)2 LoggerFactory (org.slf4j.LoggerFactory)2 LongArrayList (com.carrotsearch.hppc.LongArrayList)1