Search in sources :

Example 1 with MODIFIED_IN_SECS

use of org.apache.jackrabbit.oak.plugins.document.NodeDocument.MODIFIED_IN_SECS in project jackrabbit-oak by apache.

the class MongoDocumentStore method getModStamps.

/**
 * Returns the {@link Document#MOD_COUNT} and
 * {@link NodeDocument#MODIFIED_IN_SECS} values of the documents with the
 * given {@code keys}. The returned map will only contain entries for
 * existing documents. The default value is -1 if the document does not have
 * a modCount field. The same applies to the modified field.
 *
 * @param keys the keys of the documents.
 * @return map with key to modification stamp mapping.
 * @throws MongoException if the call fails
 */
@Nonnull
private Map<String, ModificationStamp> getModStamps(Iterable<String> keys) throws MongoException {
    // Fetch only the modCount and id
    final BasicDBObject fields = new BasicDBObject(Document.ID, 1);
    fields.put(Document.MOD_COUNT, 1);
    fields.put(NodeDocument.MODIFIED_IN_SECS, 1);
    Map<String, ModificationStamp> modCounts = Maps.newHashMap();
    nodes.withReadPreference(ReadPreference.primary()).find(Filters.in(Document.ID, keys)).projection(fields).forEach((Block<BasicDBObject>) obj -> {
        String id = (String) obj.get(Document.ID);
        Long modCount = Utils.asLong((Number) obj.get(Document.MOD_COUNT));
        if (modCount == null) {
            modCount = -1L;
        }
        Long modified = Utils.asLong((Number) obj.get(NodeDocument.MODIFIED_IN_SECS));
        if (modified == null) {
            modified = -1L;
        }
        modCounts.put(id, new ModificationStamp(modCount, modified));
    });
    return modCounts;
}
Also used : Arrays(java.util.Arrays) CacheStats(org.apache.jackrabbit.oak.cache.CacheStats) MongoDatabase(com.mongodb.client.MongoDatabase) Predicates.in(com.google.common.base.Predicates.in) Sets.difference(com.google.common.collect.Sets.difference) Key(org.apache.jackrabbit.oak.plugins.document.UpdateOp.Key) Predicates.not(com.google.common.base.Predicates.not) UpdateResult(com.mongodb.client.result.UpdateResult) Map(java.util.Map) UpdateOptions(com.mongodb.client.model.UpdateOptions) Revision(org.apache.jackrabbit.oak.plugins.document.Revision) CacheInvalidationStats(org.apache.jackrabbit.oak.plugins.document.cache.CacheInvalidationStats) Set(java.util.Set) Collection(org.apache.jackrabbit.oak.plugins.document.Collection) BulkWriteUpsert(com.mongodb.bulk.BulkWriteUpsert) Clock(org.apache.jackrabbit.oak.stats.Clock) CacheChangesTracker(org.apache.jackrabbit.oak.plugins.document.cache.CacheChangesTracker) Iterables.filter(com.google.common.collect.Iterables.filter) Iterables(com.google.common.collect.Iterables) MongoClientURI(com.mongodb.MongoClientURI) MongoCollection(com.mongodb.client.MongoCollection) BulkWriteOptions(com.mongodb.client.model.BulkWriteOptions) FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) Callable(java.util.concurrent.Callable) SD_MAX_REV_TIME_IN_SECS(org.apache.jackrabbit.oak.plugins.document.NodeDocument.SD_MAX_REV_TIME_IN_SECS) ArrayList(java.util.ArrayList) UpdateUtils(org.apache.jackrabbit.oak.plugins.document.UpdateUtils) LinkedHashMap(java.util.LinkedHashMap) Bson(org.bson.conversions.Bson) Filters(com.mongodb.client.model.Filters) Lists(com.google.common.collect.Lists) SD_TYPE(org.apache.jackrabbit.oak.plugins.document.NodeDocument.SD_TYPE) ReplicaSetInfo(org.apache.jackrabbit.oak.plugins.document.mongo.replica.ReplicaSetInfo) Nullable(javax.annotation.Nullable) DELETED_ONCE(org.apache.jackrabbit.oak.plugins.document.NodeDocument.DELETED_ONCE) Maps.filterKeys(com.google.common.collect.Maps.filterKeys) LocalChanges(org.apache.jackrabbit.oak.plugins.document.mongo.replica.LocalChanges) UpdateOneModel(com.mongodb.client.model.UpdateOneModel) BasicDBObject(com.mongodb.BasicDBObject) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) DocumentStoreStatsCollector(org.apache.jackrabbit.oak.plugins.document.DocumentStoreStatsCollector) Lock(java.util.concurrent.locks.Lock) TreeMap(java.util.TreeMap) StripedNodeDocumentLocks(org.apache.jackrabbit.oak.plugins.document.locks.StripedNodeDocumentLocks) RevisionListener(org.apache.jackrabbit.oak.plugins.document.RevisionListener) Condition.newEqualsCondition(org.apache.jackrabbit.oak.plugins.document.UpdateOp.Condition.newEqualsCondition) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) MongoBulkWriteException(com.mongodb.MongoBulkWriteException) WriteModel(com.mongodb.client.model.WriteModel) Utils(org.apache.jackrabbit.oak.plugins.document.util.Utils) MongoUtils.createPartialIndex(org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.createPartialIndex) DBObject(com.mongodb.DBObject) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) MongoUtils.createIndex(org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.createIndex) Function(com.google.common.base.Function) ImmutableMap(com.google.common.collect.ImmutableMap) MongoException(com.mongodb.MongoException) ReturnDocument(com.mongodb.client.model.ReturnDocument) PerfLogger(org.apache.jackrabbit.oak.commons.PerfLogger) NodeDocumentLocks(org.apache.jackrabbit.oak.plugins.document.locks.NodeDocumentLocks) List(java.util.List) DocumentStoreException.asDocumentStoreException(org.apache.jackrabbit.oak.plugins.document.DocumentStoreException.asDocumentStoreException) Block(com.mongodb.Block) JournalEntry(org.apache.jackrabbit.oak.plugins.document.JournalEntry) FindIterable(com.mongodb.client.FindIterable) MongoUtils.hasIndex(org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.hasIndex) Entry(java.util.Map.Entry) NodeDocumentCache(org.apache.jackrabbit.oak.plugins.document.cache.NodeDocumentCache) Condition(org.apache.jackrabbit.oak.plugins.document.UpdateOp.Condition) ModificationStamp(org.apache.jackrabbit.oak.plugins.document.cache.ModificationStamp) ReadPreference(com.mongodb.ReadPreference) DocumentStoreException(org.apache.jackrabbit.oak.plugins.document.DocumentStoreException) Stopwatch(com.google.common.base.Stopwatch) MongoUtils.getDocumentStoreExceptionTypeFor(org.apache.jackrabbit.oak.plugins.document.mongo.MongoUtils.getDocumentStoreExceptionTypeFor) UpdateOp(org.apache.jackrabbit.oak.plugins.document.UpdateOp) HashMap(java.util.HashMap) Iterators(com.google.common.collect.Iterators) MODIFIED_IN_SECS(org.apache.jackrabbit.oak.plugins.document.NodeDocument.MODIFIED_IN_SECS) HashSet(java.util.HashSet) BulkWriteError(com.mongodb.bulk.BulkWriteError) ImmutableList(com.google.common.collect.ImmutableList) MongoCursor(com.mongodb.client.MongoCursor) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument) Nonnull(javax.annotation.Nonnull) DocumentStore(org.apache.jackrabbit.oak.plugins.document.DocumentStore) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Maps(com.google.common.collect.Maps) CacheValue(org.apache.jackrabbit.oak.cache.CacheValue) TimeUnit(java.util.concurrent.TimeUnit) StableRevisionComparator(org.apache.jackrabbit.oak.plugins.document.StableRevisionComparator) BulkWriteResult(com.mongodb.bulk.BulkWriteResult) MongoClient(com.mongodb.MongoClient) Document(org.apache.jackrabbit.oak.plugins.document.Document) Operation(org.apache.jackrabbit.oak.plugins.document.UpdateOp.Operation) WriteConcern(com.mongodb.WriteConcern) Collections(java.util.Collections) CheckForNull(javax.annotation.CheckForNull) BasicDBObject(com.mongodb.BasicDBObject) ModificationStamp(org.apache.jackrabbit.oak.plugins.document.cache.ModificationStamp) Nonnull(javax.annotation.Nonnull)

Example 2 with MODIFIED_IN_SECS

use of org.apache.jackrabbit.oak.plugins.document.NodeDocument.MODIFIED_IN_SECS 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)));
}
Also used : ReadPreference(com.mongodb.ReadPreference) MongoCollection(com.mongodb.client.MongoCollection) Iterables.transform(com.google.common.collect.Iterables.transform) LoggerFactory(org.slf4j.LoggerFactory) SD_MAX_REV_TIME_IN_SECS(org.apache.jackrabbit.oak.plugins.document.NodeDocument.SD_MAX_REV_TIME_IN_SECS) MODIFIED_IN_SECS(org.apache.jackrabbit.oak.plugins.document.NodeDocument.MODIFIED_IN_SECS) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Filters(com.mongodb.client.model.Filters) Bson(org.bson.conversions.Bson) Utils(org.apache.jackrabbit.oak.plugins.document.util.Utils) Lists(com.google.common.collect.Lists) CloseableIterable(org.apache.jackrabbit.oak.plugins.document.util.CloseableIterable) StandardSystemProperty(com.google.common.base.StandardSystemProperty) SD_TYPE(org.apache.jackrabbit.oak.plugins.document.NodeDocument.SD_TYPE) NodeDocument(org.apache.jackrabbit.oak.plugins.document.NodeDocument) SplitDocType(org.apache.jackrabbit.oak.plugins.document.NodeDocument.SplitDocType) RevisionVector(org.apache.jackrabbit.oak.plugins.document.RevisionVector) Nonnull(javax.annotation.Nonnull) PATH(org.apache.jackrabbit.oak.plugins.document.NodeDocument.PATH) Revision(org.apache.jackrabbit.oak.plugins.document.Revision) NODES(org.apache.jackrabbit.oak.plugins.document.Collection.NODES) DELETED_ONCE(org.apache.jackrabbit.oak.plugins.document.NodeDocument.DELETED_ONCE) Function(com.google.common.base.Function) SplitDocumentCleanUp(org.apache.jackrabbit.oak.plugins.document.SplitDocumentCleanUp) Logger(org.slf4j.Logger) NodeDocument.getModifiedInSecs(org.apache.jackrabbit.oak.plugins.document.NodeDocument.getModifiedInSecs) BasicDBObject(com.mongodb.BasicDBObject) Set(java.util.Set) VersionGCSupport(org.apache.jackrabbit.oak.plugins.document.VersionGCSupport) VersionGCStats(org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Block(com.mongodb.Block) Clock(org.apache.jackrabbit.oak.stats.Clock) Predicate(com.google.common.base.Predicate) FindIterable(com.mongodb.client.FindIterable) Document(org.apache.jackrabbit.oak.plugins.document.Document) ID(org.apache.jackrabbit.oak.plugins.document.Document.ID) Pattern(java.util.regex.Pattern) Iterables.filter(com.google.common.collect.Iterables.filter) Joiner(com.google.common.base.Joiner) DEFAULT_NO_BRANCH(org.apache.jackrabbit.oak.plugins.document.NodeDocument.SplitDocType.DEFAULT_NO_BRANCH) BasicDBObject(com.mongodb.BasicDBObject) Bson(org.bson.conversions.Bson)

Aggregations

Function (com.google.common.base.Function)2 Iterables.filter (com.google.common.collect.Iterables.filter)2 Lists (com.google.common.collect.Lists)2 BasicDBObject (com.mongodb.BasicDBObject)2 Block (com.mongodb.Block)2 ReadPreference (com.mongodb.ReadPreference)2 FindIterable (com.mongodb.client.FindIterable)2 MongoCollection (com.mongodb.client.MongoCollection)2 Filters (com.mongodb.client.model.Filters)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Set (java.util.Set)2 TimeUnit (java.util.concurrent.TimeUnit)2 Nonnull (javax.annotation.Nonnull)2 Document (org.apache.jackrabbit.oak.plugins.document.Document)2 NodeDocument (org.apache.jackrabbit.oak.plugins.document.NodeDocument)2 DELETED_ONCE (org.apache.jackrabbit.oak.plugins.document.NodeDocument.DELETED_ONCE)2 MODIFIED_IN_SECS (org.apache.jackrabbit.oak.plugins.document.NodeDocument.MODIFIED_IN_SECS)2 SD_MAX_REV_TIME_IN_SECS (org.apache.jackrabbit.oak.plugins.document.NodeDocument.SD_MAX_REV_TIME_IN_SECS)2 SD_TYPE (org.apache.jackrabbit.oak.plugins.document.NodeDocument.SD_TYPE)2