Search in sources :

Example 6 with ObjectId

use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.

the class FormatCommonV2 method readNode.

public static Node readNode(DataInput in) throws IOException {
    final int typeAndMasks = in.readByte() & 0xFF;
    final int nodeType = typeAndMasks & TYPE_READ_MASK;
    final int boundsMask = typeAndMasks & BOUNDS_READ_MASK;
    final int metadataMask = typeAndMasks & METADATA_READ_MASK;
    final RevObject.TYPE contentType = RevObject.TYPE.valueOf(nodeType);
    final String name = in.readUTF();
    final ObjectId objectId = readObjectId(in);
    ObjectId metadataId = ObjectId.NULL;
    if (metadataMask == METADATA_PRESENT_MASK) {
        metadataId = readObjectId(in);
    }
    @Nullable final Envelope bbox;
    if (boundsMask == BOUNDS_NULL_MASK) {
        bbox = null;
    } else if (boundsMask == BOUNDS_POINT_MASK) {
        bbox = readPointBoundingBox(in);
    } else if (boundsMask == BOUNDS_BOX2D_MASK) {
        bbox = readBoundingBox(in);
    } else {
        throw new IllegalStateException(String.format("Illegal bounds mask: %s, expected one of %s, %s, %s", toBinaryString(boundsMask), toBinaryString(BOUNDS_NULL_MASK), toBinaryString(BOUNDS_POINT_MASK), toBinaryString(BOUNDS_BOX2D_MASK)));
    }
    final Node node;
    node = Node.create(name, objectId, metadataId, contentType, bbox);
    return node;
}
Also used : TYPE(org.locationtech.geogig.api.RevObject.TYPE) RevObject(org.locationtech.geogig.api.RevObject) ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) Integer.toBinaryString(java.lang.Integer.toBinaryString) Envelope(com.vividsolutions.jts.geom.Envelope) Nullable(javax.annotation.Nullable)

Example 7 with ObjectId

use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.

the class FormatCommonV2 method readBucketBody.

/**
     * Reads a bucket body (i.e assumes the head unsigned int "index" has been read already)
     */
private static final Bucket readBucketBody(DataInput in) throws IOException {
    ObjectId objectId = readObjectId(in);
    final int boundsMask = in.readByte() & 0xFF;
    @Nullable final Envelope bounds;
    if (BOUNDS_POINT_MASK == boundsMask) {
        bounds = readPointBoundingBox(in);
    } else if (BOUNDS_BOX2D_MASK == boundsMask) {
        bounds = readBoundingBox(in);
    } else {
        bounds = null;
    }
    return Bucket.create(objectId, bounds);
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) Envelope(com.vividsolutions.jts.geom.Envelope) Nullable(javax.annotation.Nullable)

Example 8 with ObjectId

use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.

the class LocalRemoteRepo method copyNewObjects.

private void copyNewObjects(RevTree oldTree, RevTree newTree, final ObjectDatabase fromDb, final ObjectDatabase toDb, final ProgressListener progress) {
    checkNotNull(oldTree);
    checkNotNull(newTree);
    checkNotNull(fromDb);
    checkNotNull(toDb);
    checkNotNull(progress);
    // the diff walk uses fromDb as both left and right data source since we're comparing what
    // we have in the "origin" database against trees on the same repository
    PostOrderDiffWalk diffWalk = new PostOrderDiffWalk(oldTree, newTree, fromDb, fromDb);
    // holds object ids that need to be copied to the target db. Pruned when it reaches a
    // threshold.
    final Set<ObjectId> ids = new HashSet<ObjectId>();
    // This filter further refines the post order diff walk by making it ignore trees/buckets
    // that are already present in the target db
    Predicate<Bounded> filter = new Predicate<Bounded>() {

        @Override
        public boolean apply(@Nullable Bounded b) {
            if (b == null) {
                return false;
            }
            if (progress.isCanceled()) {
                // abort traversal
                return false;
            }
            ObjectId id;
            if (b instanceof Node) {
                Node node = (Node) b;
                if (RevObject.TYPE.TREE.equals(node.getType())) {
                    // check of existence of trees only. For features the diff filtering is good
                    // enough and checking for existence on each feature would be killer
                    // performance wise
                    id = node.getObjectId();
                } else {
                    return true;
                }
            } else {
                id = ((Bucket) b).id();
            }
            boolean exists = ids.contains(id) || toDb.exists(id);
            return !exists;
        }
    };
    // receives notifications of feature/bucket/tree diffs. Only interested in the "new"/right
    // side of the comparisons
    Consumer consumer = new Consumer() {

        final int bulkSize = 10_000;

        @Override
        public void feature(@Nullable Node left, Node right) {
            add(left);
            add(right);
        }

        @Override
        public void tree(@Nullable Node left, Node right) {
            add(left);
            add(right);
        }

        private void add(@Nullable Node node) {
            if (node == null) {
                return;
            }
            ids.add(node.getObjectId());
            Optional<ObjectId> metadataId = node.getMetadataId();
            if (metadataId.isPresent()) {
                ids.add(metadataId.get());
            }
            checkLimitAndCopy();
        }

        @Override
        public void bucket(int bucketIndex, int bucketDepth, @Nullable Bucket left, Bucket right) {
            if (left != null) {
                ids.add(left.id());
            }
            if (right != null) {
                ids.add(right.id());
            }
            checkLimitAndCopy();
        }

        private void checkLimitAndCopy() {
            if (ids.size() >= bulkSize) {
                copy(ids, fromDb, toDb, progress);
                ids.clear();
            }
        }
    };
    diffWalk.walk(filter, consumer);
    // copy remaining objects
    copy(ids, fromDb, toDb, progress);
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) Predicate(com.google.common.base.Predicate) Bounded(org.locationtech.geogig.api.Bounded) Consumer(org.locationtech.geogig.api.plumbing.diff.PostOrderDiffWalk.Consumer) Bucket(org.locationtech.geogig.api.Bucket) PostOrderDiffWalk(org.locationtech.geogig.api.plumbing.diff.PostOrderDiffWalk) Nullable(javax.annotation.Nullable) HashSet(java.util.HashSet)

Example 9 with ObjectId

use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.

the class LocalRemoteRepo method pushNewData.

/**
     * Push all new objects from the specified {@link Ref} to the given refspec.
     * 
     * @param ref the local ref that points to new commit data
     * @param refspec the refspec to push to
     */
@Override
public void pushNewData(final Ref ref, final String refspec, final ProgressListener progress) throws SynchronizationException {
    Optional<Ref> remoteRef = remoteGeoGig.command(RefParse.class).setName(refspec).call();
    remoteRef = remoteRef.or(remoteGeoGig.command(RefParse.class).setName(Ref.TAGS_PREFIX + refspec).call());
    checkPush(ref, remoteRef);
    CommitTraverser traverser = getPushTraverser(remoteRef);
    traverser.traverse(ref.getObjectId());
    progress.setDescription("Uploading objects to " + refspec);
    progress.setProgress(0);
    while (!traverser.commits.isEmpty()) {
        ObjectId commitId = traverser.commits.pop();
        walkHead(commitId, false, progress);
    }
    String nameToSet = remoteRef.isPresent() ? remoteRef.get().getName() : Ref.HEADS_PREFIX + refspec;
    Ref updatedRef = remoteGeoGig.command(UpdateRef.class).setName(nameToSet).setNewValue(ref.getObjectId()).call().get();
    Ref remoteHead = headRef();
    if (remoteHead instanceof SymRef) {
        if (((SymRef) remoteHead).getTarget().equals(updatedRef.getName())) {
            remoteGeoGig.command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(ref.getName()).call();
            RevCommit commit = remoteGeoGig.getRepository().getCommit(ref.getObjectId());
            remoteGeoGig.getRepository().workingTree().updateWorkHead(commit.getTreeId());
            remoteGeoGig.getRepository().index().updateStageHead(commit.getTreeId());
        }
    }
}
Also used : UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) ForEachRef(org.locationtech.geogig.api.plumbing.ForEachRef) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) Ref(org.locationtech.geogig.api.Ref) SymRef(org.locationtech.geogig.api.SymRef) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) SymRef(org.locationtech.geogig.api.SymRef) ObjectId(org.locationtech.geogig.api.ObjectId) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 10 with ObjectId

use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.

the class LocalRemoteRepo method fetchNewData.

/**
     * Fetch all new objects from the specified {@link Ref} from the remote.
     * 
     * @param ref the remote ref that points to new commit data
     * @param fetchLimit the maximum depth to fetch
     */
@Override
public void fetchNewData(Ref ref, Optional<Integer> fetchLimit, ProgressListener progress) {
    CommitTraverser traverser = getFetchTraverser(fetchLimit);
    try {
        progress.setDescription("Fetching objects from " + ref.getName());
        progress.setProgress(0);
        traverser.traverse(ref.getObjectId());
        List<ObjectId> toSend = new LinkedList<ObjectId>(traverser.commits);
        // send oldest commits first
        Collections.reverse(toSend);
        for (ObjectId newHeadId : toSend) {
            walkHead(newHeadId, true, progress);
        }
    } catch (Exception e) {
        Throwables.propagate(e);
    }
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) LinkedList(java.util.LinkedList) SynchronizationException(org.locationtech.geogig.api.porcelain.SynchronizationException) IOException(java.io.IOException)

Aggregations

ObjectId (org.locationtech.geogig.api.ObjectId)361 Test (org.junit.Test)133 RevCommit (org.locationtech.geogig.api.RevCommit)109 NodeRef (org.locationtech.geogig.api.NodeRef)98 RevTree (org.locationtech.geogig.api.RevTree)91 RevObject (org.locationtech.geogig.api.RevObject)53 Ref (org.locationtech.geogig.api.Ref)46 Node (org.locationtech.geogig.api.Node)44 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)38 Feature (org.opengis.feature.Feature)35 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)34 LogOp (org.locationtech.geogig.api.porcelain.LogOp)28 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)27 LinkedList (java.util.LinkedList)26 ArrayList (java.util.ArrayList)25 RevFeature (org.locationtech.geogig.api.RevFeature)25 IOException (java.io.IOException)23 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)23 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)23 SymRef (org.locationtech.geogig.api.SymRef)22