Class MongoBlobStore
- java.lang.Object
-
- org.apache.jackrabbit.oak.spi.blob.AbstractBlobStore
-
- org.apache.jackrabbit.oak.plugins.blob.CachingBlobStore
-
- org.apache.jackrabbit.oak.plugins.document.mongo.MongoBlobStore
-
- All Implemented Interfaces:
AutoCloseable
,Cache.Backend<AbstractBlobStore.BlockId,AbstractBlobStore.Data>
,BlobStore
,GarbageCollectableBlobStore
public class MongoBlobStore extends CachingBlobStore
Implementation of blob store for the MongoDB extending fromCachingBlobStore
. It saves blobs into a separate collection in MongoDB (not using GridFS) and it supports basic garbage collection. FIXME: -Do we need to create commands for retry etc.? -Not sure if this is going to work for multiple MKs talking to same MongoDB?
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.jackrabbit.oak.spi.blob.AbstractBlobStore
AbstractBlobStore.BlockId, AbstractBlobStore.Data
-
-
Field Summary
Fields Modifier and Type Field Description static String
COLLECTION_BLOBS
-
Fields inherited from class org.apache.jackrabbit.oak.plugins.blob.CachingBlobStore
blobCacheSize, cache, DEFAULT_CACHE_SIZE, MEM_CACHE_NAME
-
Fields inherited from class org.apache.jackrabbit.oak.spi.blob.AbstractBlobStore
BLOCK_SIZE_LIMIT, HASH_ALGORITHM, inUse, TYPE_DATA, TYPE_HASH
-
-
Constructor Summary
Constructors Constructor Description MongoBlobStore(@NotNull com.mongodb.client.MongoDatabase db, long cacheSize, @Nullable DocumentNodeStoreBuilder<?> builder)
Constructs a newMongoBlobStore
MongoBlobStore(com.mongodb.client.MongoDatabase db)
Constructs a newMongoBlobStore
MongoBlobStore(com.mongodb.client.MongoDatabase db, long cacheSize)
Constructs a newMongoBlobStore
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
countDeleteChunks(List<String> chunkIds, long maxLastModifiedTime)
Deletes the blobs with the given ids.Iterator<String>
getAllChunkIds(long maxLastModifiedTime)
Gets all the identifiers.protected boolean
isMarkEnabled()
protected void
mark(AbstractBlobStore.BlockId blockId)
protected byte[]
readBlockFromBackend(AbstractBlobStore.BlockId blockId)
Load the block from the storage backend.void
startMark()
Start the mark phase.protected void
storeBlock(byte[] digest, int level, byte[] data)
Store a block of data.int
sweep()
Remove all unused blocks.-
Methods inherited from class org.apache.jackrabbit.oak.plugins.blob.CachingBlobStore
clearCache, getBlobCacheSize, getCacheStats
-
Methods inherited from class org.apache.jackrabbit.oak.spi.blob.AbstractBlobStore
clearInUse, close, deleteChunks, getBlobId, getBlobLength, getBlockSize, getBlockSizeMin, getInputStream, getOrCreateReferenceKey, getReference, getStatsCollector, load, mark, markInUse, readBlob, resolveChunks, setBlockSize, setBlockSizeMin, setReferenceKey, setReferenceKeyEncoded, setReferenceKeyPlainText, setStatsCollector, usesBlobId, writeBlob, writeBlob, writeBlob
-
-
-
-
Field Detail
-
COLLECTION_BLOBS
public static final String COLLECTION_BLOBS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MongoBlobStore
public MongoBlobStore(com.mongodb.client.MongoDatabase db)
Constructs a newMongoBlobStore
- Parameters:
db
- the database
-
MongoBlobStore
public MongoBlobStore(com.mongodb.client.MongoDatabase db, long cacheSize)
Constructs a newMongoBlobStore
- Parameters:
db
- the databasecacheSize
- the cache size
-
MongoBlobStore
public MongoBlobStore(@NotNull @NotNull com.mongodb.client.MongoDatabase db, long cacheSize, @Nullable @Nullable DocumentNodeStoreBuilder<?> builder)
Constructs a newMongoBlobStore
- Parameters:
db
- the databasecacheSize
- the cache sizebuilder
-DocumentNodeStoreBuilder
, supplying further options
-
-
Method Detail
-
storeBlock
protected void storeBlock(byte[] digest, int level, byte[] data) throws IOException
Description copied from class:AbstractBlobStore
Store a block of data.- Specified by:
storeBlock
in classAbstractBlobStore
- Parameters:
digest
- the content hash (32 bytes)level
- the indirection level (0 is for user data, 1 is a list of digests that point to user data, 2 is a list of digests that point to digests, and so on). This parameter is for informational use only, and it is not required to store it unless that's easy to achievedata
- the data to be stored (the number of bytes is at most the block size)- Throws:
IOException
-
readBlockFromBackend
protected byte[] readBlockFromBackend(AbstractBlobStore.BlockId blockId) throws Exception
Description copied from class:AbstractBlobStore
Load the block from the storage backend. Returns null if the block was not found.- Specified by:
readBlockFromBackend
in classAbstractBlobStore
- Parameters:
blockId
- the block id- Returns:
- the block data, or null
- Throws:
Exception
-
startMark
public void startMark() throws IOException
Description copied from interface:GarbageCollectableBlobStore
Start the mark phase.- Specified by:
startMark
in interfaceGarbageCollectableBlobStore
- Specified by:
startMark
in classAbstractBlobStore
- Throws:
IOException
-
isMarkEnabled
protected boolean isMarkEnabled()
- Specified by:
isMarkEnabled
in classAbstractBlobStore
-
mark
protected void mark(AbstractBlobStore.BlockId blockId) throws Exception
- Specified by:
mark
in classAbstractBlobStore
- Throws:
Exception
-
sweep
public int sweep() throws IOException
Description copied from interface:GarbageCollectableBlobStore
Remove all unused blocks.- Specified by:
sweep
in interfaceGarbageCollectableBlobStore
- Specified by:
sweep
in classAbstractBlobStore
- Returns:
- the number of removed blocks
- Throws:
IOException
-
countDeleteChunks
public long countDeleteChunks(List<String> chunkIds, long maxLastModifiedTime) throws Exception
Description copied from interface:GarbageCollectableBlobStore
Deletes the blobs with the given ids.- Parameters:
chunkIds
- the chunk idsmaxLastModifiedTime
- the max last modified time to consider for retrieval, with the special value '0' meaning no filtering by time- Returns:
- long the count of successful deletions
- Throws:
Exception
- the exception
-
getAllChunkIds
public Iterator<String> getAllChunkIds(long maxLastModifiedTime) throws Exception
Description copied from interface:GarbageCollectableBlobStore
Gets all the identifiers.- Parameters:
maxLastModifiedTime
- the max last modified time to consider for retrieval, with the special value '0' meaning no filtering by time- Returns:
- the identifiers
- Throws:
Exception
- the exception
-
-