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 thanDataStore.getMinRecordLength()
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DataStoreBlobStore.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 int
DEFAULT_CACHE_SIZE
static String
MEM_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 void
addMetadataRecord(File f, String name)
Adds the root record.void
addMetadataRecord(InputStream stream, String name)
Adds the root record.DataRecord
addRecord(InputStream stream)
Creates a new data record.DataRecord
addRecord(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 the in-use list.void
close()
Close the data store@Nullable Blob
completeBlobUpload(@NotNull String uploadToken)
long
countDeleteChunks(List<String> chunkIds, long maxLastModifiedTime)
Deletes the blobs with the given ids.void
deleteAllMetadataRecords(String prefix)
Deletes all records matching the given prefix.int
deleteAllOlderThan(long min)
Delete objects that have a modified date older than the specified date.boolean
deleteChunks(List<String> chunkIds, long maxLastModifiedTime)
Deletes the blobs with the given ids.boolean
deleteMetadataRecord(String name)
Deletes the root record represented by the given parameters.Iterator<String>
getAllChunkIds(long maxLastModifiedTime)
Gets all the identifiers.Iterator<DataIdentifier>
getAllIdentifiers()
Get all identifiers.List<DataRecord>
getAllMetadataRecords(String prefix)
Gets the all root records.Iterator<DataRecord>
getAllRecords()
Retrieved an iterator over all DataRecords.String
getBlobId(@NotNull String reference)
Returns the blobId that referred by the given binary reference.long
getBlobLength(String encodedBlobId)
Get the length of the blob.long
getBlockSizeMin()
Get the minimum block size (if there is any).CacheStats
getCacheStats()
DataStore
getDataStore()
@Nullable URI
getDownloadURI(@NotNull Blob blob, @NotNull org.apache.jackrabbit.oak.api.blob.BlobDownloadOptions downloadOptions)
InputStream
getInputStream(String encodedBlobId)
Returns a new stream for given blobId.DataRecord
getMetadataRecord(String name)
Retrieves the metadata record with the given nameint
getMinRecordLength()
Get the minimum size of an object that should be stored in this data store.DataRecord
getRecord(DataIdentifier identifier)
Returns the identified data record.DataRecord
getRecordForId(DataIdentifier identifier)
Retrieves the record for the given identifierDataRecord
getRecordFromReference(String reference)
Returns the record that matches the given binary reference.DataRecord
getRecordIfStored(DataIdentifier identifier)
Check if a record for the given identifier exists, and return it if yes.String
getReference(@NotNull String encodedBlobId)
Returns a secure reference to blob referred by blobid, ornull
if no such reference is available.String
getRepositoryId()
Returns the repository id (identifier for the repository in the DataStore)@Nullable BlobTracker
getTracker()
Gets the traker registered in the data store.SharedDataStore.Type
getType()
Gets the type.void
init(String homeDir)
Initialized the data store@Nullable org.apache.jackrabbit.oak.api.blob.BlobUpload
initiateBlobUpload(long maxUploadSizeInBytes, int maxNumberOfURIs)
@Nullable org.apache.jackrabbit.oak.api.blob.BlobUpload
initiateBlobUpload(long maxUploadSizeInBytes, int maxNumberOfURIs, @NotNull org.apache.jackrabbit.oak.api.blob.BlobUploadOptions options)
boolean
metadataRecordExists(String name)
Checks if the metadata record with the name existsint
readBlob(String encodedBlobId, long pos, byte[] buff, int off, int length)
Read a number of bytes from a blob.Iterator<String>
resolveChunks(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(String repositoryId)
Sets the repository id to identify repository in the DataStorevoid
startMark()
Start the mark phase.int
sweep()
Remove all unused blocks.String
toString()
void
updateModifiedDateOnAccess(long before)
From now on, update the modified date of an object even when accessing it.String
writeBlob(InputStream stream)
Write a blob from an input stream.String
writeBlob(InputStream stream, BlobOptions options)
Write a blob from an input stream with specified options.String
writeBlob(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 String MEM_CACHE_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
getRecordIfStored
public DataRecord getRecordIfStored(DataIdentifier identifier) throws DataStoreException
Description copied from interface:DataStore
Check if a record for the given identifier exists, and return it if yes. If no record exists, this method returns null.- Specified by:
getRecordIfStored
in 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:DataStore
Returns 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:
getRecord
in 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(String reference) throws DataStoreException
Description copied from interface:DataStore
Returns the record that matches the given binary reference. Returnsnull
if the reference is invalid, for example if it points to a record that does not exist.- Specified by:
getRecordFromReference
in interfaceDataStore
- Parameters:
reference
- binary reference- Returns:
- matching record, or
null
- Throws:
DataStoreException
- if the data store could not be accessed
-
addRecord
public DataRecord addRecord(InputStream stream) throws DataStoreException
Description copied from interface:DataStore
Creates 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:
addRecord
in 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:DataStore
From 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:
updateModifiedDateOnAccess
in 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 DataStoreException
Description copied from interface:DataStore
Delete objects that have a modified date older than the specified date.- Specified by:
deleteAllOlderThan
in interfaceDataStore
- Parameters:
min
- the minimum time- Returns:
- the number of data records deleted
- Throws:
DataStoreException
-
getAllIdentifiers
public Iterator<DataIdentifier> getAllIdentifiers() throws DataStoreException
Description copied from interface:DataStore
Get all identifiers.- Specified by:
getAllIdentifiers
in interfaceDataStore
- Returns:
- an iterator over all DataIdentifier objects
- Throws:
DataStoreException
- if the list could not be read
-
init
public void init(String homeDir) throws RepositoryException
Description copied from interface:DataStore
Initialized the data store- Specified by:
init
in interfaceDataStore
- Parameters:
homeDir
- the home directory of the repository- Throws:
RepositoryException
-
getMinRecordLength
public int getMinRecordLength()
Description copied from interface:DataStore
Get 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:
getMinRecordLength
in interfaceDataStore
- Returns:
- the minimum size in bytes
-
close
public void close() throws DataStoreException
Description copied from interface:DataStore
Close the data store- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceDataStore
- Throws:
DataStoreException
- if a problem occurred
-
writeBlob
public String writeBlob(InputStream stream) throws IOException
Description copied from interface:BlobStore
Write a blob from an input stream. This method closes the input stream.- Specified by:
writeBlob
in interfaceBlobStore
- Parameters:
stream
- the input stream- Returns:
- the blob id
- Throws:
IOException
-
writeBlob
public String writeBlob(InputStream stream, BlobOptions options) throws IOException
Description copied from interface:BlobStore
Write a blob from an input stream with specified options. This method closes the input stream.- Specified by:
writeBlob
in 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:BlobStore
Read a number of bytes from a blob.- Specified by:
readBlob
in 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
public long getBlobLength(String encodedBlobId) throws IOException
Description copied from interface:BlobStore
Get the length of the blob.- Specified by:
getBlobLength
in interfaceBlobStore
- Parameters:
encodedBlobId
- the blob id- Returns:
- the length
- Throws:
IOException
-
getBlobId
public String getBlobId(@NotNull @NotNull String reference)
Description copied from interface:BlobStore
Returns the blobId that referred by the given binary reference. Returnsnull
if the reference is invalid, for example if it points to a blob that does not exist.
-
getReference
public String getReference(@NotNull @NotNull String encodedBlobId)
Description copied from interface:BlobStore
Returns a secure reference to blob referred by blobid, ornull
if no such reference is available.- Specified by:
getReference
in interfaceBlobStore
- Parameters:
encodedBlobId
- blobId referring the blob for which reference is required- Returns:
- binary reference, or
null
-
getInputStream
public InputStream getInputStream(String encodedBlobId) throws IOException
Description copied from interface:BlobStore
Returns a new stream for given blobId. The streams returned from multiple calls to this method are byte wise equals. That is, subsequent calls toread
return the same sequence of bytes as long as neither call throws an exception.- Specified by:
getInputStream
in 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:GarbageCollectableBlobStore
Set the block size used by this blob store, if the blob store splits binaries into blocks. If not, this setting is ignored.- Specified by:
setBlockSize
in interfaceGarbageCollectableBlobStore
- Parameters:
x
- the block size in bytes.
-
writeBlob
public String writeBlob(String tempFileName) throws IOException
Description copied from interface:GarbageCollectableBlobStore
Write 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:
writeBlob
in interfaceGarbageCollectableBlobStore
- Parameters:
tempFileName
- the temporary file name- Returns:
- the blob id
- Throws:
IOException
-
sweep
public int sweep() throws IOException
Description copied from interface:GarbageCollectableBlobStore
Remove all unused blocks.- Specified by:
sweep
in interfaceGarbageCollectableBlobStore
- Returns:
- the number of removed blocks
- Throws:
IOException
-
startMark
public void startMark() throws IOException
Description copied from interface:GarbageCollectableBlobStore
Start the mark phase.- Specified by:
startMark
in interfaceGarbageCollectableBlobStore
- Throws:
IOException
-
clearInUse
public void clearInUse()
Description copied from interface:DataStore
Clear 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:
clearInUse
in interfaceDataStore
- Specified by:
clearInUse
in interfaceGarbageCollectableBlobStore
-
clearCache
public void clearCache()
Description copied from interface:GarbageCollectableBlobStore
Clear the cache.- Specified by:
clearCache
in interfaceGarbageCollectableBlobStore
-
getBlockSizeMin
public long getBlockSizeMin()
Description copied from interface:GarbageCollectableBlobStore
Get the minimum block size (if there is any).- Specified by:
getBlockSizeMin
in interfaceGarbageCollectableBlobStore
- Returns:
- the block size
-
getAllChunkIds
public Iterator<String> getAllChunkIds(long maxLastModifiedTime) throws Exception
Description copied from interface:GarbageCollectableBlobStore
Gets all the identifiers.- Specified by:
getAllChunkIds
in 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
public boolean deleteChunks(List<String> chunkIds, long maxLastModifiedTime) throws Exception
Description copied from interface:GarbageCollectableBlobStore
Deletes the blobs with the given ids.- Specified by:
deleteChunks
in 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
public long countDeleteChunks(List<String> chunkIds, long maxLastModifiedTime) throws Exception
Description copied from interface:GarbageCollectableBlobStore
Deletes the blobs with the given ids.- Specified by:
countDeleteChunks
in 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
public Iterator<String> resolveChunks(String blobId) throws IOException
Description copied from interface:GarbageCollectableBlobStore
Resolve chunks stored in the blob store from the given Id. This will not return any chunks stored in-line in the id.- Specified by:
resolveChunks
in interfaceGarbageCollectableBlobStore
- Parameters:
blobId
- the blob id- Returns:
- the iterator
- Throws:
IOException
- Signals that an I/O exception has occurred.
-
addMetadataRecord
public void addMetadataRecord(InputStream stream, String name) throws DataStoreException
Description copied from interface:SharedDataStore
Adds the root record.- Specified by:
addMetadataRecord
in interfaceSharedDataStore
- Parameters:
stream
- the streamname
- the name of the root record- Throws:
DataStoreException
- the data store exception
-
addMetadataRecord
public void addMetadataRecord(File f, String name) throws DataStoreException
Description copied from interface:SharedDataStore
Adds the root record.- Specified by:
addMetadataRecord
in interfaceSharedDataStore
- Parameters:
f
- the filename
- the name of the root record- Throws:
DataStoreException
- the data store exception
-
getMetadataRecord
public DataRecord getMetadataRecord(String name)
Description copied from interface:SharedDataStore
Retrieves the metadata record with the given name- Specified by:
getMetadataRecord
in interfaceSharedDataStore
- Parameters:
name
- the name of the record- Returns:
-
metadataRecordExists
public boolean metadataRecordExists(String name)
Description copied from interface:SharedDataStore
Checks if the metadata record with the name exists- Specified by:
metadataRecordExists
in interfaceSharedDataStore
- Returns:
-
getAllMetadataRecords
public List<DataRecord> getAllMetadataRecords(String prefix)
Description copied from interface:SharedDataStore
Gets the all root records.- Specified by:
getAllMetadataRecords
in interfaceSharedDataStore
- Returns:
- the all root records
-
deleteMetadataRecord
public boolean deleteMetadataRecord(String name)
Description copied from interface:SharedDataStore
Deletes the root record represented by the given parameters.- Specified by:
deleteMetadataRecord
in interfaceSharedDataStore
- Parameters:
name
- the name of the root record- Returns:
- success/failure
-
deleteAllMetadataRecords
public void deleteAllMetadataRecords(String prefix)
Description copied from interface:SharedDataStore
Deletes all records matching the given prefix.- Specified by:
deleteAllMetadataRecords
in interfaceSharedDataStore
- Parameters:
prefix
- metadata type identifier
-
setRepositoryId
public void setRepositoryId(String repositoryId) throws DataStoreException
Description copied from interface:SharedDataStore
Sets the repository id to identify repository in the DataStore- Specified by:
setRepositoryId
in interfaceSharedDataStore
- Throws:
DataStoreException
-
getRepositoryId
public String getRepositoryId()
Description copied from interface:SharedDataStore
Returns the repository id (identifier for the repository in the DataStore)- Specified by:
getRepositoryId
in interfaceSharedDataStore
- Returns:
- repository id
-
getAllRecords
public Iterator<DataRecord> getAllRecords() throws DataStoreException
Description copied from interface:SharedDataStore
Retrieved an iterator over all DataRecords.- Specified by:
getAllRecords
in interfaceSharedDataStore
- Returns:
- iterator over DataRecords
- Throws:
DataStoreException
-
getRecordForId
public DataRecord getRecordForId(DataIdentifier identifier) throws DataStoreException
Description copied from interface:SharedDataStore
Retrieves the record for the given identifier- Specified by:
getRecordForId
in interfaceSharedDataStore
- Parameters:
identifier
- the if of the record- Returns:
- data record
- Throws:
DataStoreException
-
getType
public SharedDataStore.Type getType()
Description copied from interface:SharedDataStore
Gets the type.- Specified by:
getType
in interfaceSharedDataStore
- Returns:
- the type
-
addRecord
public DataRecord addRecord(InputStream input, BlobOptions options) throws DataStoreException
Description copied from interface:TypedDataStore
Add a record with specified options.- Specified by:
addRecord
in interfaceTypedDataStore
- Returns:
- Throws:
DataStoreException
-
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:BlobTrackingStore
Registers a tracker in the data store.- Specified by:
addTracker
in interfaceBlobTrackingStore
-
getTracker
@Nullable public @Nullable BlobTracker getTracker()
Description copied from interface:BlobTrackingStore
Gets the traker registered in the data store.- Specified by:
getTracker
in interfaceBlobTrackingStore
- Returns:
- tracker
-
initiateBlobUpload
@Nullable public @Nullable org.apache.jackrabbit.oak.api.blob.BlobUpload initiateBlobUpload(long maxUploadSizeInBytes, int maxNumberOfURIs) throws IllegalArgumentException
- Specified by:
initiateBlobUpload
in 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:
initiateBlobUpload
in interfaceorg.apache.jackrabbit.oak.api.blob.BlobAccessProvider
- Throws:
IllegalArgumentException
-
completeBlobUpload
@Nullable public @Nullable Blob completeBlobUpload(@NotNull @NotNull String uploadToken) throws IllegalArgumentException
- Specified by:
completeBlobUpload
in interfaceorg.apache.jackrabbit.oak.api.blob.BlobAccessProvider
- Throws:
IllegalArgumentException
-
-