public class DataStoreBlobStore extends java.lang.Object implements DataStore, BlobStore, GarbageCollectableBlobStore, BlobTrackingStore, TypedDataStore, BlobAccessProvider
DataStore.getMinRecordLength()
Modifier and Type | Class and Description |
---|---|
static class |
DataStoreBlobStore.BlobId |
SharedDataStore.Type
Modifier and Type | Field and Description |
---|---|
protected LoadingCache<java.lang.String,byte[]> |
cache |
static int |
DEFAULT_CACHE_SIZE |
protected DataStore |
delegate |
static java.lang.String |
MEM_CACHE_NAME |
protected BlobStatsCollector |
stats |
Constructor and Description |
---|
DataStoreBlobStore(DataStore delegate) |
DataStoreBlobStore(DataStore delegate,
boolean encodeLengthInId) |
DataStoreBlobStore(DataStore delegate,
boolean encodeLengthInId,
int cacheSizeInMB) |
Modifier and Type | Method and Description |
---|---|
void |
addMetadataRecord(java.io.File f,
java.lang.String name)
Adds the root record.
|
void |
addMetadataRecord(java.io.InputStream stream,
java.lang.String name)
Adds the root record.
|
DataRecord |
addRecord(java.io.InputStream stream) |
DataRecord |
addRecord(java.io.InputStream input,
BlobOptions options)
Add a record with specified options.
|
void |
addTracker(BlobTracker tracker)
Registers a tracker in the data store.
|
void |
clearCache()
Clear the cache.
|
void |
clearInUse()
Clear all objects marked as "transiently in use".
|
void |
close() |
@Nullable Blob |
completeBlobUpload(@NotNull java.lang.String uploadToken)
Complete a transaction for uploading a blob to a storage location via
direct blob upload.
|
long |
countDeleteChunks(java.util.List<java.lang.String> chunkIds,
long maxLastModifiedTime)
Deletes the blobs with the given ids.
|
void |
deleteAllMetadataRecords(java.lang.String prefix)
Deletes all records matching the given prefix.
|
int |
deleteAllOlderThan(long min) |
boolean |
deleteChunks(java.util.List<java.lang.String> chunkIds,
long maxLastModifiedTime)
Deletes the blobs with the given ids.
|
boolean |
deleteMetadataRecord(java.lang.String name)
Deletes the root record represented by the given parameters.
|
protected java.lang.String |
extractBlobId(java.lang.String encodedBlobId) |
java.util.Iterator<java.lang.String> |
getAllChunkIds(long maxLastModifiedTime)
Gets all the identifiers.
|
java.util.Iterator<DataIdentifier> |
getAllIdentifiers() |
java.util.List<DataRecord> |
getAllMetadataRecords(java.lang.String prefix)
Gets the all root records.
|
java.util.Iterator<DataRecord> |
getAllRecords()
Retrieved an iterator over all DataRecords.
|
java.lang.String |
getBlobId(@NotNull java.lang.String reference)
Returns the blobId that referred by the given binary reference.
|
long |
getBlobLength(java.lang.String encodedBlobId)
Get the length of the blob.
|
long |
getBlockSizeMin()
Get the minimum block size (if there is any).
|
CacheStats |
getCacheStats() |
protected DataRecord |
getDataRecord(java.lang.String blobId) |
DataStore |
getDataStore() |
@Nullable java.net.URI |
getDownloadURI(@NotNull Blob blob,
@NotNull BlobDownloadOptions downloadOptions)
Obtain a download URI for a
Blob . |
java.io.InputStream |
getInputStream(java.lang.String encodedBlobId)
Returns a new stream for given blobId.
|
DataRecord |
getMetadataRecord(java.lang.String name)
Retrieves the metadata record with the given name
|
int |
getMinRecordLength() |
DataRecord |
getRecord(DataIdentifier identifier) |
DataRecord |
getRecordForId(DataIdentifier identifier)
Retrieves the record for the given identifier
|
DataRecord |
getRecordFromReference(java.lang.String reference) |
DataRecord |
getRecordIfStored(DataIdentifier identifier) |
java.lang.String |
getReference(@NotNull java.lang.String encodedBlobId)
Returns a secure reference to blob referred by blobid, or
null if no such
reference is available. |
java.lang.String |
getRepositoryId()
Returns the repository id (identifier for the repository in the DataStore)
|
protected java.io.InputStream |
getStream(java.lang.String blobId) |
@Nullable BlobTracker |
getTracker()
Gets the traker registered in the data store.
|
SharedDataStore.Type |
getType()
Gets the type.
|
void |
init(java.lang.String homeDir) |
@Nullable BlobUpload |
initiateBlobUpload(long maxUploadSizeInBytes,
int maxNumberOfURIs)
Begin a transaction to perform a direct blob upload to a storage
location.
|
@Nullable BlobUpload |
initiateBlobUpload(long maxUploadSizeInBytes,
int maxNumberOfURIs,
@NotNull BlobUploadOptions options)
Begin a transaction to perform a direct blob upload to a storage
location.
|
boolean |
metadataRecordExists(java.lang.String name)
Checks if the metadata record with the name exists
|
int |
readBlob(java.lang.String encodedBlobId,
long pos,
byte[] buff,
int off,
int length)
Read a number of bytes from a blob.
|
java.util.Iterator<java.lang.String> |
resolveChunks(java.lang.String blobId)
Resolve chunks stored in the blob store from the given Id.
|
void |
setBlobStatsCollector(BlobStatsCollector stats) |
void |
setBlockSize(int x)
Set the block size used by this blob store, if the blob store splits
binaries into blocks.
|
void |
setMaxCachedBinarySize(int maxCachedBinarySize) |
void |
setRepositoryId(java.lang.String repositoryId)
Sets the repository id to identify repository in the DataStore
|
void |
startMark()
Start the mark phase.
|
int |
sweep()
Remove all unused blocks.
|
java.lang.String |
toString() |
void |
updateModifiedDateOnAccess(long before) |
java.lang.String |
writeBlob(java.io.InputStream stream)
Write a blob from an input stream.
|
java.lang.String |
writeBlob(java.io.InputStream stream,
BlobOptions options)
Write a blob from an input stream with specified options.
|
java.lang.String |
writeBlob(java.lang.String tempFileName)
Write a blob from a temporary file.
|
protected final DataStore delegate
protected BlobStatsCollector stats
protected final LoadingCache<java.lang.String,byte[]> cache
public static final int DEFAULT_CACHE_SIZE
public static final java.lang.String MEM_CACHE_NAME
public DataStoreBlobStore(DataStore delegate)
public DataStoreBlobStore(DataStore delegate, boolean encodeLengthInId)
public DataStoreBlobStore(DataStore delegate, boolean encodeLengthInId, int cacheSizeInMB)
public DataRecord getRecordIfStored(DataIdentifier identifier) throws DataStoreException
getRecordIfStored
in interface DataStore
DataStoreException
public DataRecord getRecord(DataIdentifier identifier) throws DataStoreException
getRecord
in interface DataStore
DataStoreException
public DataRecord getRecordFromReference(java.lang.String reference) throws DataStoreException
getRecordFromReference
in interface DataStore
DataStoreException
public DataRecord addRecord(java.io.InputStream stream) throws DataStoreException
addRecord
in interface DataStore
DataStoreException
public void updateModifiedDateOnAccess(long before)
updateModifiedDateOnAccess
in interface DataStore
public int deleteAllOlderThan(long min) throws DataStoreException
deleteAllOlderThan
in interface DataStore
DataStoreException
public java.util.Iterator<DataIdentifier> getAllIdentifiers() throws DataStoreException
getAllIdentifiers
in interface DataStore
DataStoreException
public void init(java.lang.String homeDir) throws RepositoryException
init
in interface DataStore
RepositoryException
public int getMinRecordLength()
getMinRecordLength
in interface DataStore
public void close() throws DataStoreException
close
in interface java.lang.AutoCloseable
close
in interface DataStore
DataStoreException
public java.lang.String writeBlob(java.io.InputStream stream) throws java.io.IOException
BlobStore
public java.lang.String writeBlob(java.io.InputStream stream, BlobOptions options) throws java.io.IOException
BlobStore
public int readBlob(java.lang.String encodedBlobId, long pos, byte[] buff, int off, int length) throws java.io.IOException
BlobStore
public long getBlobLength(java.lang.String encodedBlobId) throws java.io.IOException
BlobStore
getBlobLength
in interface BlobStore
encodedBlobId
- the blob idjava.io.IOException
public java.lang.String getBlobId(@NotNull @NotNull java.lang.String reference)
BlobStore
null
if the reference is invalid, for example if it
points to a blob that does not exist.public java.lang.String getReference(@NotNull @NotNull java.lang.String encodedBlobId)
BlobStore
null
if no such
reference is available.getReference
in interface BlobStore
encodedBlobId
- blobId referring the blob for which reference is requirednull
public java.io.InputStream getInputStream(java.lang.String encodedBlobId) throws java.io.IOException
BlobStore
read
return the same sequence of bytes as long as neither call throws
an exception.getInputStream
in interface BlobStore
encodedBlobId
- the blob idjava.io.IOException
public void setBlockSize(int x)
GarbageCollectableBlobStore
setBlockSize
in interface GarbageCollectableBlobStore
x
- the block size in bytes.public java.lang.String writeBlob(java.lang.String tempFileName) throws java.io.IOException
GarbageCollectableBlobStore
writeBlob
in interface GarbageCollectableBlobStore
tempFileName
- the temporary file namejava.io.IOException
public int sweep() throws java.io.IOException
GarbageCollectableBlobStore
sweep
in interface GarbageCollectableBlobStore
java.io.IOException
public void startMark() throws java.io.IOException
GarbageCollectableBlobStore
startMark
in interface GarbageCollectableBlobStore
java.io.IOException
public void clearInUse()
GarbageCollectableBlobStore
clearInUse
in interface DataStore
clearInUse
in interface GarbageCollectableBlobStore
public void clearCache()
GarbageCollectableBlobStore
clearCache
in interface GarbageCollectableBlobStore
public long getBlockSizeMin()
GarbageCollectableBlobStore
getBlockSizeMin
in interface GarbageCollectableBlobStore
public java.util.Iterator<java.lang.String> getAllChunkIds(long maxLastModifiedTime) throws java.lang.Exception
GarbageCollectableBlobStore
getAllChunkIds
in interface GarbageCollectableBlobStore
maxLastModifiedTime
- the max last modified time to consider for retrieval,
with the special value '0' meaning no filtering by timejava.lang.Exception
- the exceptionpublic boolean deleteChunks(java.util.List<java.lang.String> chunkIds, long maxLastModifiedTime) throws java.lang.Exception
GarbageCollectableBlobStore
deleteChunks
in interface GarbageCollectableBlobStore
chunkIds
- the chunk idsmaxLastModifiedTime
- the max last modified time to consider for retrieval,
with the special value '0' meaning no filtering by timejava.lang.Exception
- the exceptionpublic long countDeleteChunks(java.util.List<java.lang.String> chunkIds, long maxLastModifiedTime) throws java.lang.Exception
GarbageCollectableBlobStore
countDeleteChunks
in interface GarbageCollectableBlobStore
chunkIds
- the chunk idsmaxLastModifiedTime
- the max last modified time to consider for retrieval,
with the special value '0' meaning no filtering by timejava.lang.Exception
- the exceptionpublic java.util.Iterator<java.lang.String> resolveChunks(java.lang.String blobId) throws java.io.IOException
GarbageCollectableBlobStore
resolveChunks
in interface GarbageCollectableBlobStore
blobId
- the blob idjava.io.IOException
- Signals that an I/O exception has occurred.public void addMetadataRecord(java.io.InputStream stream, java.lang.String name) throws DataStoreException
SharedDataStore
addMetadataRecord
in interface SharedDataStore
stream
- the streamname
- the name of the root recordDataStoreException
- the data store exceptionpublic void addMetadataRecord(java.io.File f, java.lang.String name) throws DataStoreException
SharedDataStore
addMetadataRecord
in interface SharedDataStore
f
- the filename
- the name of the root recordDataStoreException
- the data store exceptionpublic DataRecord getMetadataRecord(java.lang.String name)
SharedDataStore
getMetadataRecord
in interface SharedDataStore
name
- the name of the recordpublic boolean metadataRecordExists(java.lang.String name)
SharedDataStore
metadataRecordExists
in interface SharedDataStore
public java.util.List<DataRecord> getAllMetadataRecords(java.lang.String prefix)
SharedDataStore
getAllMetadataRecords
in interface SharedDataStore
public boolean deleteMetadataRecord(java.lang.String name)
SharedDataStore
deleteMetadataRecord
in interface SharedDataStore
name
- the name of the root recordpublic void deleteAllMetadataRecords(java.lang.String prefix)
SharedDataStore
deleteAllMetadataRecords
in interface SharedDataStore
prefix
- metadata type identifierpublic void setRepositoryId(java.lang.String repositoryId) throws DataStoreException
SharedDataStore
setRepositoryId
in interface SharedDataStore
DataStoreException
public java.lang.String getRepositoryId()
SharedDataStore
getRepositoryId
in interface SharedDataStore
public java.util.Iterator<DataRecord> getAllRecords() throws DataStoreException
SharedDataStore
getAllRecords
in interface SharedDataStore
DataStoreException
public DataRecord getRecordForId(DataIdentifier identifier) throws DataStoreException
SharedDataStore
getRecordForId
in interface SharedDataStore
identifier
- the if of the recordDataStoreException
public SharedDataStore.Type getType()
SharedDataStore
getType
in interface SharedDataStore
public DataRecord addRecord(java.io.InputStream input, BlobOptions options) throws DataStoreException
TypedDataStore
addRecord
in interface TypedDataStore
DataStoreException
public java.lang.String toString()
toString
in class java.lang.Object
public DataStore getDataStore()
public CacheStats getCacheStats()
public void setMaxCachedBinarySize(int maxCachedBinarySize)
public void setBlobStatsCollector(BlobStatsCollector stats)
public void addTracker(BlobTracker tracker)
BlobTrackingStore
addTracker
in interface BlobTrackingStore
@Nullable public @Nullable BlobTracker getTracker()
BlobTrackingStore
getTracker
in interface BlobTrackingStore
protected java.io.InputStream getStream(java.lang.String blobId) throws java.io.IOException
java.io.IOException
protected DataRecord getDataRecord(java.lang.String blobId) throws DataStoreException
DataStoreException
protected java.lang.String extractBlobId(java.lang.String encodedBlobId)
@Nullable public @Nullable BlobUpload initiateBlobUpload(long maxUploadSizeInBytes, int maxNumberOfURIs) throws java.lang.IllegalArgumentException
BlobAccessProvider
IllegalArgumentException
if no
valid upload can be arranged with the arguments specified. E.g. the max
upload size specified divided by the number of URIs requested indicates
the minimum size of each upload. If that size exceeds the maximum upload
size supported by the service provider, IllegalArgumentException
is thrown.
Each service provider has specific limitations with regard to maximum
upload sizes, maximum overall blob sizes, numbers of URIs in multi-part
uploads, etc. which can lead to IllegalArgumentException
being
thrown. You should consult the documentation for your specific service
provider for details.
Beyond service provider limitations, the implementation may also choose to enforce its own limitations and may throw this exception based on those limitations. Configuration may also be used to set limitations so this exception may be thrown when configuration parameters are exceeded.
initiateBlobUpload
in interface BlobAccessProvider
maxUploadSizeInBytes
- the largest size of the blob to be
uploaded, in bytes, based on the caller's best guess. If the
actual size of the file to be uploaded is known, that value
should be used.maxNumberOfURIs
- the maximum number of URIs the client is able to
accept. If the client does not support multi-part uploading, this
value should be 1. Note that the implementing class is not
required to support multi-part uploading so it may return only a
single upload URI regardless of the value passed in for this
parameter. If the client is able to accept any number of URIs, a
value of -1 may be passed in to indicate that the implementation
is free to return as many URIs as it desires.BlobUpload
referencing this direct upload, or
null
if the underlying implementation doesn't support
direct uploading.java.lang.IllegalArgumentException
- if maxUploadSizeInBytes
is not
a positive value, or if maxNumberOfURIs
is not either a
positive value or -1, or if the upload cannot be completed as
requested, due to a mismatch between the request parameters and
the capabilities of the service provider or the implementation.@Nullable public @Nullable BlobUpload initiateBlobUpload(long maxUploadSizeInBytes, int maxNumberOfURIs, @NotNull @NotNull BlobUploadOptions options) throws java.lang.IllegalArgumentException
BlobAccessProvider
IllegalArgumentException
if no
valid upload can be arranged with the arguments specified. E.g. the max
upload size specified divided by the number of URIs requested indicates
the minimum size of each upload. If that size exceeds the maximum upload
size supported by the service provider, IllegalArgumentException
is thrown.
Each service provider has specific limitations with regard to maximum
upload sizes, maximum overall blob sizes, numbers of URIs in multi-part
uploads, etc. which can lead to IllegalArgumentException
being
thrown. You should consult the documentation for your specific service
provider for details.
Beyond service provider limitations, the implementation may also choose to enforce its own limitations and may throw this exception based on those limitations. Configuration may also be used to set limitations so this exception may be thrown when configuration parameters are exceeded.
initiateBlobUpload
in interface BlobAccessProvider
maxUploadSizeInBytes
- the largest size of the blob to be
uploaded, in bytes, based on the caller's best guess. If the
actual size of the file to be uploaded is known, that value
should be used.maxNumberOfURIs
- the maximum number of URIs the client is able to
accept. If the client does not support multi-part uploading, this
value should be 1. Note that the implementing class is not
required to support multi-part uploading so it may return only a
single upload URI regardless of the value passed in for this
parameter. If the client is able to accept any number of URIs, a
value of -1 may be passed in to indicate that the implementation
is free to return as many URIs as it desires.options
- an instance of BlobUploadOptions
which allows the
caller to specify any desired upload URI options.BlobUpload
referencing this direct upload, or
null
if the underlying implementation doesn't support
direct uploading.java.lang.IllegalArgumentException
- if maxUploadSizeInBytes
is not
a positive value, or if maxNumberOfURIs
is not either a
positive value or -1, or if the upload cannot be completed as
requested, due to a mismatch between the request parameters and
the capabilities of the service provider or the implementation.@Nullable public @Nullable Blob completeBlobUpload(@NotNull @NotNull java.lang.String uploadToken) throws java.lang.IllegalArgumentException
BlobAccessProvider
This requires an uploadToken
that can be obtained from the
returned BlobUpload
from a previous call to BlobAccessProvider.initiateBlobUpload(long, int)
. This token is required to complete
the transaction for an upload to be valid and complete. The token
includes encoded data about the transaction and may include a signature
that will be verified by the implementation.
completeBlobUpload
in interface BlobAccessProvider
uploadToken
- the upload token from a BlobUpload
object
returned from a previous call to BlobAccessProvider.initiateBlobUpload(long, int)
.Blob
that was created, or null
if the object
could not be created.java.lang.IllegalArgumentException
- if the uploadToken
is null,
empty, or cannot be parsed or is otherwise invalid, e.g. if the
included signature does not match.@Nullable public @Nullable java.net.URI getDownloadURI(@NotNull @NotNull Blob blob, @NotNull @NotNull BlobDownloadOptions downloadOptions)
BlobAccessProvider
Blob
. This is usually a signed URI
that can be used to directly download the blob corresponding to the
provided Blob
.
A caller must specify a BlobDownloadOptions
instance. The
implementation will attempt to apply the specified downloadOptions
to the subsequent download. For example, if the caller
knows that the URI refers to a specific type of content, the caller can
specify that content type by setting it in the downloadOptions
.
The caller may also use a default instance obtained via BlobDownloadOptions.DEFAULT
in which case the caller is indicating that
the default behavior of the service provider is acceptable.
getDownloadURI
in interface BlobAccessProvider
blob
- The Blob
to be downloaded.downloadOptions
- A BlobDownloadOptions
instance that
specifies any download options to be used for the download URI.null
if the blob
cannot be downloaded directly.Copyright © 2012–2022 The Apache Software Foundation. All rights reserved.