Class TransactionalBlobStore
- java.lang.Object
-
- org.nuxeo.ecm.core.blob.AbstractBlobStore
-
- org.nuxeo.ecm.core.blob.TransactionalBlobStore
-
- All Implemented Interfaces:
javax.transaction.Synchronization
,BlobStore
public class TransactionalBlobStore extends AbstractBlobStore implements javax.transaction.Synchronization
Transactional Blob Store.Until the transaction is committed, blobs are stored in a transient store. Upon commit, they are sent to the permanent store.
It is important that a copy operation between the transient store and the permanent store be extremely fast and never fail, as it will be done during commit.
- Since:
- 11.1
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TransactionalBlobStore.TransientInfo
Transient data recording operations applied to a blob, to be executed on the permanent store at commit time.-
Nested classes/interfaces inherited from interface org.nuxeo.ecm.core.blob.BlobStore
BlobStore.OptionalOrUnknown<T>
-
-
Field Summary
Fields Modifier and Type Field Description protected static String
DELETE_MARKER
protected Map<String,javax.transaction.Transaction>
keysInActiveTransactions
BlobStore
store
protected ThreadLocal<Map<String,TransactionalBlobStore.TransientInfo>>
transientInfo
BlobStore
transientStore
-
Fields inherited from class org.nuxeo.ecm.core.blob.AbstractBlobStore
BYTE_RANGE_SEP, keyStrategy, name
-
-
Constructor Summary
Constructors Constructor Description TransactionalBlobStore(BlobStore store, BlobStore transientStore)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterCompletion(int status)
void
beforeCompletion()
boolean
copyBlob(String key, BlobStore sourceStore, String sourceKey, boolean atomicMove)
Writes a file based on a key, as a copy/move from a source in another blob store.void
deleteBlob(String key)
Deletes a blob based on a key.BinaryGarbageCollector
getBinaryGarbageCollector()
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.BlobStore.OptionalOrUnknown<InputStream>
getStream(String key)
Gets the stream of the blob for the given key, if present.protected javax.transaction.Transaction
getTransaction()
protected TransactionalBlobStore.TransientInfo
getTransientInfo(String key)
protected String
getTransientKey(String key)
boolean
hasVersioning()
Whether this blob store has versioning.protected static boolean
isDeleteMarker(String transientKey)
protected void
putTransientKey(String key, String transientKey)
protected void
putTransientUpdate(String key, BlobUpdateContext blobUpdateContext)
boolean
readBlob(String key, Path file)
Reads a blob based on its key into the given file.BlobStore
unwrap()
If this blob store wraps another one, returns it, otherwise returns this.String
writeBlob(BlobWriteContext blobWriteContext)
Writes a blob.void
writeBlobProperties(BlobUpdateContext blobUpdateContext)
Sets properties on a blob.-
Methods inherited from class org.nuxeo.ecm.core.blob.AbstractBlobStore
copyBlobIsOptimized, deleteBlob, getByteRangeFromKey, getKeyStrategy, getName, logTrace, logTrace, logTrace, randomLong, randomString, setByteRangeInKey, stripBlobKeyPrefix, transfer, transfer, transfer, writeBlob
-
-
-
-
Field Detail
-
transientStore
public final BlobStore transientStore
-
transientInfo
protected final ThreadLocal<Map<String,TransactionalBlobStore.TransientInfo>> transientInfo
-
keysInActiveTransactions
protected final Map<String,javax.transaction.Transaction> keysInActiveTransactions
-
DELETE_MARKER
protected static final String DELETE_MARKER
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TransactionalBlobStore
public TransactionalBlobStore(BlobStore store, BlobStore transientStore)
-
-
Method Detail
-
isDeleteMarker
protected static boolean isDeleteMarker(String transientKey)
-
getBinaryGarbageCollector
public BinaryGarbageCollector getBinaryGarbageCollector()
Description copied from interface:BlobStore
Returns 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()
.- Specified by:
getBinaryGarbageCollector
in interfaceBlobStore
- Returns:
- the binary GC
-
hasVersioning
public boolean hasVersioning()
Description copied from interface:BlobStore
Whether 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:
hasVersioning
in interfaceBlobStore
- Overrides:
hasVersioning
in classAbstractBlobStore
-
unwrap
public BlobStore unwrap()
Description copied from interface:BlobStore
If this blob store wraps another one, returns it, otherwise returns this.- Specified by:
unwrap
in interfaceBlobStore
- Overrides:
unwrap
in classAbstractBlobStore
- Returns:
- the lowest-level blob store
-
writeBlob
public String writeBlob(BlobWriteContext blobWriteContext) throws IOException
Description copied from interface:BlobStore
Writes a blob.Note that the returned key may be different than the one requested by the
BlobWriteContext
, if the blob store needs additional version info to retrieve it.- Specified by:
writeBlob
in interfaceBlobStore
- Parameters:
blobWriteContext
- the context of the blob write, including the blob- Returns:
- the key to use to read this blob in the future
- Throws:
IOException
-
copyBlob
public boolean copyBlob(String key, BlobStore sourceStore, String sourceKey, boolean atomicMove) throws IOException
Description copied from interface:BlobStore
Writes a file based on a key, as a copy/move from a source in another blob store.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.
- Specified by:
copyBlob
in interfaceBlobStore
- Parameters:
key
- the keysourceStore
- the source storesourceKey
- the source keyatomicMove
-true
for an atomic move,false
for a regular copy- Returns:
true
if the file was found in the source store,false
if it was not found- Throws:
IOException
-
getFile
public BlobStore.OptionalOrUnknown<Path> getFile(String key)
Description copied from interface:BlobStore
Gets 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.
-
getStream
public BlobStore.OptionalOrUnknown<InputStream> getStream(String key) throws IOException
Description copied from interface:BlobStore
Gets 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.
- Specified by:
getStream
in interfaceBlobStore
- 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 file) throws IOException
Description copied from interface:BlobStore
Reads a blob based on its key into the given file.- Specified by:
readBlob
in interfaceBlobStore
- Parameters:
key
- the blob keyfile
- the file to use to store the fetched data- Returns:
true
if the file was fetched,false
if the file was not found- Throws:
IOException
-
writeBlobProperties
public void writeBlobProperties(BlobUpdateContext blobUpdateContext) throws IOException
Description copied from interface:BlobStore
Sets properties on a blob.- Specified by:
writeBlobProperties
in interfaceBlobStore
- Overrides:
writeBlobProperties
in classAbstractBlobStore
- Parameters:
blobUpdateContext
- the blob update context- Throws:
IOException
-
deleteBlob
public void deleteBlob(String key)
Description copied from interface:BlobStore
Deletes 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.- Specified by:
deleteBlob
in interfaceBlobStore
- Parameters:
key
- the blob key
-
getTransaction
protected javax.transaction.Transaction getTransaction()
-
getTransientKey
protected String getTransientKey(String key)
-
putTransientKey
protected void putTransientKey(String key, String transientKey)
-
putTransientUpdate
protected void putTransientUpdate(String key, BlobUpdateContext blobUpdateContext)
-
getTransientInfo
protected TransactionalBlobStore.TransientInfo getTransientInfo(String key)
-
beforeCompletion
public void beforeCompletion()
- Specified by:
beforeCompletion
in interfacejavax.transaction.Synchronization
-
afterCompletion
public void afterCompletion(int status)
- Specified by:
afterCompletion
in interfacejavax.transaction.Synchronization
-
-