Search in sources :

Example 56 with RevObject

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

the class BinaryPackedChanges method asObjects.

/**
     * Returns an iterator that calls the {@code callback} for each {@link DiffPacket}'s
     * {@link DiffEntry} once, and returns either zero, one, or two {@link RevObject}s, depending on
     * which information the diff packet carried over.
     */
private Iterator<RevObject> asObjects(final PacketReadingIterator readingIterator, final Callback callback) {
    return new AbstractIterator<RevObject>() {

        private DiffPacket current;

        @Override
        protected RevObject computeNext() {
            if (current != null) {
                Preconditions.checkState(current.metadataObject != null);
                RevObject ret = current.metadataObject;
                current = null;
                return ret;
            }
            while (readingIterator.hasNext()) {
                DiffPacket diffPacket = readingIterator.next();
                callback.callback(diffPacket.entry);
                RevObject obj = diffPacket.newObject;
                RevObject md = diffPacket.metadataObject;
                Preconditions.checkState(obj != null || (obj == null && md == null));
                if (obj != null) {
                    if (md != null) {
                        current = diffPacket;
                    }
                    return obj;
                }
            }
            return endOfData();
        }
    };
}
Also used : RevObject(org.locationtech.geogig.api.RevObject) AbstractIterator(com.google.common.collect.AbstractIterator)

Example 57 with RevObject

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

the class BinaryPackedChanges method ingest.

/**
     * Read in the changes from the provided input stream and call the provided callback for each
     * change. The input stream represents the output of another {@code BinaryPackedChanges}
     * instance.
     * 
     * @param in the stream to read from
     * @param callback the callback to call for each item
     */
public void ingest(final InputStream in, Callback callback) {
    PacketReadingIterator readingIterator = new PacketReadingIterator(in);
    Iterator<RevObject> asObjects = asObjects(readingIterator, callback);
    ObjectDatabase objectDatabase = repository.objectDatabase();
    CountingListener listener = BulkOpListener.newCountingListener();
    objectDatabase.putAll(asObjects, listener);
    LOGGER.info("Ingested %,d objects. Inserted: %,d. Already existing: %,d\n", listener.inserted() + listener.found(), listener.inserted(), listener.found());
    this.filtered = readingIterator.isFiltered();
}
Also used : CountingListener(org.locationtech.geogig.storage.BulkOpListener.CountingListener) RevObject(org.locationtech.geogig.api.RevObject) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase)

Example 58 with RevObject

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

the class BinaryPackedChanges method write.

/**
     * Writes the set of changes to the provided output stream.
     * 
     * @param out the stream to write to
     * @param changes the changes to write
     * @throws IOException
     * @return the number of objects written
     */
public long write(OutputStream out, Iterator<DiffEntry> changes) throws IOException {
    final ObjectDatabase objectDatabase = repository.objectDatabase();
    out = new CountingOutputStream(out);
    // avoids sending the same metadata object multiple times
    Set<ObjectId> writtenMetadataIds = new HashSet<ObjectId>();
    // buffer to avoid ObjectId cloning its internal state for each object
    byte[] oidbuffer = new byte[ObjectId.NUM_BYTES];
    long objectCount = 0;
    while (changes.hasNext()) {
        DiffEntry diff = changes.next();
        if (diff.isDelete()) {
            out.write(CHUNK_TYPE.DIFF_ENTRY.value());
        } else {
            // its a change or an addition, new object is guaranteed to be present
            NodeRef newObject = diff.getNewObject();
            ObjectId metadataId = newObject.getMetadataId();
            if (writtenMetadataIds.contains(metadataId)) {
                out.write(CHUNK_TYPE.OBJECT_AND_DIFF_ENTRY.value());
            } else {
                out.write(CHUNK_TYPE.METADATA_OBJECT_AND_DIFF_ENTRY.value());
                RevObject metadata = objectDatabase.get(metadataId);
                writeObjectId(metadataId, out, oidbuffer);
                serializer.createObjectWriter(metadata.getType()).write(metadata, out);
                writtenMetadataIds.add(metadataId);
                objectCount++;
            }
            ObjectId objectId = newObject.objectId();
            writeObjectId(objectId, out, oidbuffer);
            RevObject object = objectDatabase.get(objectId);
            serializer.createObjectWriter(object.getType()).write(object, out);
            objectCount++;
        }
        DataOutput dataOut = new DataOutputStream(out);
        FormatCommonV1.writeDiff(diff, dataOut);
    }
    // signal the end of changes
    out.write(CHUNK_TYPE.FILTER_FLAG.value());
    final boolean filtersApplied = changes instanceof FilteredDiffIterator && ((FilteredDiffIterator) changes).wasFiltered();
    out.write(filtersApplied ? 1 : 0);
    LOGGER.info(String.format("Written %,d bytes to remote accounting for %,d objects.", ((CountingOutputStream) out).getCount(), objectCount));
    return objectCount;
}
Also used : DataOutput(java.io.DataOutput) ObjectId(org.locationtech.geogig.api.ObjectId) FormatCommonV1.readObjectId(org.locationtech.geogig.storage.datastream.FormatCommonV1.readObjectId) RevObject(org.locationtech.geogig.api.RevObject) DataOutputStream(java.io.DataOutputStream) NodeRef(org.locationtech.geogig.api.NodeRef) CountingOutputStream(com.google.common.io.CountingOutputStream) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) HashSet(java.util.HashSet) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 59 with RevObject

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

the class LocalRemoteRepo method walkHead.

protected void walkHead(final ObjectId newHeadId, final boolean fetch, final ProgressListener progress) {
    Repository from = localRepository;
    Repository to = remoteGeoGig.getRepository();
    if (fetch) {
        Repository tmp = to;
        to = from;
        from = tmp;
    }
    final ObjectDatabase fromDb = from.objectDatabase();
    final ObjectDatabase toDb = to.objectDatabase();
    final RevObject object = fromDb.get(newHeadId);
    RevCommit commit = null;
    RevTag tag = null;
    if (object.getType().equals(TYPE.COMMIT)) {
        commit = (RevCommit) object;
    } else if (object.getType().equals(TYPE.TAG)) {
        tag = (RevTag) object;
        commit = fromDb.getCommit(tag.getCommitId());
    }
    if (commit != null) {
        final RevTree newTree = fromDb.getTree(commit.getTreeId());
        List<ObjectId> parentIds = new ArrayList<>(commit.getParentIds());
        if (parentIds.isEmpty()) {
            parentIds.add(ObjectId.NULL);
        }
        RevTree oldTree = RevTree.EMPTY;
        // the diff against each parent is not working. For some reason some buckets that are
        // equal between the two ends of the comparison never get transferred (at some point
        // they shouldn't be equal and so the Consumer notified of it/them). Yet with the target
        // databse exists check for each tree the performance is good enough.
        // for (ObjectId parentId : parentIds) {
        // if (!parentId.isNull()) {
        // RevCommit parent = fromDb.getCommit(parentId);
        // oldTree = fromDb.getTree(parent.getTreeId());
        // }
        copyNewObjects(oldTree, newTree, fromDb, toDb, progress);
        // }
        Preconditions.checkState(toDb.exists(newTree.getId()));
        toDb.put(commit);
    }
    if (tag != null) {
        toDb.put(tag);
    }
}
Also used : Repository(org.locationtech.geogig.repository.Repository) RevTag(org.locationtech.geogig.api.RevTag) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) RevObject(org.locationtech.geogig.api.RevObject) ObjectId(org.locationtech.geogig.api.ObjectId) ArrayList(java.util.ArrayList) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 60 with RevObject

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

the class LocalCopyingDiffIterator method computeNext.

/**
     * @return the next {@link DiffEntry}
     */
protected DiffEntry computeNext() {
    if (source.hasNext()) {
        DiffEntry next = source.next();
        if (next.getNewObject() != null) {
            NodeRef newObject = next.getNewObject();
            RevObject object = sourceRepo.command(RevObjectParse.class).setObjectId(newObject.getNode().getObjectId()).call().get();
            RevObject metadata = null;
            if (newObject.getMetadataId() != ObjectId.NULL) {
                metadata = sourceRepo.command(RevObjectParse.class).setObjectId(newObject.getMetadataId()).call().get();
            }
            if (!destinationRepo.blobExists(object.getId())) {
                destinationRepo.objectDatabase().put(object);
            }
            if (metadata != null && !destinationRepo.blobExists(metadata.getId())) {
                destinationRepo.objectDatabase().put(metadata);
            }
        }
        return next;
    }
    return endOfData();
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) RevObject(org.locationtech.geogig.api.RevObject) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Aggregations

RevObject (org.locationtech.geogig.api.RevObject)84 ObjectId (org.locationtech.geogig.api.ObjectId)51 RevCommit (org.locationtech.geogig.api.RevCommit)30 NodeRef (org.locationtech.geogig.api.NodeRef)22 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)22 RevTree (org.locationtech.geogig.api.RevTree)21 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)17 RevFeature (org.locationtech.geogig.api.RevFeature)17 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)16 Feature (org.opengis.feature.Feature)16 IOException (java.io.IOException)15 LinkedList (java.util.LinkedList)15 LogOp (org.locationtech.geogig.api.porcelain.LogOp)14 GeoGIG (org.locationtech.geogig.api.GeoGIG)13 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)11 HashMap (java.util.HashMap)10 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)10 Optional (com.google.common.base.Optional)8 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)8