Class MongoDocumentStore
- All Implemented Interfaces:
DocumentStore
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe threshold value (in hours) after which the document store should start (if enabled) throttling.static final int -
Constructor Summary
ConstructorsConstructorDescriptionMongoDocumentStore(com.mongodb.client.MongoClient connection, com.mongodb.client.MongoDatabase db, MongoDocumentNodeStoreBuilderBase<?> builder) -
Method Summary
Modifier and TypeMethodDescriptionprotected <T extends Document>
TconvertFromDBObject(@NotNull Collection<T> collection, @Nullable com.mongodb.DBObject n) <T extends Document>
booleancreate(Collection<T> collection, List<UpdateOp> updateOps) Try to create a list of documents.createOrUpdate(Collection<T> collection, List<UpdateOp> updateOps) Try to apply all theUpdateOps with at least MongoDB requests as possible.<T extends Document>
TcreateOrUpdate(Collection<T> collection, UpdateOp update) Atomically checks if the document exists and updates it, otherwise the document is created (aka "upsert"), unless the update operation requires the document to be present (seeUpdateOp.isNew()).longvoiddispose()Dispose this instance.voidfinalize()<T extends Document>
Tfind(Collection<T> collection, String key) Get the document with the givenkey.<T extends Document>
Tfind(Collection<T> collection, String key, int maxCacheAge) Get the document with thekey.findAndUpdate(@NotNull Collection<T> collection, @NotNull List<UpdateOp> updateOps) Try to apply all theUpdateOps with at least MongoDB requests as possible.<T extends Document>
TfindAndUpdate(Collection<T> collection, UpdateOp update) Performs a conditional update (e.g.protected <T extends Document>
TfindUncached(Collection<T> collection, String key, org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore.DocumentReadPreference docReadPref) long<T extends Document>
TgetIfCached(Collection<T> collection, String key) Fetches the cached document.intReturn the size limit for node name based on the document store implementationgetStats()Returns statistics about the underlying storage.Invalidate the document cache.invalidateCache(Iterable<String> keys) Invalidate the document cache but only with entries that match one of the keys provided.<T extends Document>
voidinvalidateCache(Collection<T> collection, String key) Invalidate the document cache for the given key.boolean<T extends Document>
voidprefetch(Collection<T> collection, Iterable<String> keysToPrefetch) optional method indicating the DocumentStore should prefetch, in the most optimal way eg by batching, a bunch of keys as they might soon be needed.query(Collection<T> collection, String fromKey, String toKey, int limit) Get a list of documents where the key is greater than a start value and less than an end value.query(Collection<T> collection, String fromKey, String toKey, String indexedProperty, long startValue, int limit) Get a list of documents where the key is greater than a start value and less than an end value and the given "indexed property" is greater or equals the specified value.query(Collection<T> collection, String fromKey, String toKey, String indexedProperty, long startValue, int limit, List<String> projection) Get a list of documents with only projected fields (as mentioned in projections param) along with "_id" field and where the key is greater than a start value and less than an end value and the given "indexed property" is greater or equals the specified value.queryInternal(Collection<T> collection, String fromKey, String toKey, String indexedProperty, long startValue, int limit, List<String> projection, long maxQueryTime) <T extends Document>
voidremove(Collection<T> collection, String key) Remove a document.<T extends Document>
intremove(Collection<T> collection, String indexedProperty, long startValue, long endValue) Batch remove documents where the given "indexed property" is within the given range (exclusive) -(startValue, endValue).<T extends Document>
voidremove(Collection<T> collection, List<String> keys) Batch remove documents with given keys.<T extends Document>
intremove(Collection<T> collection, Map<String, Long> toRemove) Batch remove documents with given keys and corresponding equal conditions onNodeDocument.MODIFIED_IN_SECSvalues.voidsetReadWriteMode(String readWriteMode) Set the level of guarantee for read and write operations, if supported by this backend.voidReturn theThrottlerfor the underlying store Default is no throttling
-
Field Details
-
DEFAULT_THROTTLING_THRESHOLD
public static final int DEFAULT_THROTTLING_THRESHOLDThe threshold value (in hours) after which the document store should start (if enabled) throttling. Default is 2 hours.For mongo based document store this value is threshold for the oplog replication window.
-
IN_CLAUSE_BATCH_SIZE
public static final int IN_CLAUSE_BATCH_SIZE- See Also:
-
-
Constructor Details
-
MongoDocumentStore
public MongoDocumentStore(com.mongodb.client.MongoClient connection, com.mongodb.client.MongoDatabase db, MongoDocumentNodeStoreBuilderBase<?> builder)
-
-
Method Details
-
getNodeNameLimit
public int getNodeNameLimit()Description copied from interface:DocumentStoreReturn the size limit for node name based on the document store implementation- Specified by:
getNodeNameLimitin interfaceDocumentStore- Returns:
- node name size limit
-
throttler
Return theThrottlerfor the underlying store Default is no throttling- Specified by:
throttlerin interfaceDocumentStore- Returns:
- throttler for document store
-
isReadOnly
public boolean isReadOnly() -
finalize
-
invalidateCache
Description copied from interface:DocumentStoreInvalidate the document cache. Calling this method instructs the implementation to invalidate each document from the cache, which is not up to date with the underlying storage at the time this method is called. A document is considered in the cache ifDocumentStore.getIfCached(Collection, String)returns a non-null value for a key.An implementation is allowed to perform lazy invalidation and only check whether a document is up-to-date when it is accessed after this method is called. However, this also includes a call to
DocumentStore.getIfCached(Collection, String), which must only return the document if it was up-to-date at the time this method was called. Similarly, a call toDocumentStore.find(Collection, String)must guarantee the returned document reflects all the changes done up to wheninvalidateCache()was called.In some implementations this method can be a NOP because documents can only be modified through a single instance of a
DocumentStore.- Specified by:
invalidateCachein interfaceDocumentStore- Returns:
- cache invalidation statistics or
nullif none are available.
-
invalidateCache
Description copied from interface:DocumentStoreInvalidate the document cache but only with entries that match one of the keys provided. SeeDocumentStore.invalidateCache()for the general contract of cache invalidation.- Specified by:
invalidateCachein interfaceDocumentStore- Parameters:
keys- the keys of the documents to invalidate.- Returns:
- cache invalidation statistics or
nullif none are available.
-
invalidateCache
Description copied from interface:DocumentStoreInvalidate the document cache for the given key. SeeDocumentStore.invalidateCache()for the general contract of cache invalidation.- Specified by:
invalidateCachein interfaceDocumentStore- Parameters:
collection- the collectionkey- the key
-
find
Description copied from interface:DocumentStoreGet the document with the givenkey. This is a convenience method and equivalent toDocumentStore.find(Collection, String, int)with amaxCacheAgeofInteger.MAX_VALUE.The returned document is immutable.
- Specified by:
findin interfaceDocumentStore- Type Parameters:
T- the document type- Parameters:
collection- the collectionkey- the key- Returns:
- the document, or null if not found
-
find
Description copied from interface:DocumentStoreGet the document with thekey. The implementation may serve the document from a cache, but the cached document must not be older than the givenmaxCacheAgein milliseconds. An implementation must invalidate a cached document when it detects it is outdated. That is, a subsequent call toDocumentStore.find(Collection, String)must return the newer version of the document.The returned document is immutable.
- Specified by:
findin interfaceDocumentStore- Type Parameters:
T- the document type- Parameters:
collection- the collectionkey- the keymaxCacheAge- the maximum age of the cached document (in ms)- Returns:
- the document, or null if not found
-
findUncached
@Nullable protected <T extends Document> T findUncached(Collection<T> collection, String key, org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore.DocumentReadPreference docReadPref) -
query
@NotNull public <T extends Document> @NotNull List<T> query(Collection<T> collection, String fromKey, String toKey, int limit) Description copied from interface:DocumentStoreGet a list of documents where the key is greater than a start value and less than an end value.The returned documents are sorted by key and are immutable.
- Specified by:
queryin interfaceDocumentStore- Type Parameters:
T- the document type- Parameters:
collection- the collectionfromKey- the start value (excluding)toKey- the end value (excluding)limit- the maximum number of entries to return (starting with the lowest key)- Returns:
- the list (possibly empty)
-
query
@NotNull public <T extends Document> @NotNull List<T> query(Collection<T> collection, String fromKey, String toKey, String indexedProperty, long startValue, int limit) Description copied from interface:DocumentStoreGet a list of documents where the key is greater than a start value and less than an end value and the given "indexed property" is greater or equals the specified value.The indexed property can either be a
Longvalue, in which case numeric comparison applies, or aBooleanvalue, in which case "false" is mapped to "0" and "true" is mapped to "1".The returned documents are sorted by key and are immutable.
- Specified by:
queryin interfaceDocumentStore- Type Parameters:
T- the document type- Parameters:
collection- the collectionfromKey- the start value (excluding)toKey- the end value (excluding)indexedProperty- the name of the indexed property (optional)startValue- the minimum value of the indexed propertylimit- the maximum number of entries to return- Returns:
- the list (possibly empty)
-
query
@NotNull public <T extends Document> @NotNull List<T> query(Collection<T> collection, String fromKey, String toKey, String indexedProperty, long startValue, int limit, List<String> projection) throws DocumentStoreException Description copied from interface:DocumentStoreGet a list of documents with only projected fields (as mentioned in projections param) along with "_id" field and where the key is greater than a start value and less than an end value and the given "indexed property" is greater or equals the specified value.The indexed property can either be a
Longvalue, in which case numeric comparison applies, or aBooleanvalue, in which case "false" is mapped to "0" and "true" is mapped to "1".The returned documents are sorted by key and are immutable.
- Specified by:
queryin interfaceDocumentStore- Type Parameters:
T- the document type- Parameters:
collection- the collectionfromKey- the start value (excluding)toKey- the end value (excluding)indexedProperty- the name of the indexed property (optional)startValue- the minimum value of the indexed propertylimit- the maximum number of entries to returnprojection-Listof projected keys (optional). Keep this empty to fetch all fields on document.- Returns:
- the list (possibly empty)
- Throws:
DocumentStoreException- if the operation failed. E.g. because of an I/O error.
-
queryInternal
-
remove
Description copied from interface:DocumentStoreRemove a document. This method does nothing if there is no document with the given key.In case of a
DocumentStoreException, the document with the given key may or may not have been removed from the store. It is the responsibility of the caller to check whether it still exists. The implementation however ensures that the result of the operation is properly reflected in the document cache. That is, an implementation could simply evict the document with the given key.- Specified by:
removein interfaceDocumentStore- Type Parameters:
T- the document type- Parameters:
collection- the collectionkey- the key
-
remove
Description copied from interface:DocumentStoreBatch remove documents with given keys. Keys for documents that do not exist are simply ignored. If this method fails with an exception, then only some of the documents identified bykeysmay have been removed.In case of a
DocumentStoreException, the documents with the given keys may or may not have been removed from the store. It may also be possible that only some have been removed from the store. It is the responsibility of the caller to check which documents still exist. The implementation however ensures that the result of the operation is properly reflected in the document cache. That is, an implementation could simply evict documents with the given keys from the cache.- Specified by:
removein interfaceDocumentStore- Type Parameters:
T- the document type- Parameters:
collection- the collectionkeys- list of keys
-
remove
Description copied from interface:DocumentStoreBatch remove documents with given keys and corresponding equal conditions onNodeDocument.MODIFIED_IN_SECSvalues. Keys for documents that do not exist are simply ignored. A document is only removed if the corresponding condition is met.In case of a
DocumentStoreException, the documents with the given keys may or may not have been removed from the store. It may also be possible that only some have been removed from the store. It is the responsibility of the caller to check which documents still exist. The implementation however ensures that the result of the operation is properly reflected in the document cache. That is, an implementation could simply evict documents with the given keys from the cache.- Specified by:
removein interfaceDocumentStore- Type Parameters:
T- the document type- Parameters:
collection- the collection.toRemove- the keys of the documents to remove with the corresponding timestamps.- Returns:
- the number of removed documents.
-
remove
public <T extends Document> int remove(Collection<T> collection, String indexedProperty, long startValue, long endValue) throws DocumentStoreException Description copied from interface:DocumentStoreBatch remove documents where the given "indexed property" is within the given range (exclusive) -(startValue, endValue).The indexed property is a
Longvalue and numeric comparison applies.In case of a
DocumentStoreException, the documents with the given keys may or may not have been removed from the store. It may also be possible that only some have been removed from the store. It is the responsibility of the caller to check which documents still exist. The implementation however ensures that the result of the operation is properly reflected in the document cache. That is, an implementation could simply evict documents with the given keys from the cache.- Specified by:
removein interfaceDocumentStore- Type Parameters:
T- the document type- Parameters:
collection- the collection.indexedProperty- the name of the indexed propertystartValue- the minimum value of the indexed property (exclusive)endValue- the maximum value of the indexed property (exclusive)- Returns:
- the number of removed documents.
- Throws:
DocumentStoreException- if the operation failed. E.g. because of an I/O error.
-
findAndUpdate
@NotNull public <T extends Document> @NotNull List<T> findAndUpdate(@NotNull @NotNull Collection<T> collection, @NotNull @NotNull List<UpdateOp> updateOps) Try to apply all theUpdateOps with at least MongoDB requests as possible. The return value is the list of the old documents (before applying changes). The mechanism is as follows:- For each UpdateOp try to read the assigned document from the cache.
Add them to
oldDocs. - Prepare a list of all UpdateOps that doesn't have their documents and
read them in one find() call. Add results to
oldDocs. - Prepare a bulk update. For each remaining UpdateOp add following
operation:
- Find document with the same id and the same mod_count as in the
oldDocs. - Apply changes from the UpdateOps.
- Find document with the same id and the same mod_count as in the
- Execute the bulk update.
oldDocsand restart the process from point 2. It will stop after 3rd iteration.- Specified by:
findAndUpdatein interfaceDocumentStore- Type Parameters:
T- the document type- Parameters:
collection- the collectionupdateOps- the update operation List- Returns:
- the list containing old documents or
nullif the condition is not met or if the document wasn't found. The order in the result list reflects the order in the updateOps parameter - See Also:
- For each UpdateOp try to read the assigned document from the cache.
Add them to
-
createOrUpdate
@Nullable public <T extends Document> T createOrUpdate(Collection<T> collection, UpdateOp update) throws DocumentStoreException Description copied from interface:DocumentStoreAtomically checks if the document exists and updates it, otherwise the document is created (aka "upsert"), unless the update operation requires the document to be present (seeUpdateOp.isNew()). The returned document is immutable.If this method fails with a
DocumentStoreException, then the document may or may not have been created or updated. It is the responsibility of the caller to check the result e.g. by callingDocumentStore.find(Collection, String). The implementation however ensures that the result of the operation is properly reflected in the document cache. That is, an implementation could simply evict documents with the given keys from the cache.- Specified by:
createOrUpdatein interfaceDocumentStore- Type Parameters:
T- the document type- Parameters:
collection- the collectionupdate- the update operation (whereUpdateOp.Conditions are not allowed)- Returns:
- the old document or
nullif it either didn't exist before, or the UpdateOp required the document to be present butUpdateOp.isNew()wasfalse. - Throws:
DocumentStoreException- if the operation failed. E.g. because of an I/O error.
-
createOrUpdate
@Nullable public <T extends Document> @Nullable List<T> createOrUpdate(Collection<T> collection, List<UpdateOp> updateOps) Try to apply all theUpdateOps with at least MongoDB requests as possible. The return value is the list of the old documents (before applying changes). The mechanism is as follows:- For each UpdateOp try to read the assigned document from the cache.
Add them to
oldDocs. - Prepare a list of all UpdateOps that doesn't have their documents and
read them in one find() call. Add results to
oldDocs. - Prepare a bulk update. For each remaining UpdateOp add following
operation:
- Find document with the same id and the same mod_count as in the
oldDocs. - Apply changes from the UpdateOps.
- Find document with the same id and the same mod_count as in the
- Execute the bulk update.
oldDocsand restart the process from point 2. It will stop after 3rd iteration.- Specified by:
createOrUpdatein interfaceDocumentStore- Type Parameters:
T- the document type- Parameters:
collection- the collectionupdateOps- the update operation list- Returns:
- the list containing old documents or
nullvalues if they didn't exist before (see DocumentStore.createOrUpdate(Collection, UpdateOp)), where the order reflects the order in the "updateOps" parameter
- For each UpdateOp try to read the assigned document from the cache.
Add them to
-
findAndUpdate
public <T extends Document> T findAndUpdate(Collection<T> collection, UpdateOp update) throws DocumentStoreException Description copied from interface:DocumentStorePerforms a conditional update (e.g. usingUpdateOp.Condition.Type.EXISTSand only updates the document if the condition istrue. The returned document is immutable.In case of a
DocumentStoreException(e.g. when a communication error occurs) the update may or may not have been applied. In this case it is the responsibility of the caller to check whether the update was applied and take appropriate action. The implementation however ensures that the result of the operation is properly reflected in the document cache. That is, an implementation could simply evict the document related to the given update operation from the cache.- Specified by:
findAndUpdatein interfaceDocumentStore- Type Parameters:
T- the document type- Parameters:
collection- the collectionupdate- the update operation with the condition- Returns:
- the old document or
nullif the condition is not met or if the document wasn't found - Throws:
DocumentStoreException- if the operation failed. E.g. because of an I/O error.- See Also:
-
create
Description copied from interface:DocumentStoreTry to create a list of documents. This method returnstrueiff none of the documents existed before and the create was successful. This method will returnfalseif one of the documents already exists in the store. Some documents may still have been created in the store. An implementation does not have to guarantee an atomic create of all the documents described in theupdateOps. It is the responsibility of the caller to check, which documents were created and take appropriate action. The same is true when this method throwsDocumentStoreException(e.g. when a communication error occurs). In this case only some documents may have been created.- Specified by:
createin interfaceDocumentStore- Type Parameters:
T- the document type- Parameters:
collection- the collectionupdateOps- the list of documents to add (whereUpdateOp.Conditions are not allowed)- Returns:
- true if this worked (if none of the documents already existed)
-
prefetch
public <T extends Document> void prefetch(Collection<T> collection, Iterable<String> keysToPrefetch) Description copied from interface:DocumentStoreoptional method indicating the DocumentStore should prefetch, in the most optimal way eg by batching, a bunch of keys as they might soon be needed.- Specified by:
prefetchin interfaceDocumentStore
-
convertFromDBObject
@Nullable protected <T extends Document> T convertFromDBObject(@NotNull @NotNull Collection<T> collection, @Nullable @Nullable com.mongodb.DBObject n) -
dispose
public void dispose()Description copied from interface:DocumentStoreDispose this instance.- Specified by:
disposein interfaceDocumentStore
-
getCacheStats
- Specified by:
getCacheStatsin interfaceDocumentStore- Returns:
- status information about the cache
-
getMetadata
- Specified by:
getMetadatain interfaceDocumentStore- Returns:
- description of the underlying storage.
-
getStats
Description copied from interface:DocumentStoreReturns statistics about the underlying storage. The information and keys returned by this method are implementation specific, may change between releases or may even depend on deployment aspects. E.g. depending on access rights, the method may return more or less information from the underlying store. This method should only be used for informational or debug purposes.- Specified by:
getStatsin interfaceDocumentStore- Returns:
- statistics about this document store.
-
getIfCached
Description copied from interface:DocumentStoreFetches the cached document. If the document is not present in the cachenullwill be returned. This method is consistent with other find methods that may return cached documents and will returnnulleven when the implementation has a negative cache for documents that do not exist. This method will never returnNodeDocument.NULL.- Specified by:
getIfCachedin interfaceDocumentStore- Type Parameters:
T- the document type- Parameters:
collection- the collectionkey- the key- Returns:
- cached document if present. Otherwise
null.
-
setReadWriteMode
Description copied from interface:DocumentStoreSet the level of guarantee for read and write operations, if supported by this backend.- Specified by:
setReadWriteModein interfaceDocumentStore- Parameters:
readWriteMode- the read/write mode
-
setStatsCollector
-
determineServerTimeDifferenceMillis
public long determineServerTimeDifferenceMillis()- Specified by:
determineServerTimeDifferenceMillisin interfaceDocumentStore- Returns:
- the estimated time difference in milliseconds between the local instance and the (typically common, shared) document server system. The value can be zero if the times are estimated to be equal, positive when the local instance is ahead of the remote server and negative when the local instance is behind the remote server. An invocation is not cached and typically requires a round-trip to the server (but that is not a requirement).
-
getAmountOfMongoWriteExceptions
public long getAmountOfMongoWriteExceptions()
-