Search in sources :

Example 6 with StagingDatabase

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

the class MongoConflictsTest method testConflicts.

@Test
public void testConflicts() {
    StagingDatabase db = geogig.getRepository().stagingDatabase();
    List<Conflict> conflicts = db.getConflicts(null, null);
    assertTrue(conflicts.isEmpty());
    Conflict conflict = new Conflict(idP1, ObjectId.forString("ancestor"), ObjectId.forString("ours"), ObjectId.forString("theirs"));
    Conflict conflict2 = new Conflict(idP2, ObjectId.forString("ancestor2"), ObjectId.forString("ours2"), ObjectId.forString("theirs2"));
    db.addConflict(null, conflict);
    Optional<Conflict> returnedConflict = db.getConflict(null, idP1);
    assertTrue(returnedConflict.isPresent());
    assertEquals(conflict, returnedConflict.get());
    db.removeConflict(null, idP1);
    conflicts = db.getConflicts(null, null);
    assertTrue(conflicts.isEmpty());
    db.addConflict(null, conflict);
    db.addConflict(null, conflict2);
    assertEquals(2, db.getConflicts(null, null).size());
    db.removeConflicts(null);
    conflicts = db.getConflicts(null, null);
    assertTrue(conflicts.isEmpty());
    final String NS = "ns";
    db.addConflict(NS, conflict);
    db.addConflict(null, conflict2);
    returnedConflict = db.getConflict(NS, idP1);
    assertTrue(returnedConflict.isPresent());
    assertEquals(conflict, returnedConflict.get());
    assertEquals(1, db.getConflicts(NS, null).size());
    db.removeConflict(NS, idP1);
    conflicts = db.getConflicts(NS, null);
    assertTrue(conflicts.isEmpty());
    db.addConflict(NS, conflict);
    db.addConflict(NS, conflict2);
    assertEquals(2, db.getConflicts(NS, null).size());
    assertEquals(1, db.getConflicts(null, null).size());
    db.removeConflicts(NS);
    conflicts = db.getConflicts(NS, null);
    assertTrue(conflicts.isEmpty());
    conflicts = db.getConflicts(null, null);
    assertFalse(conflicts.isEmpty());
}
Also used : Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) StagingDatabase(org.locationtech.geogig.storage.StagingDatabase) Test(org.junit.Test)

Example 7 with StagingDatabase

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

the class WriteTree2 method applyChanges.

private RevTree applyChanges(@Nullable final NodeRef leftTreeRef, @Nullable final NodeRef rightTreeRef) {
    Preconditions.checkArgument(leftTreeRef != null || rightTreeRef != null, "either left or right tree shall be non null");
    final ObjectDatabase repositoryDatabase = objectDatabase();
    final String treePath = rightTreeRef == null ? leftTreeRef.path() : rightTreeRef.path();
    final List<String> strippedPathFilters = stripParentAndFiltersThatDontApply(this.pathFilters, treePath);
    // find the diffs that apply to the path filters
    final ObjectId leftTreeId = leftTreeRef == null ? RevTree.EMPTY_TREE_ID : leftTreeRef.objectId();
    final ObjectId rightTreeId = rightTreeRef == null ? RevTree.EMPTY_TREE_ID : rightTreeRef.objectId();
    final Predicate<Bounded> existsFilter = new Predicate<Bounded>() {

        private final ObjectDatabase targetDb = repositoryDatabase;

        @Override
        public boolean apply(Bounded input) {
            ObjectId id = null;
            if (input instanceof Node && TYPE.TREE.equals(((Node) input).getType())) {
                id = ((Node) input).getObjectId();
            } else if (input instanceof Bucket) {
                Bucket b = (Bucket) input;
                id = b.id();
            }
            if (id != null) {
                if (targetDb.exists(id)) {
                    LOGGER.trace("Ignoring {}. Already exists in target database.", input);
                    return false;
                }
            }
            return true;
        }
    };
    DiffTree diffs = command(DiffTree.class).setRecursive(false).setReportTrees(false).setOldTree(leftTreeId).setNewTree(rightTreeId).setPathFilter(strippedPathFilters).setCustomFilter(existsFilter);
    // move new blobs from the index to the repository (note: this could be parallelized)
    Supplier<Iterator<Node>> nodesToMove = asNodeSupplierOfNewContents(diffs, strippedPathFilters);
    command(DeepMove.class).setObjects(nodesToMove).call();
    final StagingDatabase stagingDatabase = stagingDatabase();
    final RevTree currentLeftTree = stagingDatabase.getTree(leftTreeId);
    final RevTreeBuilder builder = currentLeftTree.builder(repositoryDatabase);
    // remove the exists filter, we need to create the new trees taking into account all the
    // nodes
    diffs.setCustomFilter(null);
    Iterator<DiffEntry> iterator = diffs.get();
    if (!strippedPathFilters.isEmpty()) {
        final Set<String> expected = Sets.newHashSet(strippedPathFilters);
        iterator = Iterators.filter(iterator, new Predicate<DiffEntry>() {

            @Override
            public boolean apply(DiffEntry input) {
                boolean applies;
                if (input.isDelete()) {
                    applies = expected.contains(input.oldName());
                } else {
                    applies = expected.contains(input.newName());
                }
                return applies;
            }
        });
    }
    for (; iterator.hasNext(); ) {
        final DiffEntry diff = iterator.next();
        if (diff.isDelete()) {
            builder.remove(diff.oldName());
        } else {
            NodeRef newObject = diff.getNewObject();
            Node node = newObject.getNode();
            builder.put(node);
        }
    }
    final RevTree newTree = builder.build();
    repositoryDatabase.put(newTree);
    return newTree;
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) Predicate(com.google.common.base.Predicate) NodeRef(org.locationtech.geogig.api.NodeRef) Bounded(org.locationtech.geogig.api.Bounded) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) Bucket(org.locationtech.geogig.api.Bucket) Iterator(java.util.Iterator) RevTree(org.locationtech.geogig.api.RevTree) StagingDatabase(org.locationtech.geogig.storage.StagingDatabase) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 8 with StagingDatabase

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

the class DiffCount method _call.

@Override
protected DiffObjectCount _call() {
    checkState(oldRefSpec != null, "old ref spec not provided");
    checkState(newRefSpec != null, "new ref spec not provided");
    final RevTree oldTree = getTree(oldRefSpec);
    final RevTree newTree = getTree(newRefSpec);
    DiffObjectCount diffCount;
    StagingDatabase index = stagingDatabase();
    PreOrderDiffWalk visitor = new PreOrderDiffWalk(oldTree, newTree, index, index);
    DiffCountConsumer counter = new DiffCountConsumer(index);
    PreOrderDiffWalk.Consumer filter = counter;
    if (!pathFilters.isEmpty()) {
        filter = new PathFilteringDiffConsumer(pathFilters, counter);
    }
    visitor.walk(filter);
    diffCount = counter.get();
    return diffCount;
}
Also used : DiffObjectCount(org.locationtech.geogig.api.plumbing.diff.DiffObjectCount) PreOrderDiffWalk(org.locationtech.geogig.api.plumbing.diff.PreOrderDiffWalk) DiffCountConsumer(org.locationtech.geogig.api.plumbing.diff.DiffCountConsumer) RevTree(org.locationtech.geogig.api.RevTree) StagingDatabase(org.locationtech.geogig.storage.StagingDatabase) PathFilteringDiffConsumer(org.locationtech.geogig.api.plumbing.diff.PathFilteringDiffConsumer)

Aggregations

StagingDatabase (org.locationtech.geogig.storage.StagingDatabase)8 NodeRef (org.locationtech.geogig.api.NodeRef)4 ObjectId (org.locationtech.geogig.api.ObjectId)4 RevTree (org.locationtech.geogig.api.RevTree)4 Test (org.junit.Test)3 Optional (com.google.common.base.Optional)2 Node (org.locationtech.geogig.api.Node)2 RevFeature (org.locationtech.geogig.api.RevFeature)2 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)2 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)2 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)2 Conflict (org.locationtech.geogig.api.plumbing.merge.Conflict)2 SimpleFeature (org.opengis.feature.simple.SimpleFeature)2 Function (com.google.common.base.Function)1 Predicate (com.google.common.base.Predicate)1 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 DefaultTransaction (org.geotools.data.DefaultTransaction)1