Class CachingBlobStore
- java.lang.Object
-
- org.nuxeo.ecm.core.blob.AbstractBlobStore
-
- org.nuxeo.ecm.core.blob.CachingBlobStore
-
- All Implemented Interfaces:
BlobStore
public class CachingBlobStore extends AbstractBlobStore
Blob store wrapper that caches blobs locally because fetching them may be expensive.- Since:
- 11.1
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classCachingBlobStore.CachingBinaryGarbageCollectorGarbage collector that delegates to the underlying one, but purges the cache after an actual GC is done.protected static classCachingBlobStore.PathInfo-
Nested classes/interfaces inherited from interface org.nuxeo.ecm.core.blob.BlobStore
BlobStore.OptionalOrUnknown<T>
-
-
Field Summary
Fields Modifier and Type Field Description protected CachingConfigurationcacheConfigLocalBlobStorecacheStoreprotected longclearOldBlobsIntervalprotected longclearOldBlobsLastTimeprotected LockclearOldBlobsLockprotected Clockclockprotected BinaryGarbageCollectorgcprotected static Set<Path>LOCKED_FILESprotected BlobStorestore-
Fields inherited from class org.nuxeo.ecm.core.blob.AbstractBlobStore
blobProviderId, BYTE_RANGE_SEP, keyStrategy, name
-
-
Constructor Summary
Constructors Constructor Description CachingBlobStore(String blobProviderId, String name, BlobStore store, CachingConfiguration config)CachingBlobStore(String name, BlobStore store, CachingConfiguration config)Deprecated.since 11.5
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()INTERNAL (TESTS).protected voidclearOldBlobs()Clear old blobs from the cache, but not too often (as doing directory listings has a cost).protected voidclearOldBlobsNow()Clear old blobs from the cache.StringcopyOrMoveBlob(String key, BlobStore sourceStore, String sourceKey, boolean atomicMove)Writes a file based on a key, as an optimized copy/move from a source in another compatible blob store.protected PathcopyOrMoveCachedBlob(String destKey, LocalBlobStore sourceStore, String sourceKey, boolean atomicMove)voiddeleteBlob(String key)Deletes a blob based on a key.BinaryGarbageCollectorgetBinaryGarbageCollector()Returns the binary garbage collector (GC).BlobStore.OptionalOrUnknown<Path>getFile(String key)Gets an already-existing file containing the blob for the given key, if present.protected BlobStore.OptionalOrUnknown<Path>getFileFromCache(String key, boolean exists)BlobStore.OptionalOrUnknown<InputStream>getStream(String key)Gets the stream of the blob for the given key, if present.booleanhasVersioning()Whether this blob store has versioning.booleanreadBlob(String key, Path dest)Reads a blob based on its key into the given file.protected voidrecordBlobAccess(Path path)Records access to a file by changing its modification time.protected voidrecordBlobAccess(LocalBlobStore localBlobStore, String key)protected PathrenameCachedBlob(String tmpKey, String key)protected static booleantryLock(Path path)protected static voidunlock(Path path)BlobStoreunwrap()If this blob store wraps another one, returns it, otherwise returns this.booleanuseAsyncDigest()Whether this blob store is configured for async digest computation.protected StringwriteBlobGeneric(BlobWriteContext blobWriteContext)Writes the blob without using any store-to-store optimization.voidwriteBlobProperties(BlobUpdateContext blobUpdateContext)Sets properties on a blob.-
Methods inherited from class org.nuxeo.ecm.core.blob.AbstractBlobStore
copyBlobIsOptimized, deleteBlob, getBlobKeyReplacement, getByteRangeFromKey, getKeyStrategy, getName, logTrace, logTrace, logTrace, notifyAsyncDigest, randomLong, randomString, setByteRangeInKey, stripBlobKeyPrefix, stripBlobKeyVersionSuffix, transfer, transfer, transfer, writeBlob, writeBlob, writeBlobUsingOptimizedCopy
-
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.blob.BlobStore
copyBlob, exists, hasDefaultStorageClass
-
-
-
-
Field Detail
-
store
protected final BlobStore store
-
cacheConfig
protected final CachingConfiguration cacheConfig
-
cacheStore
public final LocalBlobStore cacheStore
-
gc
protected final BinaryGarbageCollector gc
-
clearOldBlobsLock
protected final Lock clearOldBlobsLock
-
clearOldBlobsLastTime
protected long clearOldBlobsLastTime
-
clearOldBlobsInterval
protected long clearOldBlobsInterval
-
clock
protected Clock clock
-
-
Constructor Detail
-
CachingBlobStore
@Deprecated public CachingBlobStore(String name, BlobStore store, CachingConfiguration config)
Deprecated.since 11.5
-
CachingBlobStore
public CachingBlobStore(String blobProviderId, String name, BlobStore store, CachingConfiguration config)
- Since:
- 11.5
-
-
Method Detail
-
hasVersioning
public boolean hasVersioning()
Description copied from interface:BlobStoreWhether this blob store has versioning.With versioning, two writes may use the same key. The returned keys will include a different version number to distinguish the writes.
- Specified by:
hasVersioningin interfaceBlobStore- Overrides:
hasVersioningin classAbstractBlobStore
-
unwrap
public BlobStore unwrap()
Description copied from interface:BlobStoreIf this blob store wraps another one, returns it, otherwise returns this.- Specified by:
unwrapin interfaceBlobStore- Overrides:
unwrapin classAbstractBlobStore- Returns:
- the lowest-level blob store
-
renameCachedBlob
protected Path renameCachedBlob(String tmpKey, String key) throws IOException
- Throws:
IOException
-
copyOrMoveCachedBlob
protected Path copyOrMoveCachedBlob(String destKey, LocalBlobStore sourceStore, String sourceKey, boolean atomicMove) throws IOException
- Throws:
IOException
-
writeBlobGeneric
protected String writeBlobGeneric(BlobWriteContext blobWriteContext) throws IOException
Description copied from class:AbstractBlobStoreWrites the blob without using any store-to-store optimization.- Overrides:
writeBlobGenericin classAbstractBlobStore- Throws:
IOException
-
copyOrMoveBlob
public String copyOrMoveBlob(String key, BlobStore sourceStore, String sourceKey, boolean atomicMove) throws IOException
Description copied from interface:BlobStoreWrites a file based on a key, as an optimized copy/move from a source in another compatible blob store.The target
keymay benull, which is a signal from the caller that it has determined that deduplication is enabled and async digest computation is enabled, but the needed digest hasn't been computed, so this method should either find the digest in an efficient way if it can, or otherwise trigger an async digest computation.If the copy/move is requested to be atomic, then the destination file is created atomically. In case of atomic move, in some stores the destination will be created atomically but the source will only be deleted afterwards.
The returned key may be different than the passed one when versioning is used.
- Parameters:
key- the key; ornullif the store should choose it or trigger async digest computationsourceStore- the source storesourceKey- the source keyatomicMove-truefor an atomic move,falsefor a regular copy- Returns:
- the key of the copied/moved file, or
nullif copy/move failed - Throws:
IOException
-
useAsyncDigest
public boolean useAsyncDigest()
Description copied from class:AbstractBlobStoreWhether this blob store is configured for async digest computation.- Overrides:
useAsyncDigestin classAbstractBlobStore
-
getFile
public BlobStore.OptionalOrUnknown<Path> getFile(String key)
Description copied from interface:BlobStoreGets an already-existing file containing the blob for the given key, if present.Note that this method is best-effort, it may return unknown even though the blob exists in the store, it's just that it's not handily available locally in a file.
- Parameters:
key- the blob key- Returns:
- the file containing the blob, or empty if the blob cannot be found, or unknown if no file is available locally
-
getFileFromCache
protected BlobStore.OptionalOrUnknown<Path> getFileFromCache(String key, boolean exists)
-
getStream
public BlobStore.OptionalOrUnknown<InputStream> getStream(String key) throws IOException
Description copied from interface:BlobStoreGets the stream of the blob for the given key, if present.Note that this method is best-effort, it may return unknown even though the blob exists in the store, it's just that it's not efficient to return it as a stream.
- Parameters:
key- the blob key- Returns:
- the blob stream, or empty if the blob cannot be found, or unknown if no stream is efficiently available
- Throws:
IOException
-
readBlob
public boolean readBlob(String key, Path dest) throws IOException
Description copied from interface:BlobStoreReads a blob based on its key into the given file.- Parameters:
key- the blob keydest- the file to use to store the fetched data- Returns:
trueif the file was fetched,falseif the file was not found- Throws:
IOException
-
writeBlobProperties
public void writeBlobProperties(BlobUpdateContext blobUpdateContext) throws IOException
Description copied from interface:BlobStoreSets properties on a blob.- Specified by:
writeBlobPropertiesin interfaceBlobStore- Overrides:
writeBlobPropertiesin classAbstractBlobStore- Parameters:
blobUpdateContext- the blob update context- Throws:
IOException
-
deleteBlob
public void deleteBlob(String key)
Description copied from interface:BlobStoreDeletes a blob based on a key. No error occurs if the blob does not exist.This method does not throw
IOException, but may log an error message.- Parameters:
key- the blob key
-
clear
public void clear()
Description copied from interface:BlobStoreINTERNAL (TESTS). Clears the blob store of all its data.
-
clearOldBlobs
protected void clearOldBlobs()
Clear old blobs from the cache, but not too often (as doing directory listings has a cost).- Since:
- 11.5
-
clearOldBlobsNow
protected void clearOldBlobsNow()
Clear old blobs from the cache.A blob is deleted if it has not been recently created or accessed (minimum age), and if in addition it would be too big for the maximum cache size in bytes, or if the cache would contain too many blobs.
- Since:
- 11.5
-
recordBlobAccess
protected void recordBlobAccess(LocalBlobStore localBlobStore, String key)
-
recordBlobAccess
protected void recordBlobAccess(Path path)
Records access to a file by changing its modification time.Recording access is also a form of locking against concurrent deletion by the clearing mechanism.
- Since:
- 11.5
-
tryLock
protected static boolean tryLock(Path path)
-
unlock
protected static void unlock(Path path)
-
getBinaryGarbageCollector
public BinaryGarbageCollector getBinaryGarbageCollector()
Description copied from interface:BlobStoreReturns the binary garbage collector (GC).Several calls to this method will return the same GC, so that its status can be monitored using
BinaryGarbageCollector.isInProgress().- Returns:
- the binary GC
-
-