Class 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
    • Constructor Detail

      • TransactionalBlobStore

        public TransactionalBlobStore​(String blobProviderId,
                                      BlobStore store,
                                      BlobStore transientStore)
        Since:
        11.5
    • Method Detail

      • isDeleteMarker

        protected static boolean isDeleteMarker​(String transientKey)
      • 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 interface BlobStore
        Overrides:
        hasVersioning in class AbstractBlobStore
      • 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 interface BlobStore
        Overrides:
        unwrap in class AbstractBlobStore
        Returns:
        the lowest-level blob store
      • copyOrMoveBlob

        public String copyOrMoveBlob​(String key,
                                     BlobStore sourceStore,
                                     String sourceKey,
                                     boolean atomicMove)
                              throws IOException
        Description copied from interface: BlobStore
        Writes a file based on a key, as an optimized copy/move from a source in another compatible blob store.

        The target key may be null, 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.

        Specified by:
        copyOrMoveBlob in interface BlobStore
        Parameters:
        key - the key; or null if the store should choose it or trigger async digest computation
        sourceStore - the source store
        sourceKey - the source key
        atomicMove - true for an atomic move, false for a regular copy
        Returns:
        the key of the copied/moved file, or null if copy/move failed
        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.

        Specified by:
        getFile in interface BlobStore
        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
      • 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 interface BlobStore
        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 interface BlobStore
        Parameters:
        key - the blob key
        file - 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
      • 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 interface BlobStore
        Parameters:
        key - the blob key
      • clear

        public void clear()
        Description copied from interface: BlobStore
        INTERNAL (TESTS). Clears the blob store of all its data.
        Specified by:
        clear in interface BlobStore
      • getTransaction

        protected javax.transaction.Transaction getTransaction()
      • getTransientKey

        protected String getTransientKey​(String key)
      • putTransientKey

        protected void putTransientKey​(String key,
                                       String transientKey)
      • beforeCompletion

        public void beforeCompletion()
        Specified by:
        beforeCompletion in interface javax.transaction.Synchronization
      • afterCompletion

        public void afterCompletion​(int status)
        Specified by:
        afterCompletion in interface javax.transaction.Synchronization