use of org.locationtech.geogig.api.plumbing.diff.PostOrderDiffWalk.Consumer 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);
}
use of org.locationtech.geogig.api.plumbing.diff.PostOrderDiffWalk.Consumer in project GeoGig by boundlessgeo.
the class PostOrderDiffWalkTest method testSameRootTree.
@Test
public void testSameRootTree() {
RevTree left = createFeaturesTree(leftSource, "f", 10).build();
RevTree right = left;
PostOrderDiffWalk visitor = new PostOrderDiffWalk(left, right, leftSource, rightSource);
Consumer consumer = mock(Consumer.class);
visitor.walk(consumer);
verifyNoMoreInteractions(consumer);
}
use of org.locationtech.geogig.api.plumbing.diff.PostOrderDiffWalk.Consumer in project GeoGig by boundlessgeo.
the class PostOrderDiffWalkTest method testSameChildTree.
@Test
public void testSameChildTree() {
RevTree left = createFeaturesTree(leftSource, "f", 10).build();
RevTree right = left;
PostOrderDiffWalk visitor = new PostOrderDiffWalk(left, right, leftSource, rightSource);
Consumer consumer = mock(Consumer.class);
visitor.walk(consumer);
verifyNoMoreInteractions(consumer);
}
Aggregations