Search in sources :

Example 21 with ObjectDatabase

use of org.locationtech.geogig.storage.ObjectDatabase in project GeoGig by boundlessgeo.

the class DiffTreeTest method testChangeTypeFilter.

@Test
public void testChangeTypeFilter() {
    ObjectDatabase db = geogit.getContext().objectDatabase();
    final RevTree tree1 = tree(1000, db);
    final RevTree tree2 = tree(50, db);
    final RevTree tree2Changed;
    {
        RevTreeBuilder builder = new RevTreeBuilder(db, tree2);
        // add 10 changed features, and delete 10 more
        for (int i = 0; i < 20; i++) {
            if (i % 2 == 0) {
                builder.remove(String.valueOf(i));
            } else {
                builder.put(feature(i, ObjectId.forString("changed" + i)));
            }
        }
        tree2Changed = builder.build();
        db.put(tree2Changed);
        assertEquals(tree2.size() - 10, tree2Changed.size());
    }
    final RevTree root1 = createRoot(db, tree1, tree2);
    final RevTree root2 = createRoot(db, tree1, tree2Changed);
    assertChangeTypeFilter(ObjectId.NULL, root1.getId(), (int) (tree1.size() + tree2.size()), 0, 0);
    assertChangeTypeFilter(root1.getId(), ObjectId.NULL, 0, (int) (tree1.size() + tree2.size()), 0);
    assertChangeTypeFilter(tree2.getId(), tree2Changed.getId(), 0, 10, 10);
    assertChangeTypeFilter(root1.getId(), root2.getId(), 0, 10, 10);
    assertChangeTypeFilter(root2.getId(), root1.getId(), 10, 0, 10);
}
Also used : ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 22 with ObjectDatabase

use of org.locationtech.geogig.storage.ObjectDatabase in project GeoGig by boundlessgeo.

the class DiffTreeTest method testMixedFilters.

/**
     * Apply path, bounds, and changeType filtering all at once
     */
@Test
public void testMixedFilters() {
    ObjectDatabase db = geogit.getContext().objectDatabase();
    final RevTree tree1 = tree(1000, db);
    final RevTree tree2 = tree(50, db);
    final RevTree tree2Changed;
    {
        RevTreeBuilder builder = new RevTreeBuilder(db, tree2);
        // add 10 changed features, and delete 10 more
        for (int i = 0; i < 20; i++) {
            if (i % 2 == 0) {
                builder.remove(String.valueOf(i));
            } else {
                builder.put(feature(i, ObjectId.forString("changed" + i)));
            }
        }
        tree2Changed = builder.build();
        db.put(tree2Changed);
        assertEquals(tree2.size() - 10, tree2Changed.size());
    }
    final RevTree root1 = createRoot(db, tree1, tree2);
    final RevTree root2 = createRoot(db, tree1, tree2Changed);
    final ObjectId rootId1 = root1.getId();
    final ObjectId rootId2 = root2.getId();
    CoordinateReferenceSystem crs = revtype.type().getCoordinateReferenceSystem();
    // boundsFilter covers features 1-11
    ReferencedEnvelope boundsFilter = new ReferencedEnvelope(1.9, 11.1, 1.9, 11.1, crs);
    // first try with bounds only
    diffTree.setBoundsFilter(boundsFilter);
    assertEquals(10, Iterators.size(diffTree.setOldTree(rootId1).setNewTree(rootId2).call()));
    assertChangeTypeFilter(rootId1, rootId2, 0, 5, 5);
    assertChangeTypeFilter(rootId2, rootId1, 5, 0, 5);
    // now add path filtering
    diffTree.setPathFilter("tree1");
    assertChangeTypeFilter(rootId1, rootId2, 0, 0, 0);
    assertChangeTypeFilter(rootId2, rootId1, 0, 0, 0);
    diffTree.setPathFilter("tree2");
    assertChangeTypeFilter(rootId1, rootId2, 0, 5, 5);
    assertChangeTypeFilter(rootId2, rootId1, 5, 0, 5);
    // odd feature ids from 0 to 18 were removed from tree2
    // tree2/0 and tree2/12 match path filter but don't match bounds filter
    diffTree.setPathFilter(ImmutableList.of("tree2/0", "tree2/2", "tree2/4", "tree2/12"));
    diffTree.setBoundsFilter(null);
    assertChangeTypeFilter(rootId1, rootId2, 0, 4, 0);
    assertChangeTypeFilter(rootId2, rootId1, 4, 0, 0);
    diffTree.setBoundsFilter(boundsFilter);
    assertChangeTypeFilter(rootId1, rootId2, 0, 2, 0);
    assertChangeTypeFilter(rootId2, rootId1, 2, 0, 0);
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) ObjectId(org.locationtech.geogig.api.ObjectId) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 23 with ObjectDatabase

use of org.locationtech.geogig.storage.ObjectDatabase in project GeoGig by boundlessgeo.

the class WriteTree2Test method verifyRepositoryTree.

private void verifyRepositoryTree(String path, ObjectId repoTreeId) {
    ObjectDatabase objectDb = this.objectDb;
    verifyTree(objectDb, path, repoTreeId);
}
Also used : ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase)

Example 24 with ObjectDatabase

use of org.locationtech.geogig.storage.ObjectDatabase in project GeoGig by boundlessgeo.

the class AbstractMappedRemoteRepo method fetchSparseCommit.

/**
     * This function takes all of the changes introduced by the specified commit and filters them
     * based on the repository filter. It then uses the filtered results to construct a new commit
     * that is the descendant of commits that the original's parents are mapped to.
     * 
     * @param commitId the commit id of the original, non-sparse commit
     * @param allowEmpty allow the function to create an empty sparse commit
     */
private void fetchSparseCommit(ObjectId commitId, boolean allowEmpty) {
    Optional<RevObject> object = getObject(commitId);
    if (object.isPresent() && object.get().getType().equals(TYPE.COMMIT)) {
        RevCommit commit = (RevCommit) object.get();
        FilteredDiffIterator changes = getFilteredChanges(commit);
        GraphDatabase graphDatabase = localRepository.graphDatabase();
        ObjectDatabase objectDatabase = localRepository.objectDatabase();
        graphDatabase.put(commit.getId(), commit.getParentIds());
        RevTree rootTree = RevTree.EMPTY;
        if (commit.getParentIds().size() > 0) {
            // Map this commit to the last "sparse" commit in my ancestry
            ObjectId mappedCommit = graphDatabase.getMapping(commit.getParentIds().get(0));
            graphDatabase.map(commit.getId(), mappedCommit);
            Optional<ObjectId> treeId = localRepository.command(ResolveTreeish.class).setTreeish(mappedCommit).call();
            if (treeId.isPresent()) {
                rootTree = localRepository.getTree(treeId.get());
            }
        } else {
            graphDatabase.map(commit.getId(), ObjectId.NULL);
        }
        Iterator<DiffEntry> it = Iterators.filter(changes, new Predicate<DiffEntry>() {

            @Override
            public boolean apply(DiffEntry e) {
                return true;
            }
        });
        if (it.hasNext()) {
            // Create new commit
            WriteTree writeTree = localRepository.command(WriteTree.class).setOldRoot(Suppliers.ofInstance(rootTree)).setDiffSupplier(Suppliers.ofInstance((Iterator<DiffEntry>) it));
            if (changes.isAutoIngesting()) {
                // the iterator already ingests objects into the ObjectDatabase
                writeTree.dontMoveObjects();
            }
            ObjectId newTreeId = writeTree.call();
            CommitBuilder builder = new CommitBuilder(commit);
            List<ObjectId> newParents = new LinkedList<ObjectId>();
            for (ObjectId parentCommitId : commit.getParentIds()) {
                newParents.add(graphDatabase.getMapping(parentCommitId));
            }
            builder.setParentIds(newParents);
            builder.setTreeId(newTreeId);
            RevCommit mapped = builder.build();
            objectDatabase.put(mapped);
            if (changes.wasFiltered()) {
                graphDatabase.setProperty(mapped.getId(), GraphDatabase.SPARSE_FLAG, "true");
            }
            graphDatabase.map(mapped.getId(), commit.getId());
            // Replace the old mapping with the new commit Id.
            graphDatabase.map(commit.getId(), mapped.getId());
        } else if (allowEmpty) {
            CommitBuilder builder = new CommitBuilder(commit);
            List<ObjectId> newParents = new LinkedList<ObjectId>();
            for (ObjectId parentCommitId : commit.getParentIds()) {
                newParents.add(graphDatabase.getMapping(parentCommitId));
            }
            builder.setParentIds(newParents);
            builder.setTreeId(rootTree.getId());
            builder.setMessage(PLACEHOLDER_COMMIT_MESSAGE);
            RevCommit mapped = builder.build();
            objectDatabase.put(mapped);
            graphDatabase.setProperty(mapped.getId(), GraphDatabase.SPARSE_FLAG, "true");
            graphDatabase.map(mapped.getId(), commit.getId());
            // Replace the old mapping with the new commit Id.
            graphDatabase.map(commit.getId(), mapped.getId());
        } else {
            // Mark the mapped commit as sparse, since it wont have these changes
            graphDatabase.setProperty(graphDatabase.getMapping(commit.getId()), GraphDatabase.SPARSE_FLAG, "true");
        }
    }
}
Also used : WriteTree(org.locationtech.geogig.api.plumbing.WriteTree) RevObject(org.locationtech.geogig.api.RevObject) GraphDatabase(org.locationtech.geogig.storage.GraphDatabase) ObjectId(org.locationtech.geogig.api.ObjectId) CommitBuilder(org.locationtech.geogig.api.CommitBuilder) LinkedList(java.util.LinkedList) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) Iterator(java.util.Iterator) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) List(java.util.List) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 25 with ObjectDatabase

use of org.locationtech.geogig.storage.ObjectDatabase 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)

Aggregations

ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)27 RevTree (org.locationtech.geogig.api.RevTree)18 ObjectId (org.locationtech.geogig.api.ObjectId)13 RevObject (org.locationtech.geogig.api.RevObject)8 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)8 Test (org.junit.Test)7 NodeRef (org.locationtech.geogig.api.NodeRef)7 RevCommit (org.locationtech.geogig.api.RevCommit)5 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)5 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)4 HashSet (java.util.HashSet)3 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)3 Node (org.locationtech.geogig.api.Node)3 IOException (java.io.IOException)2 Iterator (java.util.Iterator)2 LinkedList (java.util.LinkedList)2 CommitBuilder (org.locationtech.geogig.api.CommitBuilder)2 ProgressListener (org.locationtech.geogig.api.ProgressListener)2 Ref (org.locationtech.geogig.api.Ref)2 TYPE (org.locationtech.geogig.api.RevObject.TYPE)2