- All Known Implementing Classes:
AbstractBlobContainer
,FilterBlobContainer
,FsBlobContainer
public interface BlobContainer
An interface for managing a repository of blob entries, where each blob entry is just a named group of bytes.
A BlobStore creates BlobContainers.
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
assertPurposeConsistency
(OperationPurpose purpose, String blobName) Verify that theOperationPurpose
is (somewhat) suitable for the name of the blob to which it applies:OperationPurpose.SNAPSHOT_DATA
is not used for blobs that look like metadata blobs.OperationPurpose.SNAPSHOT_METADATA
is not used for blobs that look like data blobs.boolean
blobExists
(OperationPurpose purpose, String blobName) Tests whether a blob with the given blob name exists in the container.children
(OperationPurpose purpose) Lists all child containers under this container.void
compareAndExchangeRegister
(OperationPurpose purpose, String key, BytesReference expected, BytesReference updated, ActionListener<OptionalBytesReference> listener) Atomically sets the value stored at the given key toupdated
if thecurrent value == expected
.default void
compareAndSetRegister
(OperationPurpose purpose, String key, BytesReference expected, BytesReference updated, ActionListener<Boolean> listener) Atomically sets the value stored at the given key toupdated
if thecurrent value == expected
.delete
(OperationPurpose purpose) Deletes this container and all its contents from the repository.void
deleteBlobsIgnoringIfNotExists
(OperationPurpose purpose, Iterator<String> blobNames) Deletes the blobs with given names.default void
getRegister
(OperationPurpose purpose, String key, ActionListener<OptionalBytesReference> listener) Gets the value set bycompareAndSetRegister(org.elasticsearch.common.blobstore.OperationPurpose, java.lang.String, org.elasticsearch.common.bytes.BytesReference, org.elasticsearch.common.bytes.BytesReference, org.elasticsearch.action.ActionListener<java.lang.Boolean>)
orcompareAndExchangeRegister(org.elasticsearch.common.blobstore.OperationPurpose, java.lang.String, org.elasticsearch.common.bytes.BytesReference, org.elasticsearch.common.bytes.BytesReference, org.elasticsearch.action.ActionListener<org.elasticsearch.common.blobstore.OptionalBytesReference>)
for a given key.listBlobs
(OperationPurpose purpose) Lists all blobs in the container.listBlobsByPrefix
(OperationPurpose purpose, String blobNamePrefix) Lists all blobs in the container that match the specified prefix.path()
Gets theBlobPath
that defines the implementation specific paths to where the blobs are contained.readBlob
(OperationPurpose purpose, String blobName) Creates a newInputStream
for the given blob name.readBlob
(OperationPurpose purpose, String blobName, long position, long length) Creates a newInputStream
that can be used to read the given blob starting from a specificposition
in the blob.default long
Provides a hint to clients for a suitable length to use withreadBlob(OperationPurpose, String, long, long)
.void
writeBlob
(OperationPurpose purpose, String blobName, InputStream inputStream, long blobSize, boolean failIfAlreadyExists) Reads blob content from the input stream and writes it to the container in a new blob with the given name.default void
writeBlob
(OperationPurpose purpose, String blobName, BytesReference bytes, boolean failIfAlreadyExists) Reads blob content from aBytesReference
and writes it to the container in a new blob with the given name.void
writeBlobAtomic
(OperationPurpose purpose, String blobName, BytesReference bytes, boolean failIfAlreadyExists) Reads blob content from aBytesReference
and writes it to the container in a new blob with the given name, using an atomic write operation if the implementation supports it.void
writeMetadataBlob
(OperationPurpose purpose, String blobName, boolean failIfAlreadyExists, boolean atomic, CheckedConsumer<OutputStream, IOException> writer) Write a blob by providing a consumer that will write its contents to an output stream.
-
Method Details
-
path
BlobPath path()Gets theBlobPath
that defines the implementation specific paths to where the blobs are contained.- Returns:
- the BlobPath where the blobs are contained
-
blobExists
Tests whether a blob with the given blob name exists in the container.- Parameters:
purpose
- The purpose of the operationblobName
- The name of the blob whose existence is to be determined.- Returns:
true
if a blob exists in theBlobContainer
with the given name, andfalse
otherwise.- Throws:
IOException
-
readBlob
Creates a newInputStream
for the given blob name.- Parameters:
purpose
- The purpose of the operationblobName
- The name of the blob to get anInputStream
for.- Returns:
- The
InputStream
to read the blob. - Throws:
NoSuchFileException
- if the blob does not existIOException
- if the blob can not be read.
-
readBlob
InputStream readBlob(OperationPurpose purpose, String blobName, long position, long length) throws IOException Creates a newInputStream
that can be used to read the given blob starting from a specificposition
in the blob. Thelength
is an indication of the number of bytes that are expected to be read from theInputStream
.- Parameters:
purpose
- The purpose of the operationblobName
- The name of the blob to get anInputStream
for.position
- The position in the blob where the next byte will be read.length
- An indication of the number of bytes to be read.- Returns:
- The
InputStream
to read the blob. - Throws:
NoSuchFileException
- if the blob does not existIOException
- if the blob can not be read.
-
readBlobPreferredLength
default long readBlobPreferredLength()Provides a hint to clients for a suitable length to use withreadBlob(OperationPurpose, String, long, long)
. Some blob containers have nontrivial costs attached to each readBlob call, so it is a good idea for consumers to speculatively request more data than they need right now and to re-use this stream for future needs if possible. Also, some blob containers return streams that are expensive to close before the stream has been fully consumed, and the cost may depend on the length of the data that was left unconsumed. For these containers it's best to bound the cost of a partial read by bounding the length of the data requested.- Returns:
- a hint to consumers regarding the length of data to request if there is a good chance that future reads can be satisfied from the same stream.
-
writeBlob
void writeBlob(OperationPurpose purpose, String blobName, InputStream inputStream, long blobSize, boolean failIfAlreadyExists) throws IOException Reads blob content from the input stream and writes it to the container in a new blob with the given name. This method assumes the container does not already contain a blob of the same blobName. If a blob by the same name already exists, the operation will fail and anIOException
will be thrown.- Parameters:
purpose
- The purpose of the operationblobName
- The name of the blob to write the contents of the input stream to.inputStream
- The input stream from which to retrieve the bytes to write to the blob.blobSize
- The size of the blob to be written, in bytes. It is implementation dependent whether this value is used in writing the blob to the repository.failIfAlreadyExists
- whether to throw a FileAlreadyExistsException if the given blob already exists- Throws:
FileAlreadyExistsException
- if failIfAlreadyExists is true and a blob by the same name already existsIOException
- if the input stream could not be read, or the target blob could not be written to.
-
writeBlob
default void writeBlob(OperationPurpose purpose, String blobName, BytesReference bytes, boolean failIfAlreadyExists) throws IOException Reads blob content from aBytesReference
and writes it to the container in a new blob with the given name.- Parameters:
purpose
- The purpose of the operationblobName
- The name of the blob to write the contents of the input stream to.bytes
- The bytes to writefailIfAlreadyExists
- whether to throw a FileAlreadyExistsException if the given blob already exists- Throws:
FileAlreadyExistsException
- if failIfAlreadyExists is true and a blob by the same name already existsIOException
- if the input stream could not be read, or the target blob could not be written to.
-
writeMetadataBlob
void writeMetadataBlob(OperationPurpose purpose, String blobName, boolean failIfAlreadyExists, boolean atomic, CheckedConsumer<OutputStream, IOException> writer) throws IOExceptionWrite a blob by providing a consumer that will write its contents to an output stream. This method allows serializing a blob's contents directly to the blob store without having to materialize the serialized version in full before writing. This method is only used for streaming serialization of repository metadata that is known to be of limited size at any point in time and across all concurrent invocations of this method.- Parameters:
purpose
- The purpose of the operationblobName
- the name of the blob to writefailIfAlreadyExists
- whether to throw a FileAlreadyExistsException if the given blob already existsatomic
- whether the write should be atomic in case the implementation supports itwriter
- consumer for an output stream that will write the blob contents to the stream- Throws:
IOException
-
writeBlobAtomic
void writeBlobAtomic(OperationPurpose purpose, String blobName, BytesReference bytes, boolean failIfAlreadyExists) throws IOException Reads blob content from aBytesReference
and writes it to the container in a new blob with the given name, using an atomic write operation if the implementation supports it.- Parameters:
purpose
- The purpose of the operationblobName
- The name of the blob to write the contents of the input stream to.bytes
- The bytes to writefailIfAlreadyExists
- whether to throw a FileAlreadyExistsException if the given blob already exists- Throws:
FileAlreadyExistsException
- if failIfAlreadyExists is true and a blob by the same name already existsIOException
- if the input stream could not be read, or the target blob could not be written to.
-
delete
Deletes this container and all its contents from the repository.- Parameters:
purpose
- The purpose of the operation- Returns:
- delete result
- Throws:
IOException
- on failure
-
deleteBlobsIgnoringIfNotExists
void deleteBlobsIgnoringIfNotExists(OperationPurpose purpose, Iterator<String> blobNames) throws IOException Deletes the blobs with given names. This method will not throw an exception when one or multiple of the given blobs don't exist and simply ignore this case.- Parameters:
purpose
- The purpose of the operationblobNames
- the names of the blobs to delete- Throws:
IOException
- if a subset of blob exists but could not be deleted.
-
listBlobs
Lists all blobs in the container.- Returns:
- A map of all the blobs in the container. The keys in the map are the names of the blobs and
the values are
BlobMetadata
, containing basic information about each blob. - Throws:
IOException
- if there were any failures in reading from the blob container.
-
children
Lists all child containers under this container. A child container is defined as a container whosepath()
method returns a path that has this containerspath()
return as its prefix and has one more path element than the current container's path.- Parameters:
purpose
- The purpose of the operation- Returns:
- Map of name of the child container to child container
- Throws:
IOException
- on failure to list child containers
-
listBlobsByPrefix
Map<String,BlobMetadata> listBlobsByPrefix(OperationPurpose purpose, String blobNamePrefix) throws IOException Lists all blobs in the container that match the specified prefix.- Parameters:
purpose
- The purpose of the operationblobNamePrefix
- The prefix to match against blob names in the container.- Returns:
- A map of the matching blobs in the container. The keys in the map are the names of the blobs
and the values are
BlobMetadata
, containing basic information about each blob. - Throws:
IOException
- if there were any failures in reading from the blob container.
-
compareAndExchangeRegister
void compareAndExchangeRegister(OperationPurpose purpose, String key, BytesReference expected, BytesReference updated, ActionListener<OptionalBytesReference> listener) Atomically sets the value stored at the given key toupdated
if thecurrent value == expected
. Keys not yet used start at initial value 0. Returns the current value (before it was updated).- Parameters:
purpose
- The purpose of the operationkey
- key of the value to updateexpected
- the expected valueupdated
- the new valuelistener
- a listener, completed with the value read from the register (before it was updated) orOptionalBytesReference.MISSING
if the value could not be read due to concurrent activity.
-
compareAndSetRegister
default void compareAndSetRegister(OperationPurpose purpose, String key, BytesReference expected, BytesReference updated, ActionListener<Boolean> listener) Atomically sets the value stored at the given key toupdated
if thecurrent value == expected
. Keys not yet used start at initial value 0.- Parameters:
purpose
-key
- key of the value to updateexpected
- the expected valueupdated
- the new valuelistener
- a listener which is completed withBoolean.TRUE
if successful,Boolean.FALSE
if the expected value did not match the updated value or the value could not be read due to concurrent activity
-
getRegister
default void getRegister(OperationPurpose purpose, String key, ActionListener<OptionalBytesReference> listener) Gets the value set bycompareAndSetRegister(org.elasticsearch.common.blobstore.OperationPurpose, java.lang.String, org.elasticsearch.common.bytes.BytesReference, org.elasticsearch.common.bytes.BytesReference, org.elasticsearch.action.ActionListener<java.lang.Boolean>)
orcompareAndExchangeRegister(org.elasticsearch.common.blobstore.OperationPurpose, java.lang.String, org.elasticsearch.common.bytes.BytesReference, org.elasticsearch.common.bytes.BytesReference, org.elasticsearch.action.ActionListener<org.elasticsearch.common.blobstore.OptionalBytesReference>)
for a given key. If a key has not yet been used, the initial value is an emptyBytesReference
.- Parameters:
purpose
- The purpose of the operationkey
- key of the value to getlistener
- a listener, completed with the value read from the register orOptionalBytesReference#MISSING
if the value could not be read due to concurrent activity.
-
assertPurposeConsistency
Verify that theOperationPurpose
is (somewhat) suitable for the name of the blob to which it applies:OperationPurpose.SNAPSHOT_DATA
is not used for blobs that look like metadata blobs.OperationPurpose.SNAPSHOT_METADATA
is not used for blobs that look like data blobs.
-