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());
}
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;
}
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;
}
Aggregations