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