Search in sources :

Example 61 with StaticBuffer

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

the class IDManagementTest method testEdgeTypeWriting.

public void testEdgeTypeWriting(long etid) {
    IDHandler.DirectionID[] dir = IDManager.VertexIDType.EdgeLabel.is(etid) ? new IDHandler.DirectionID[] { IDHandler.DirectionID.EDGE_IN_DIR, IDHandler.DirectionID.EDGE_OUT_DIR } : new IDHandler.DirectionID[] { IDHandler.DirectionID.PROPERTY_DIR };
    RelationCategory relCat = IDManager.VertexIDType.EdgeLabel.is(etid) ? RelationCategory.EDGE : RelationCategory.PROPERTY;
    boolean invisible = IDManager.isSystemRelationTypeId(etid);
    for (IDHandler.DirectionID d : dir) {
        StaticBuffer b = IDHandler.getRelationType(etid, d, invisible);
        IDHandler.RelationTypeParse parse = IDHandler.readRelationType(b.asReadBuffer());
        assertEquals(d, parse.dirID);
        assertEquals(etid, parse.typeId);
    }
}
Also used : RelationCategory(com.thinkaurelius.titan.graphdb.internal.RelationCategory) IDHandler(com.thinkaurelius.titan.graphdb.database.idhandling.IDHandler) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer)

Example 62 with StaticBuffer

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

the class PartitionIDRangeTest method convert.

public static List<KeyRange> convert(long lower, long upper, int bitwidth) {
    StaticBuffer lowerBuffer = BufferUtil.getLongBuffer(convert(lower, bitwidth));
    StaticBuffer upperBuffer = BufferUtil.getLongBuffer(convert(upper, bitwidth));
    //        Preconditions.checkArgument(lowerBuffer.compareTo(upperBuffer) < 0, "%s vs %s",lowerBuffer,upperBuffer);
    return Lists.newArrayList(new KeyRange(lowerBuffer, upperBuffer));
}
Also used : KeyRange(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyRange) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer)

Example 63 with StaticBuffer

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

the class IndexRepairJob method process.

@Override
public void process(TitanVertex vertex, ScanMetrics metrics) {
    try {
        BackendTransaction mutator = writeTx.getTxHandle();
        if (index instanceof RelationTypeIndex) {
            RelationTypeIndexWrapper wrapper = (RelationTypeIndexWrapper) index;
            InternalRelationType wrappedType = wrapper.getWrappedType();
            EdgeSerializer edgeSerializer = writeTx.getEdgeSerializer();
            List<Entry> additions = new ArrayList<>();
            for (TitanRelation relation : vertex.query().types(indexRelationTypeName).direction(Direction.OUT).relations()) {
                InternalRelation titanRelation = (InternalRelation) relation;
                for (int pos = 0; pos < titanRelation.getArity(); pos++) {
                    if (!wrappedType.isUnidirected(Direction.BOTH) && !wrappedType.isUnidirected(EdgeDirection.fromPosition(pos)))
                        //Directionality is not covered
                        continue;
                    Entry entry = edgeSerializer.writeRelation(titanRelation, wrappedType, pos, writeTx);
                    additions.add(entry);
                }
            }
            StaticBuffer vertexKey = writeTx.getIdInspector().getKey(vertex.longId());
            mutator.mutateEdges(vertexKey, additions, KCVSCache.NO_DELETIONS);
            metrics.incrementCustom(ADDED_RECORDS_COUNT, additions.size());
        } else if (index instanceof TitanGraphIndex) {
            IndexType indexType = mgmt.getSchemaVertex(index).asIndexType();
            assert indexType != null;
            IndexSerializer indexSerializer = graph.getIndexSerializer();
            //Gather elements to index
            List<TitanElement> elements;
            switch(indexType.getElement()) {
                case VERTEX:
                    elements = ImmutableList.of(vertex);
                    break;
                case PROPERTY:
                    elements = Lists.newArrayList();
                    for (TitanVertexProperty p : addIndexSchemaConstraint(vertex.query(), indexType).properties()) {
                        elements.add(p);
                    }
                    break;
                case EDGE:
                    elements = Lists.newArrayList();
                    for (TitanEdge e : addIndexSchemaConstraint(vertex.query().direction(Direction.OUT), indexType).edges()) {
                        elements.add(e);
                    }
                    break;
                default:
                    throw new AssertionError("Unexpected category: " + indexType.getElement());
            }
            if (indexType.isCompositeIndex()) {
                for (TitanElement element : elements) {
                    Set<IndexSerializer.IndexUpdate<StaticBuffer, Entry>> updates = indexSerializer.reindexElement(element, (CompositeIndexType) indexType);
                    for (IndexSerializer.IndexUpdate<StaticBuffer, Entry> update : updates) {
                        log.debug("Mutating index {}: {}", indexType, update.getEntry());
                        mutator.mutateIndex(update.getKey(), Lists.newArrayList(update.getEntry()), KCVSCache.NO_DELETIONS);
                        metrics.incrementCustom(ADDED_RECORDS_COUNT);
                    }
                }
            } else {
                assert indexType.isMixedIndex();
                Map<String, Map<String, List<IndexEntry>>> documentsPerStore = new HashMap<>();
                for (TitanElement element : elements) {
                    indexSerializer.reindexElement(element, (MixedIndexType) indexType, documentsPerStore);
                    metrics.incrementCustom(DOCUMENT_UPDATES_COUNT);
                }
                mutator.getIndexTransaction(indexType.getBackingIndexName()).restore(documentsPerStore);
            }
        } else
            throw new UnsupportedOperationException("Unsupported index found: " + index);
    } catch (final Exception e) {
        mgmt.rollback();
        writeTx.rollback();
        metrics.incrementCustom(FAILED_TX);
        throw new TitanException(e.getMessage(), e);
    }
}
Also used : InternalRelation(com.thinkaurelius.titan.graphdb.internal.InternalRelation) Entry(com.thinkaurelius.titan.diskstorage.Entry) IndexEntry(com.thinkaurelius.titan.diskstorage.indexing.IndexEntry) EdgeSerializer(com.thinkaurelius.titan.graphdb.database.EdgeSerializer) RelationTypeIndexWrapper(com.thinkaurelius.titan.graphdb.database.management.RelationTypeIndexWrapper) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) ImmutableList(com.google.common.collect.ImmutableList) MixedIndexType(com.thinkaurelius.titan.graphdb.types.MixedIndexType) CompositeIndexType(com.thinkaurelius.titan.graphdb.types.CompositeIndexType) IndexType(com.thinkaurelius.titan.graphdb.types.IndexType) BackendTransaction(com.thinkaurelius.titan.diskstorage.BackendTransaction) MixedIndexType(com.thinkaurelius.titan.graphdb.types.MixedIndexType) IndexSerializer(com.thinkaurelius.titan.graphdb.database.IndexSerializer) CompositeIndexType(com.thinkaurelius.titan.graphdb.types.CompositeIndexType) InternalRelationType(com.thinkaurelius.titan.graphdb.internal.InternalRelationType)

Example 64 with StaticBuffer

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

the class PartitionIDRange method getIDRanges.

public static List<PartitionIDRange> getIDRanges(final int partitionBits, final List<KeyRange> locals) {
    Preconditions.checkArgument(partitionBits > 0 && partitionBits < (Integer.SIZE - 1));
    Preconditions.checkArgument(locals != null && !locals.isEmpty(), "KeyRanges are empty");
    final int partitionIdBound = (1 << (partitionBits));
    final int backShift = Integer.SIZE - partitionBits;
    List<PartitionIDRange> partitionRanges = Lists.newArrayList();
    for (KeyRange local : locals) {
        Preconditions.checkArgument(local.getStart().length() >= 4);
        Preconditions.checkArgument(local.getEnd().length() >= 4);
        if (local.getStart().equals(local.getEnd())) {
            //Start=End => Partition spans entire range
            partitionRanges.add(new PartitionIDRange(0, partitionIdBound, partitionIdBound));
            continue;
        }
        int startInt = local.getStart().getInt(0);
        int lowerID = startInt >>> backShift;
        assert lowerID >= 0 && lowerID < partitionIdBound;
        //Lower id must be inclusive, so check that we did not truncate anything!
        boolean truncatedBits = (lowerID << backShift) != startInt;
        StaticBuffer start = local.getAt(0);
        for (int i = 4; i < start.length() && !truncatedBits; i++) {
            if (start.getByte(i) != 0)
                truncatedBits = true;
        }
        //adjust to make sure we are inclusive
        if (truncatedBits)
            lowerID += 1;
        //upper id is exclusive
        int upperID = local.getEnd().getInt(0) >>> backShift;
        //Check that we haven't jumped order indicating that the interval was too small
        if ((local.getStart().compareTo(local.getEnd()) < 0 && lowerID >= upperID)) {
            discardRange(local);
            continue;
        }
        //ensure that lowerID remains within range
        lowerID = lowerID % partitionIdBound;
        if (lowerID == upperID) {
            //After re-normalizing, check for interval colision
            discardRange(local);
            continue;
        }
        partitionRanges.add(new PartitionIDRange(lowerID, upperID, partitionIdBound));
    }
    return partitionRanges;
}
Also used : KeyRange(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyRange) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer)

Example 65 with StaticBuffer

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

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);
    EnumMap<LogTxMeta, Object> meta = new EnumMap<LogTxMeta, Object>(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(com.thinkaurelius.titan.graphdb.database.serialize.DataOutput) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer)

Aggregations

StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)92 Test (org.junit.Test)30 ArrayList (java.util.ArrayList)16 StaticBufferEntry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry)15 Entry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry)14 TemporaryStorageException (com.thinkaurelius.titan.diskstorage.TemporaryStorageException)13 ConsistentKeyLockStatus (com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus)13 DataOutput (com.thinkaurelius.titan.graphdb.database.serialize.DataOutput)12 HashMap (java.util.HashMap)12 ImmutableMap (com.google.common.collect.ImmutableMap)11 Map (java.util.Map)11 Entry (com.thinkaurelius.titan.diskstorage.Entry)10 ReadBuffer (com.thinkaurelius.titan.diskstorage.ReadBuffer)10 StorageException (com.thinkaurelius.titan.diskstorage.StorageException)9 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)8 KeySliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery)7 KCVMutation (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KCVMutation)6 KeyRange (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyRange)6 SliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)6 Instant (java.time.Instant)6