Class MongoDBTransientStore
- java.lang.Object
-
- org.nuxeo.ecm.core.mongodb.transientstore.MongoDBTransientStore
-
- All Implemented Interfaces:
TransientStore
,TransientStoreProvider
public class MongoDBTransientStore extends Object implements TransientStoreProvider
Transient Store optimized for MongoDB, using a blob provider for binaries. It can replace the KeyValueBlobTransientStore implementation, it uses the same configuration.A MongoDB collection is created per store, the name is prefixed by "transient.". If not provided the blob provider is created using a default configuration with "transient_" prefix that gives the required transient property.
The storage format is the following:
{ "_id" : $KEY, "completed" : false, "ttl" : ISODate("2022-11-17T12:10:16.568Z"), "params" : { "chunked" : "false" } }, "blobs" : [ { "key" : ..., "mimetype" : ..., "encoding" : ..., "filename" : ..., "length" : NumberLong(131984), "digest" : ... } ], "blobSize" : NumberLong(131984), "blobCount" : 1 }
The total size of the storage is computed with an aggregation on the blobSize property.- Since:
- 2021.30
-
-
Field Summary
Fields Modifier and Type Field Description protected long
absoluteMaxSize
static String
BLOB_COUNT_KEY
static String
BLOB_SIZE_KEY
protected String
blobProviderId
static String
BLOBS_KEY
protected com.mongodb.client.MongoCollection<org.bson.Document>
coll
static String
COLLECTION_NAME_PROPERTY
static String
COMPLETED_KEY
protected TransientStoreConfig
config
static String
CONFIG_BLOB_PROVIDER
static String
CONFIG_DEFAULT_BLOB_PROVIDER
static String
CONFIG_DEFAULT_BLOB_PROVIDER_DEFAULT
static String
DEFAULT_COLLECTION_NAME
protected String
defaultBlobProviderId
static String
DIGEST
static String
ENCODING
static String
FILENAME
protected int
firstLevelTTL
static String
ID_KEY
static String
KEY
static String
LENGTH
static String
MIMETYPE
static Double
ONE
protected int
secondLevelTTL
protected long
targetMaxSize
static String
TRANSIENT_DATABASE_ID
static String
TTL_KEY
protected static long
WARN_DURATION_MS_THRESHOLD
-
Constructor Summary
Constructors Constructor Description MongoDBTransientStore()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.bson.Document
createEntry(String key)
protected Serializable
deSerializeValue(Object value)
void
doGC()
Runs garbage collecting to delete the file system resources that are associated with entries that were removed.boolean
exists(String key)
Returnstrue
if an entry exists with the givenkey
.BlobProvider
getBlobProvider()
List<Blob>
getBlobs(String key)
Gets the blobs associated with the entry with the givenkey
.protected com.mongodb.client.MongoCollection<org.bson.Document>
getColl()
Serializable
getParameter(String key, String parameter)
Gets the value ofparameter
in the entry with the givenkey
.Map<String,Serializable>
getParameters(String key)
Gets values of the parameters in the entry with the givenkey
.long
getSize(String key)
Returns the size of the blobs associated with the entry with the givenkey
or-1
if entry does not exist.long
getStorageSize()
Returns the size (in bytes) of the disk storage used for blobs.void
init(TransientStoreConfig config)
Initializes the store from the givenconfig
.boolean
isCompleted(String key)
Returnstrue
if the entry with the givenkey
is ready.Stream<String>
keyStream()
Returns aStream
of keys for all entries.void
putBlobs(String key, List<Blob> blobs)
Associates the givenblobs
with the entry with the givenkey
.void
putParameter(String key, String parameter, Serializable value)
Setsparameter
tovalue
in the entry with the givenkey
.void
putParameters(String key, Map<String,Serializable> parameters)
Putsparameters
in the entry with the givenkey
.void
release(String key)
Informs the store that the entry with the givenkey
can be released if TTL or GC parameters require to do some cleanup.void
remove(String key)
Removes entry with the givenkey
.void
removeAll()
Removes all entries from the store.protected Object
serializeValue(Serializable value)
void
setCompleted(String key, boolean completed)
Marks the entry with the givenkey
as ready.protected void
setTTL(org.bson.Document entry, int ttlSeconds)
void
shutdown()
Shuts down the store.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.nuxeo.ecm.core.transientstore.api.TransientStoreProvider
getStorageSizeMB, keySet
-
-
-
-
Field Detail
-
COLLECTION_NAME_PROPERTY
public static final String COLLECTION_NAME_PROPERTY
- See Also:
- Constant Field Values
-
DEFAULT_COLLECTION_NAME
public static final String DEFAULT_COLLECTION_NAME
- See Also:
- Constant Field Values
-
TRANSIENT_DATABASE_ID
public static final String TRANSIENT_DATABASE_ID
- See Also:
- Constant Field Values
-
CONFIG_BLOB_PROVIDER
public static final String CONFIG_BLOB_PROVIDER
- See Also:
- Constant Field Values
-
CONFIG_DEFAULT_BLOB_PROVIDER
public static final String CONFIG_DEFAULT_BLOB_PROVIDER
- See Also:
- Constant Field Values
-
CONFIG_DEFAULT_BLOB_PROVIDER_DEFAULT
public static final String CONFIG_DEFAULT_BLOB_PROVIDER_DEFAULT
- See Also:
- Constant Field Values
-
KEY
public static final String KEY
- See Also:
- Constant Field Values
-
MIMETYPE
public static final String MIMETYPE
- See Also:
- Constant Field Values
-
ENCODING
public static final String ENCODING
- See Also:
- Constant Field Values
-
FILENAME
public static final String FILENAME
- See Also:
- Constant Field Values
-
LENGTH
public static final String LENGTH
- See Also:
- Constant Field Values
-
DIGEST
public static final String DIGEST
- See Also:
- Constant Field Values
-
ID_KEY
public static final String ID_KEY
- See Also:
- Constant Field Values
-
TTL_KEY
public static final String TTL_KEY
- See Also:
- Constant Field Values
-
COMPLETED_KEY
public static final String COMPLETED_KEY
- See Also:
- Constant Field Values
-
BLOBS_KEY
public static final String BLOBS_KEY
- See Also:
- Constant Field Values
-
BLOB_SIZE_KEY
public static final String BLOB_SIZE_KEY
- See Also:
- Constant Field Values
-
BLOB_COUNT_KEY
public static final String BLOB_COUNT_KEY
- See Also:
- Constant Field Values
-
ONE
public static final Double ONE
-
WARN_DURATION_MS_THRESHOLD
protected static final long WARN_DURATION_MS_THRESHOLD
- See Also:
- Constant Field Values
-
coll
protected com.mongodb.client.MongoCollection<org.bson.Document> coll
-
config
protected TransientStoreConfig config
-
firstLevelTTL
protected int firstLevelTTL
-
secondLevelTTL
protected int secondLevelTTL
-
blobProviderId
protected String blobProviderId
-
defaultBlobProviderId
protected String defaultBlobProviderId
-
absoluteMaxSize
protected long absoluteMaxSize
-
targetMaxSize
protected long targetMaxSize
-
-
Method Detail
-
init
public void init(TransientStoreConfig config)
Description copied from interface:TransientStoreProvider
Initializes the store from the givenconfig
.- Specified by:
init
in interfaceTransientStoreProvider
-
getColl
protected com.mongodb.client.MongoCollection<org.bson.Document> getColl()
-
shutdown
public void shutdown()
Description copied from interface:TransientStoreProvider
Shuts down the store.- Specified by:
shutdown
in interfaceTransientStoreProvider
-
keyStream
public Stream<String> keyStream()
Description copied from interface:TransientStoreProvider
Returns aStream
of keys for all entries.- Specified by:
keyStream
in interfaceTransientStoreProvider
-
getStorageSize
public long getStorageSize()
Description copied from interface:TransientStoreProvider
Returns the size (in bytes) of the disk storage used for blobs.- Specified by:
getStorageSize
in interfaceTransientStoreProvider
- Returns:
- the number of bytes used by stored blobs
-
doGC
public void doGC()
Description copied from interface:TransientStoreProvider
Runs garbage collecting to delete the file system resources that are associated with entries that were removed.- Specified by:
doGC
in interfaceTransientStoreProvider
-
removeAll
public void removeAll()
Description copied from interface:TransientStoreProvider
Removes all entries from the store.- Specified by:
removeAll
in interfaceTransientStoreProvider
-
exists
public boolean exists(String key)
Description copied from interface:TransientStore
Returnstrue
if an entry exists with the givenkey
.- Specified by:
exists
in interfaceTransientStore
-
putParameter
public void putParameter(String key, String parameter, Serializable value)
Description copied from interface:TransientStore
Setsparameter
tovalue
in the entry with the givenkey
.If entry does not exist a new entry is created. If
parameter
already exists in the entry it is overwritten.- Specified by:
putParameter
in interfaceTransientStore
-
getParameter
public Serializable getParameter(String key, String parameter)
Description copied from interface:TransientStore
Gets the value ofparameter
in the entry with the givenkey
.Returns
null
if entry or parameter does not exist.- Specified by:
getParameter
in interfaceTransientStore
-
deSerializeValue
protected Serializable deSerializeValue(Object value)
-
serializeValue
protected Object serializeValue(Serializable value)
-
putParameters
public void putParameters(String key, Map<String,Serializable> parameters)
Description copied from interface:TransientStore
Putsparameters
in the entry with the givenkey
. Overwrites any existing parameter in the entry.If entry does not exist a new entry is created.
- Specified by:
putParameters
in interfaceTransientStore
-
getParameters
public Map<String,Serializable> getParameters(String key)
Description copied from interface:TransientStore
Gets values of the parameters in the entry with the givenkey
.Returns
null
if entry does not exist.- Specified by:
getParameters
in interfaceTransientStore
-
putBlobs
public void putBlobs(String key, List<Blob> blobs)
Description copied from interface:TransientStore
Associates the givenblobs
with the entry with the givenkey
.If entry does not exist a new entry is created.
- Specified by:
putBlobs
in interfaceTransientStore
-
getBlobs
public List<Blob> getBlobs(String key)
Description copied from interface:TransientStore
Gets the blobs associated with the entry with the givenkey
.Returns
null
if entry does not exist.- Specified by:
getBlobs
in interfaceTransientStore
-
getSize
public long getSize(String key)
Description copied from interface:TransientStore
Returns the size of the blobs associated with the entry with the givenkey
or-1
if entry does not exist.- Specified by:
getSize
in interfaceTransientStore
-
isCompleted
public boolean isCompleted(String key)
Description copied from interface:TransientStore
Returnstrue
if the entry with the givenkey
is ready.- Specified by:
isCompleted
in interfaceTransientStore
-
setCompleted
public void setCompleted(String key, boolean completed)
Description copied from interface:TransientStore
Marks the entry with the givenkey
as ready.If entry does not exist a new entry is created.
- Specified by:
setCompleted
in interfaceTransientStore
-
setTTL
protected void setTTL(org.bson.Document entry, int ttlSeconds)
-
createEntry
protected org.bson.Document createEntry(String key)
-
remove
public void remove(String key)
Description copied from interface:TransientStore
Removes entry with the givenkey
.Has no effect if entry does not exist.
- Specified by:
remove
in interfaceTransientStore
-
release
public void release(String key)
Description copied from interface:TransientStore
Informs the store that the entry with the givenkey
can be released if TTL or GC parameters require to do some cleanup.Has no effect if entry does not exist.
- Specified by:
release
in interfaceTransientStore
-
getBlobProvider
public BlobProvider getBlobProvider()
-
-