Class DataStoreBlobStore
- java.lang.Object
-
- org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore
-
- All Implemented Interfaces:
java.lang.AutoCloseable,DataStore,org.apache.jackrabbit.oak.api.blob.BlobAccessProvider,BlobTrackingStore,TypedDataStore,SharedDataStore,BlobStore,GarbageCollectableBlobStore
public class DataStoreBlobStore extends java.lang.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 thanDataStore.getMinRecordLength()
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDataStoreBlobStore.BlobId-
Nested classes/interfaces inherited from interface org.apache.jackrabbit.oak.plugins.blob.SharedDataStore
SharedDataStore.Type
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_CACHE_SIZEstatic java.lang.StringMEM_CACHE_NAME
-
Constructor Summary
Constructors Constructor Description DataStoreBlobStore(DataStore delegate)DataStoreBlobStore(DataStore delegate, boolean encodeLengthInId)DataStoreBlobStore(DataStore delegate, boolean encodeLengthInId, int cacheSizeInMB)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMetadataRecord(java.io.File f, java.lang.String name)Adds the root record.voidaddMetadataRecord(java.io.InputStream stream, java.lang.String name)Adds the root record.DataRecordaddRecord(java.io.InputStream stream)Creates a new data record.DataRecordaddRecord(java.io.InputStream input, BlobOptions options)Add a record with specified options.voidaddTracker(BlobTracker tracker)Registers a tracker in the data store.voidclearCache()Clear the cache.voidclearInUse()Clear the in-use list.voidclose()Close the data store@Nullable BlobcompleteBlobUpload(@NotNull java.lang.String uploadToken)longcountDeleteChunks(java.util.List<java.lang.String> chunkIds, long maxLastModifiedTime)Deletes the blobs with the given ids.voiddeleteAllMetadataRecords(java.lang.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(java.util.List<java.lang.String> chunkIds, long maxLastModifiedTime)Deletes the blobs with the given ids.booleandeleteMetadataRecord(java.lang.String name)Deletes the root record represented by the given parameters.java.util.Iterator<java.lang.String>getAllChunkIds(long maxLastModifiedTime)Gets all the identifiers.java.util.Iterator<DataIdentifier>getAllIdentifiers()Get all identifiers.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.StringgetBlobId(@NotNull java.lang.String reference)Returns the blobId that referred by the given binary reference.longgetBlobLength(java.lang.String encodedBlobId)Get the length of the blob.longgetBlockSizeMin()Get the minimum block size (if there is any).CacheStatsgetCacheStats()DataStoregetDataStore()@Nullable java.net.URIgetDownloadURI(@NotNull Blob blob, @NotNull org.apache.jackrabbit.oak.api.blob.BlobDownloadOptions downloadOptions)java.io.InputStreamgetInputStream(java.lang.String encodedBlobId)Returns a new stream for given blobId.DataRecordgetMetadataRecord(java.lang.String name)Retrieves the metadata record with the given nameintgetMinRecordLength()Get the minimum size of an object that should be stored in this data store.DataRecordgetRecord(DataIdentifier identifier)Returns the identified data record.DataRecordgetRecordForId(DataIdentifier identifier)Retrieves the record for the given identifierDataRecordgetRecordFromReference(java.lang.String reference)Returns the record that matches the given binary reference.DataRecordgetRecordIfStored(DataIdentifier identifier)Check if a record for the given identifier exists, and return it if yes.java.lang.StringgetReference(@NotNull java.lang.String encodedBlobId)Returns a secure reference to blob referred by blobid, ornullif no such reference is available.java.lang.StringgetRepositoryId()Returns the repository id (identifier for the repository in the DataStore)@Nullable BlobTrackergetTracker()Gets the traker registered in the data store.SharedDataStore.TypegetType()Gets the type.voidinit(java.lang.String homeDir)Initialized 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(java.lang.String name)Checks if the metadata record with the name existsintreadBlob(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.voidsetBlobStatsCollector(BlobStatsCollector stats)voidsetBlockSize(int x)Set the block size used by this blob store, if the blob store splits binaries into blocks.voidsetMaxCachedBinarySize(int maxCachedBinarySize)voidsetRepositoryId(java.lang.String repositoryId)Sets the repository id to identify repository in the DataStorevoidstartMark()Start the mark phase.intsweep()Remove all unused blocks.java.lang.StringtoString()voidupdateModifiedDateOnAccess(long before)From now on, update the modified date of an object even when accessing it.java.lang.StringwriteBlob(java.io.InputStream stream)Write a blob from an input stream.java.lang.StringwriteBlob(java.io.InputStream stream, BlobOptions options)Write a blob from an input stream with specified options.java.lang.StringwriteBlob(java.lang.String tempFileName)Write a blob from a temporary file.
-
-
-
Field Detail
-
DEFAULT_CACHE_SIZE
public static final int DEFAULT_CACHE_SIZE
- See Also:
- Constant Field Values
-
MEM_CACHE_NAME
public static final java.lang.String MEM_CACHE_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
getRecordIfStored
public DataRecord getRecordIfStored(DataIdentifier identifier) throws DataStoreException
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
public DataRecord getRecord(DataIdentifier identifier) throws DataStoreException
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
public DataRecord getRecordFromReference(java.lang.String reference) throws DataStoreException
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
public DataRecord addRecord(java.io.InputStream stream) throws DataStoreException
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
public int deleteAllOlderThan(long min) throws DataStoreExceptionDescription 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
public java.util.Iterator<DataIdentifier> getAllIdentifiers() throws DataStoreException
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
public void init(java.lang.String homeDir) throws RepositoryExceptionDescription 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
public void close() throws DataStoreExceptionDescription copied from interface:DataStoreClose the data store- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceDataStore- Throws:
DataStoreException- if a problem occurred
-
writeBlob
public java.lang.String writeBlob(java.io.InputStream stream) throws java.io.IOExceptionDescription copied from interface:BlobStoreWrite a blob from an input stream. This method closes the input stream.
-
writeBlob
public java.lang.String writeBlob(java.io.InputStream stream, BlobOptions options) throws java.io.IOExceptionDescription copied from interface:BlobStoreWrite a blob from an input stream with specified options. This method closes the input stream.
-
readBlob
public int readBlob(java.lang.String encodedBlobId, long pos, byte[] buff, int off, int length) throws java.io.IOExceptionDescription copied from interface:BlobStoreRead a number of bytes from a blob.
-
getBlobLength
public long getBlobLength(java.lang.String encodedBlobId) throws java.io.IOExceptionDescription copied from interface:BlobStoreGet the length of the blob.- Specified by:
getBlobLengthin interfaceBlobStore- Parameters:
encodedBlobId- the blob id- Returns:
- the length
- Throws:
java.io.IOException
-
getBlobId
public java.lang.String getBlobId(@NotNull @NotNull java.lang.String reference)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
public java.lang.String getReference(@NotNull @NotNull java.lang.String encodedBlobId)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
public java.io.InputStream getInputStream(java.lang.String encodedBlobId) throws java.io.IOExceptionDescription 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:
java.io.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
public java.lang.String writeBlob(java.lang.String tempFileName) throws java.io.IOExceptionDescription 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:
java.io.IOException
-
sweep
public int sweep() throws java.io.IOExceptionDescription copied from interface:GarbageCollectableBlobStoreRemove all unused blocks.- Specified by:
sweepin interfaceGarbageCollectableBlobStore- Returns:
- the number of removed blocks
- Throws:
java.io.IOException
-
startMark
public void startMark() throws java.io.IOExceptionDescription copied from interface:GarbageCollectableBlobStoreStart the mark phase.- Specified by:
startMarkin interfaceGarbageCollectableBlobStore- Throws:
java.io.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
public java.util.Iterator<java.lang.String> getAllChunkIds(long maxLastModifiedTime) throws java.lang.ExceptionDescription 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:
java.lang.Exception- the exception
-
deleteChunks
public boolean deleteChunks(java.util.List<java.lang.String> chunkIds, long maxLastModifiedTime) throws java.lang.ExceptionDescription 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:
java.lang.Exception- the exception
-
countDeleteChunks
public long countDeleteChunks(java.util.List<java.lang.String> chunkIds, long maxLastModifiedTime) throws java.lang.ExceptionDescription 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:
java.lang.Exception- the exception
-
resolveChunks
public java.util.Iterator<java.lang.String> resolveChunks(java.lang.String blobId) throws java.io.IOExceptionDescription 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:
java.io.IOException- Signals that an I/O exception has occurred.
-
addMetadataRecord
public void addMetadataRecord(java.io.InputStream stream, java.lang.String name) throws DataStoreExceptionDescription 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
public void addMetadataRecord(java.io.File f, java.lang.String name) throws DataStoreExceptionDescription 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
public DataRecord getMetadataRecord(java.lang.String name)
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
public boolean metadataRecordExists(java.lang.String name)
Description copied from interface:SharedDataStoreChecks if the metadata record with the name exists- Specified by:
metadataRecordExistsin interfaceSharedDataStore- Returns:
-
getAllMetadataRecords
public java.util.List<DataRecord> getAllMetadataRecords(java.lang.String prefix)
Description copied from interface:SharedDataStoreGets the all root records.- Specified by:
getAllMetadataRecordsin interfaceSharedDataStore- Returns:
- the all root records
-
deleteMetadataRecord
public boolean deleteMetadataRecord(java.lang.String name)
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
public void deleteAllMetadataRecords(java.lang.String prefix)
Description copied from interface:SharedDataStoreDeletes all records matching the given prefix.- Specified by:
deleteAllMetadataRecordsin interfaceSharedDataStore- Parameters:
prefix- metadata type identifier
-
setRepositoryId
public void setRepositoryId(java.lang.String repositoryId) throws DataStoreExceptionDescription copied from interface:SharedDataStoreSets the repository id to identify repository in the DataStore- Specified by:
setRepositoryIdin interfaceSharedDataStore- Throws:
DataStoreException
-
getRepositoryId
public java.lang.String getRepositoryId()
Description copied from interface:SharedDataStoreReturns the repository id (identifier for the repository in the DataStore)- Specified by:
getRepositoryIdin interfaceSharedDataStore- Returns:
- repository id
-
getAllRecords
public java.util.Iterator<DataRecord> getAllRecords() throws DataStoreException
Description copied from interface:SharedDataStoreRetrieved an iterator over all DataRecords.- Specified by:
getAllRecordsin interfaceSharedDataStore- Returns:
- iterator over DataRecords
- Throws:
DataStoreException
-
getRecordForId
public DataRecord getRecordForId(DataIdentifier identifier) throws DataStoreException
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
public SharedDataStore.Type getType()
Description copied from interface:SharedDataStoreGets the type.- Specified by:
getTypein interfaceSharedDataStore- Returns:
- the type
-
addRecord
public DataRecord addRecord(java.io.InputStream input, BlobOptions options) throws DataStoreException
Description copied from interface:TypedDataStoreAdd a record with specified options.- Specified by:
addRecordin interfaceTypedDataStore- Returns:
- Throws:
DataStoreException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getDataStore
public DataStore getDataStore()
-
getCacheStats
public CacheStats getCacheStats()
-
setMaxCachedBinarySize
public void setMaxCachedBinarySize(int maxCachedBinarySize)
-
setBlobStatsCollector
public void setBlobStatsCollector(BlobStatsCollector stats)
-
addTracker
public void addTracker(BlobTracker tracker)
Description copied from interface:BlobTrackingStoreRegisters a tracker in the data store.- Specified by:
addTrackerin interfaceBlobTrackingStore
-
getTracker
@Nullable public @Nullable BlobTracker 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 java.lang.IllegalArgumentException- Specified by:
initiateBlobUploadin interfaceorg.apache.jackrabbit.oak.api.blob.BlobAccessProvider- Throws:
java.lang.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 java.lang.IllegalArgumentException- Specified by:
initiateBlobUploadin interfaceorg.apache.jackrabbit.oak.api.blob.BlobAccessProvider- Throws:
java.lang.IllegalArgumentException
-
completeBlobUpload
@Nullable public @Nullable Blob completeBlobUpload(@NotNull @NotNull java.lang.String uploadToken) throws java.lang.IllegalArgumentException
- Specified by:
completeBlobUploadin interfaceorg.apache.jackrabbit.oak.api.blob.BlobAccessProvider- Throws:
java.lang.IllegalArgumentException
-
getDownloadURI
@Nullable public @Nullable java.net.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
-
-