Class DataStoreBlobStore
java.lang.Object
org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore
- All Implemented Interfaces:
AutoCloseable,DataStore,org.apache.jackrabbit.oak.api.blob.BlobAccessProvider,BlobTrackingStore,TypedDataStore,SharedDataStore,BlobStore,GarbageCollectableBlobStore
public class DataStoreBlobStore
extends Object
implements DataStore, BlobStore, GarbageCollectableBlobStore, BlobTrackingStore, TypedDataStore, org.apache.jackrabbit.oak.api.blob.BlobAccessProvider
BlobStore wrapper for DataStore. Wraps Jackrabbit 2 DataStore and expose them as BlobStores
It also handles inlining binaries if there size is smaller than
DataStore.getMinRecordLength()-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.apache.jackrabbit.oak.plugins.blob.SharedDataStore
SharedDataStore.Type -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDataStoreBlobStore(DataStore delegate) DataStoreBlobStore(DataStore delegate, boolean encodeLengthInId) DataStoreBlobStore(DataStore delegate, boolean encodeLengthInId, int cacheSizeInMB) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMetadataRecord(File f, String name) Adds the root record.voidaddMetadataRecord(InputStream stream, String name) Adds the root record.addRecord(InputStream stream) Creates a new data record.addRecord(InputStream input, BlobOptions options) Add a record with specified options.voidaddTracker(BlobTracker tracker) Registers a tracker in the data store.voidClear the cache.voidClear the in-use list.voidclose()Close the data store@Nullable BlobcompleteBlobUpload(@NotNull String uploadToken) longcountDeleteChunks(List<String> chunkIds, long maxLastModifiedTime) Deletes the blobs with the given ids.voiddeleteAllMetadataRecords(String prefix) Deletes all records matching the given prefix.intdeleteAllOlderThan(long min) Delete objects that have a modified date older than the specified date.booleandeleteChunks(List<String> chunkIds, long maxLastModifiedTime) Deletes the blobs with the given ids.booleandeleteMetadataRecord(String name) Deletes the root record represented by the given parameters.getAllChunkIds(long maxLastModifiedTime) Gets all the identifiers.Get all identifiers.getAllMetadataRecords(String prefix) Gets the all root records.Retrieved an iterator over all DataRecords.Returns the blobId that referred by the given binary reference.longgetBlobLength(String encodedBlobId) Get the length of the blob.longGet the minimum block size (if there is any).@Nullable URIgetDownloadURI(@NotNull Blob blob, @NotNull org.apache.jackrabbit.oak.api.blob.BlobDownloadOptions downloadOptions) getInputStream(String encodedBlobId) Returns a new stream for given blobId.getMetadataRecord(String name) Retrieves the metadata record with the given nameintGet the minimum size of an object that should be stored in this data store.getRecord(DataIdentifier identifier) Returns the identified data record.getRecordForId(DataIdentifier identifier) Retrieves the record for the given identifiergetRecordFromReference(String reference) Returns the record that matches the given binary reference.getRecordIfStored(DataIdentifier identifier) Check if a record for the given identifier exists, and return it if yes.getReference(@NotNull String encodedBlobId) Returns a secure reference to blob referred by blobid, ornullif no such reference is available.Returns the repository id (identifier for the repository in the DataStore)@Nullable BlobTrackerGets the traker registered in the data store.getType()Gets the type.voidInitialized the data store@Nullable org.apache.jackrabbit.oak.api.blob.BlobUploadinitiateBlobUpload(long maxUploadSizeInBytes, int maxNumberOfURIs) @Nullable org.apache.jackrabbit.oak.api.blob.BlobUploadinitiateBlobUpload(long maxUploadSizeInBytes, int maxNumberOfURIs, @NotNull org.apache.jackrabbit.oak.api.blob.BlobUploadOptions options) booleanmetadataRecordExists(String name) Checks if the metadata record with the name existsintRead a number of bytes from a blob.resolveChunks(String blobId) Resolve chunks stored in the blob store from the given Id.voidvoidsetBlockSize(int x) Set the block size used by this blob store, if the blob store splits binaries into blocks.voidsetMaxCachedBinarySize(int maxCachedBinarySize) voidsetRepositoryId(String repositoryId) Sets the repository id to identify repository in the DataStorevoidStart the mark phase.intsweep()Remove all unused blocks.toString()voidupdateModifiedDateOnAccess(long before) From now on, update the modified date of an object even when accessing it.writeBlob(InputStream stream) Write a blob from an input stream.writeBlob(InputStream stream, BlobOptions options) Write a blob from an input stream with specified options.Write a blob from a temporary file.
-
Field Details
-
DEFAULT_CACHE_SIZE
public static final int DEFAULT_CACHE_SIZE- See Also:
-
MEM_CACHE_NAME
- See Also:
-
-
Constructor Details
-
DataStoreBlobStore
-
DataStoreBlobStore
-
DataStoreBlobStore
-
-
Method Details
-
getRecordIfStored
Description copied from interface:DataStoreCheck if a record for the given identifier exists, and return it if yes. If no record exists, this method returns null.- Specified by:
getRecordIfStoredin interfaceDataStore- Parameters:
identifier- data identifier- Returns:
- the record if found, and null if not
- Throws:
DataStoreException- if the data store could not be accessed
-
getRecord
Description copied from interface:DataStoreReturns the identified data record. The given identifier should be the identifier of a previously saved data record. Since records are never removed, there should never be cases where the identified record is not found. Abnormal cases like that are treated as errors and handled by throwing an exception.- Specified by:
getRecordin interfaceDataStore- Parameters:
identifier- data identifier- Returns:
- identified data record
- Throws:
DataStoreException- if the data store could not be accessed, or if the given identifier is invalid
-
getRecordFromReference
Description copied from interface:DataStoreReturns the record that matches the given binary reference. Returnsnullif the reference is invalid, for example if it points to a record that does not exist.- Specified by:
getRecordFromReferencein interfaceDataStore- Parameters:
reference- binary reference- Returns:
- matching record, or
null - Throws:
DataStoreException- if the data store could not be accessed
-
addRecord
Description copied from interface:DataStoreCreates a new data record. The given binary stream is consumed and a binary record containing the consumed stream is created and returned. If the same stream already exists in another record, then that record is returned instead of creating a new one.The given stream is consumed and not closed by this method. It is the responsibility of the caller to close the stream. A typical call pattern would be:
InputStream stream = ...; try { record = store.addRecord(stream); } finally { stream.close(); }- Specified by:
addRecordin interfaceDataStore- Parameters:
stream- binary stream- Returns:
- data record that contains the given stream
- Throws:
DataStoreException- if the data store could not be accessed
-
updateModifiedDateOnAccess
public void updateModifiedDateOnAccess(long before) Description copied from interface:DataStoreFrom now on, update the modified date of an object even when accessing it. Usually, the modified date is only updated when creating a new object, or when a new link is added to an existing object. When this setting is enabled, even getLength() will update the modified date.- Specified by:
updateModifiedDateOnAccessin interfaceDataStore- Parameters:
before- - update the modified date to the current time if it is older than this value
-
deleteAllOlderThan
Description copied from interface:DataStoreDelete objects that have a modified date older than the specified date.- Specified by:
deleteAllOlderThanin interfaceDataStore- Parameters:
min- the minimum time- Returns:
- the number of data records deleted
- Throws:
DataStoreException
-
getAllIdentifiers
Description copied from interface:DataStoreGet all identifiers.- Specified by:
getAllIdentifiersin interfaceDataStore- Returns:
- an iterator over all DataIdentifier objects
- Throws:
DataStoreException- if the list could not be read
-
init
Description copied from interface:DataStoreInitialized the data store- Specified by:
initin interfaceDataStore- Parameters:
homeDir- the home directory of the repository- Throws:
RepositoryException
-
getMinRecordLength
public int getMinRecordLength()Description copied from interface:DataStoreGet the minimum size of an object that should be stored in this data store. Depending on the overhead and configuration, each store may return a different value.- Specified by:
getMinRecordLengthin interfaceDataStore- Returns:
- the minimum size in bytes
-
close
Description copied from interface:DataStoreClose the data store- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceDataStore- Throws:
DataStoreException- if a problem occurred
-
writeBlob
Description copied from interface:BlobStoreWrite a blob from an input stream. This method closes the input stream.- Specified by:
writeBlobin interfaceBlobStore- Parameters:
stream- the input stream- Returns:
- the blob id
- Throws:
IOException
-
writeBlob
Description copied from interface:BlobStoreWrite a blob from an input stream with specified options. This method closes the input stream.- Specified by:
writeBlobin interfaceBlobStore- Parameters:
stream- the input stream to writeoptions- the options to use- Returns:
- Throws:
IOException
-
readBlob
public int readBlob(String encodedBlobId, long pos, byte[] buff, int off, int length) throws IOException Description copied from interface:BlobStoreRead a number of bytes from a blob.- Specified by:
readBlobin interfaceBlobStore- Parameters:
encodedBlobId- the blob idpos- the position within the blobbuff- the target byte arrayoff- the offset within the target arraylength- the number of bytes to read- Returns:
- the number of bytes read
- Throws:
IOException
-
getBlobLength
Description copied from interface:BlobStoreGet the length of the blob.- Specified by:
getBlobLengthin interfaceBlobStore- Parameters:
encodedBlobId- the blob id- Returns:
- the length
- Throws:
IOException
-
getBlobId
Description copied from interface:BlobStoreReturns the blobId that referred by the given binary reference. Returnsnullif the reference is invalid, for example if it points to a blob that does not exist. -
getReference
Description copied from interface:BlobStoreReturns a secure reference to blob referred by blobid, ornullif no such reference is available.- Specified by:
getReferencein interfaceBlobStore- Parameters:
encodedBlobId- blobId referring the blob for which reference is required- Returns:
- binary reference, or
null
-
getInputStream
Description copied from interface:BlobStoreReturns a new stream for given blobId. The streams returned from multiple calls to this method are byte wise equals. That is, subsequent calls toreadreturn the same sequence of bytes as long as neither call throws an exception.- Specified by:
getInputStreamin interfaceBlobStore- Parameters:
encodedBlobId- the blob id- Returns:
- a new stream for given blobId
- Throws:
IOException
-
setBlockSize
public void setBlockSize(int x) Description copied from interface:GarbageCollectableBlobStoreSet the block size used by this blob store, if the blob store splits binaries into blocks. If not, this setting is ignored.- Specified by:
setBlockSizein interfaceGarbageCollectableBlobStore- Parameters:
x- the block size in bytes.
-
writeBlob
Description copied from interface:GarbageCollectableBlobStoreWrite a blob from a temporary file. The temporary file is removed afterwards. A file based blob stores might simply rename the file, so that no additional writes are necessary.- Specified by:
writeBlobin interfaceGarbageCollectableBlobStore- Parameters:
tempFileName- the temporary file name- Returns:
- the blob id
- Throws:
IOException
-
sweep
Description copied from interface:GarbageCollectableBlobStoreRemove all unused blocks.- Specified by:
sweepin interfaceGarbageCollectableBlobStore- Returns:
- the number of removed blocks
- Throws:
IOException
-
startMark
Description copied from interface:GarbageCollectableBlobStoreStart the mark phase.- Specified by:
startMarkin interfaceGarbageCollectableBlobStore- Throws:
IOException
-
clearInUse
public void clearInUse()Description copied from interface:DataStoreClear the in-use list. This is only used for testing to make the the garbage collection think that objects are no longer in use.- Specified by:
clearInUsein interfaceDataStore- Specified by:
clearInUsein interfaceGarbageCollectableBlobStore
-
clearCache
public void clearCache()Description copied from interface:GarbageCollectableBlobStoreClear the cache.- Specified by:
clearCachein interfaceGarbageCollectableBlobStore
-
getBlockSizeMin
public long getBlockSizeMin()Description copied from interface:GarbageCollectableBlobStoreGet the minimum block size (if there is any).- Specified by:
getBlockSizeMinin interfaceGarbageCollectableBlobStore- Returns:
- the block size
-
getAllChunkIds
Description copied from interface:GarbageCollectableBlobStoreGets all the identifiers.- Specified by:
getAllChunkIdsin interfaceGarbageCollectableBlobStore- Parameters:
maxLastModifiedTime- the max last modified time to consider for retrieval, with the special value '0' meaning no filtering by time- Returns:
- the identifiers
- Throws:
Exception- the exception
-
deleteChunks
Description copied from interface:GarbageCollectableBlobStoreDeletes the blobs with the given ids.- Specified by:
deleteChunksin interfaceGarbageCollectableBlobStore- Parameters:
chunkIds- the chunk idsmaxLastModifiedTime- the max last modified time to consider for retrieval, with the special value '0' meaning no filtering by time- Returns:
- true, if successful
- Throws:
Exception- the exception
-
countDeleteChunks
Description copied from interface:GarbageCollectableBlobStoreDeletes the blobs with the given ids.- Specified by:
countDeleteChunksin interfaceGarbageCollectableBlobStore- Parameters:
chunkIds- the chunk idsmaxLastModifiedTime- the max last modified time to consider for retrieval, with the special value '0' meaning no filtering by time- Returns:
- long the count of successful deletions
- Throws:
Exception- the exception
-
resolveChunks
Description copied from interface:GarbageCollectableBlobStoreResolve chunks stored in the blob store from the given Id. This will not return any chunks stored in-line in the id.- Specified by:
resolveChunksin interfaceGarbageCollectableBlobStore- Parameters:
blobId- the blob id- Returns:
- the iterator
- Throws:
IOException- Signals that an I/O exception has occurred.
-
addMetadataRecord
Description copied from interface:SharedDataStoreAdds the root record.- Specified by:
addMetadataRecordin interfaceSharedDataStore- Parameters:
stream- the streamname- the name of the root record- Throws:
DataStoreException- the data store exception
-
addMetadataRecord
Description copied from interface:SharedDataStoreAdds the root record.- Specified by:
addMetadataRecordin interfaceSharedDataStore- Parameters:
f- the filename- the name of the root record- Throws:
DataStoreException- the data store exception
-
getMetadataRecord
Description copied from interface:SharedDataStoreRetrieves the metadata record with the given name- Specified by:
getMetadataRecordin interfaceSharedDataStore- Parameters:
name- the name of the record- Returns:
-
metadataRecordExists
Description copied from interface:SharedDataStoreChecks if the metadata record with the name exists- Specified by:
metadataRecordExistsin interfaceSharedDataStore- Parameters:
name-- Returns:
-
getAllMetadataRecords
Description copied from interface:SharedDataStoreGets the all root records.- Specified by:
getAllMetadataRecordsin interfaceSharedDataStore- Returns:
- the all root records
-
deleteMetadataRecord
Description copied from interface:SharedDataStoreDeletes the root record represented by the given parameters.- Specified by:
deleteMetadataRecordin interfaceSharedDataStore- Parameters:
name- the name of the root record- Returns:
- success/failure
-
deleteAllMetadataRecords
Description copied from interface:SharedDataStoreDeletes all records matching the given prefix.- Specified by:
deleteAllMetadataRecordsin interfaceSharedDataStore- Parameters:
prefix- metadata type identifier
-
setRepositoryId
Description copied from interface:SharedDataStoreSets the repository id to identify repository in the DataStore- Specified by:
setRepositoryIdin interfaceSharedDataStore- Parameters:
repositoryId-- Throws:
DataStoreException
-
getRepositoryId
Description copied from interface:SharedDataStoreReturns the repository id (identifier for the repository in the DataStore)- Specified by:
getRepositoryIdin interfaceSharedDataStore- Returns:
- repository id
-
getAllRecords
Description copied from interface:SharedDataStoreRetrieved an iterator over all DataRecords.- Specified by:
getAllRecordsin interfaceSharedDataStore- Returns:
- iterator over DataRecords
- Throws:
DataStoreException
-
getRecordForId
Description copied from interface:SharedDataStoreRetrieves the record for the given identifier- Specified by:
getRecordForIdin interfaceSharedDataStore- Parameters:
identifier- the if of the record- Returns:
- data record
- Throws:
DataStoreException
-
getType
Description copied from interface:SharedDataStoreGets the type.- Specified by:
getTypein interfaceSharedDataStore- Returns:
- the type
-
addRecord
Description copied from interface:TypedDataStoreAdd a record with specified options.- Specified by:
addRecordin interfaceTypedDataStore- Parameters:
input-options-- Returns:
- Throws:
DataStoreException
-
toString
-
getDataStore
-
getCacheStats
-
setMaxCachedBinarySize
public void setMaxCachedBinarySize(int maxCachedBinarySize) -
setBlobStatsCollector
-
addTracker
Description copied from interface:BlobTrackingStoreRegisters a tracker in the data store.- Specified by:
addTrackerin interfaceBlobTrackingStore- Parameters:
tracker-
-
getTracker
Description copied from interface:BlobTrackingStoreGets the traker registered in the data store.- Specified by:
getTrackerin interfaceBlobTrackingStore- Returns:
- tracker
-
initiateBlobUpload
@Nullable public @Nullable org.apache.jackrabbit.oak.api.blob.BlobUpload initiateBlobUpload(long maxUploadSizeInBytes, int maxNumberOfURIs) throws IllegalArgumentException - Specified by:
initiateBlobUploadin interfaceorg.apache.jackrabbit.oak.api.blob.BlobAccessProvider- Throws:
IllegalArgumentException
-
initiateBlobUpload
@Nullable public @Nullable org.apache.jackrabbit.oak.api.blob.BlobUpload initiateBlobUpload(long maxUploadSizeInBytes, int maxNumberOfURIs, @NotNull @NotNull org.apache.jackrabbit.oak.api.blob.BlobUploadOptions options) throws IllegalArgumentException - Specified by:
initiateBlobUploadin interfaceorg.apache.jackrabbit.oak.api.blob.BlobAccessProvider- Throws:
IllegalArgumentException
-
completeBlobUpload
@Nullable public @Nullable Blob completeBlobUpload(@NotNull @NotNull String uploadToken) throws IllegalArgumentException - Specified by:
completeBlobUploadin interfaceorg.apache.jackrabbit.oak.api.blob.BlobAccessProvider- Throws:
IllegalArgumentException
-
getDownloadURI
@Nullable public @Nullable URI getDownloadURI(@NotNull @NotNull Blob blob, @NotNull @NotNull org.apache.jackrabbit.oak.api.blob.BlobDownloadOptions downloadOptions) - Specified by:
getDownloadURIin interfaceorg.apache.jackrabbit.oak.api.blob.BlobAccessProvider
-