use of org.apache.jackrabbit.oak.plugins.document.util.CloseableIterable in project jackrabbit-oak by apache.
the class MongoDocumentTraverser method getAllDocuments.
public <T extends Document> CloseableIterable<T> getAllDocuments(Collection<T> collection, Predicate<String> filter) {
if (!disableReadOnlyCheck) {
checkState(mongoStore.isReadOnly(), "Traverser can only be used with readOnly store");
}
MongoCollection<BasicDBObject> dbCollection = mongoStore.getDBCollection(collection);
// TODO This may lead to reads being routed to secondary depending on MongoURI
// So caller must ensure that its safe to read from secondary
Iterable<BasicDBObject> cursor = dbCollection.withReadPreference(mongoStore.getConfiguredReadPreference(collection)).find();
CloseableIterable<BasicDBObject> closeableCursor = CloseableIterable.wrap(cursor);
cursor = closeableCursor;
@SuppressWarnings("Guava") Iterable<T> result = FluentIterable.from(cursor).filter(o -> filter.test((String) o.get(Document.ID))).transform(o -> {
T doc = mongoStore.convertFromDBObject(collection, o);
// TODO Review the cache update approach where tracker has to track *all* docs
if (collection == Collection.NODES) {
NodeDocument nodeDoc = (NodeDocument) doc;
getNodeDocCache().put(nodeDoc);
}
return doc;
});
return CloseableIterable.wrap(result, closeableCursor);
}
use of org.apache.jackrabbit.oak.plugins.document.util.CloseableIterable in project jackrabbit-oak by apache.
the class MongoMissingLastRevSeeker method getCandidates.
@Override
@Nonnull
public CloseableIterable<NodeDocument> getCandidates(final long startTime) {
Bson query = Filters.gte(NodeDocument.MODIFIED_IN_SECS, NodeDocument.getModifiedInSecs(startTime));
Bson sortFields = new BasicDBObject(NodeDocument.MODIFIED_IN_SECS, 1);
FindIterable<BasicDBObject> cursor = getNodeCollection().withReadPreference(ReadPreference.primary()).find(query).sort(sortFields);
return CloseableIterable.wrap(transform(cursor, input -> store.convertFromDBObject(NODES, input)));
}
use of org.apache.jackrabbit.oak.plugins.document.util.CloseableIterable in project jackrabbit-oak by apache.
the class MongoVersionGCSupport method getPossiblyDeletedDocs.
@Override
public CloseableIterable<NodeDocument> getPossiblyDeletedDocs(final long fromModified, final long toModified) {
// _deletedOnce == true && _modified >= fromModified && _modified < toModified
Bson query = Filters.and(Filters.eq(DELETED_ONCE, true), Filters.gte(MODIFIED_IN_SECS, getModifiedInSecs(fromModified)), Filters.lt(MODIFIED_IN_SECS, getModifiedInSecs(toModified)));
FindIterable<BasicDBObject> cursor = getNodeCollection().withReadPreference(ReadPreference.secondaryPreferred()).find(query).batchSize(batchSize);
return CloseableIterable.wrap(transform(cursor, input -> store.convertFromDBObject(NODES, input)));
}
Aggregations