Package com.thinkaurelius.titan.diskstorage

Examples of com.thinkaurelius.titan.diskstorage.BackendTransaction$SliceQueryRunner


    public void commit(final Collection<InternalRelation> addedRelations,
                     final Collection<InternalRelation> deletedRelations, final StandardTitanTx tx) {
        //Setup
        log.debug("Saving transaction. Added {}, removed {}", addedRelations.size(), deletedRelations.size());

        final BackendTransaction mutator = tx.getTxHandle();
        final boolean acquireLocks = tx.getConfiguration().hasAcquireLocks();

        //1. Assign TitanVertex IDs
        if (!tx.getConfiguration().hasAssignIDsImmediately())
            idAssigner.assignIDs(addedRelations);

        Callable<List<StaticBuffer>> persist = new Callable<List<StaticBuffer>>() {
            @Override
            public List<StaticBuffer> call() throws Exception {
                //2. Collect deleted edges
                ListMultimap<InternalVertex, InternalRelation> mutations = ArrayListMultimap.create();
                if (deletedRelations != null && !deletedRelations.isEmpty()) {
                    for (InternalRelation del : deletedRelations) {
                        Preconditions.checkArgument(del.isRemoved());
                        for (int pos = 0; pos < del.getLen(); pos++) {
                            InternalVertex vertex = del.getVertex(pos);
                            if (pos == 0 || !del.isLoop()) mutations.put(vertex, del);
                            Direction dir = EdgeDirection.fromPosition(pos);
                            if (acquireLocks && del.getType().isUnique(dir) &&
                                    ((InternalType) del.getType()).uniqueLock(dir)) {
                                Entry entry = edgeSerializer.writeRelation(del, pos, tx);
                                mutator.acquireEdgeLock(IDHandler.getKey(vertex.getID()), entry.getColumn(), entry.getValue());
                            }
                        }
                        //Update Indexes
                        if (del.isProperty()) {
                            if (acquireLocks) indexSerializer.lockKeyedProperty((TitanProperty) del, mutator);
                        }

                    }
                }

                ListMultimap<InternalType, InternalRelation> otherEdgeTypes = ArrayListMultimap.create();

                //3. Sort Added Edges
                for (InternalRelation relation : addedRelations) {
                    Preconditions.checkArgument(relation.isNew());

                    TitanType type = relation.getType();

                    //Give special treatment to edge type definitions
                    if (SystemTypeManager.prepersistedSystemTypes.contains(type)) {
                        InternalType itype = (InternalType) relation.getVertex(0);
                        otherEdgeTypes.put(itype, relation);
                    } else { //STANDARD TitanRelation
                        for (int pos = 0; pos < relation.getLen(); pos++) {
                            InternalVertex vertex = relation.getVertex(pos);
                            if (pos == 0 || !relation.isLoop()) mutations.put(vertex, relation);
                            Direction dir = EdgeDirection.fromPosition(pos);
                            if (acquireLocks && relation.getType().isUnique(dir) && !vertex.isNew()
                                    && ((InternalType) relation.getType()).uniqueLock(dir)) {
                                Entry entry = edgeSerializer.writeRelation(relation, pos, tx);
                                mutator.acquireEdgeLock(IDHandler.getKey(vertex.getID()), entry.getColumn(), null);
                            }
                        }
                    }
                    //Update Indexes
                    if (relation.isProperty()) {
                        if (acquireLocks) indexSerializer.lockKeyedProperty((TitanProperty) relation, mutator);
                    }

                }

                //3. Persist
                List<StaticBuffer> mutatedVertexKeys = new ArrayList<StaticBuffer>();
                if (!otherEdgeTypes.isEmpty()) {
                    mutatedVertexKeys.addAll(persist(otherEdgeTypes, tx));
                    mutator.flush();
                    //Register new keys with indexprovider
                    for (InternalType itype : otherEdgeTypes.keySet()) {
                        if (itype.isPropertyKey() && itype.isNew())
                            indexSerializer.newPropertyKey((TitanKey) itype, mutator);
                    }
                }

                if (!mutations.isEmpty()) mutatedVertexKeys.addAll(persist(mutations, tx));
                mutator.commit();
                return mutatedVertexKeys;
            }

            @Override
            public String toString() {
View Full Code Here


                                                    StandardTitanTx tx) throws StorageException {
        assert mutatedEdges != null && !mutatedEdges.isEmpty();

        Collection<V> vertices = mutatedEdges.keySet();

        BackendTransaction mutator = tx.getTxHandle();
        List<StaticBuffer> mutatedKeys = new ArrayList<StaticBuffer>(vertices.size());
        for (V vertex : vertices) {
            Preconditions.checkArgument(vertex.getID() > 0, "Vertex has no id: %s", vertex.getID());
            List<InternalRelation> edges = mutatedEdges.get(vertex);
            List<Entry> additions = new ArrayList<Entry>(edges.size());
            List<StaticBuffer> deletions = new ArrayList<StaticBuffer>(Math.max(10, edges.size() / 10));
            for (InternalRelation edge : edges) {
                for (int pos = 0; pos < edge.getLen(); pos++) {
                    if (edge.getVertex(pos).equals(vertex)) {
                        if (edge.isRemoved()) {
                            deletions.add(edgeSerializer.writeRelation(edge, pos, tx).getColumn());
                        } else {
                            Preconditions.checkArgument(edge.isNew());
                            additions.add(edgeSerializer.writeRelation(edge, pos, tx));
                        }
                    }
                }
            }

            StaticBuffer vertexKey = IDHandler.getKey(vertex.getID());
            mutator.mutateEdges(vertexKey, additions, deletions);
            if (!vertex.isNew()) mutatedKeys.add(vertexKey);
            //Index Updates
            for (InternalRelation relation : edges) {
                if (relation.getVertex(0).equals(vertex)) {
                    if (relation.isRemoved()) {
View Full Code Here

TOP

Related Classes of com.thinkaurelius.titan.diskstorage.BackendTransaction$SliceQueryRunner

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.