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
,org.apache.jackrabbit.oak.spi.blob.BlobStore
,org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore
public class DataStoreBlobStore extends java.lang.Object implements DataStore, org.apache.jackrabbit.oak.spi.blob.BlobStore, org.apache.jackrabbit.oak.spi.blob.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 protected org.apache.jackrabbit.guava.common.cache.LoadingCache<java.lang.String,byte[]>
cache
static int
DEFAULT_CACHE_SIZE
protected DataStore
delegate
static java.lang.String
MEM_CACHE_NAME
protected org.apache.jackrabbit.oak.spi.blob.stats.BlobStatsCollector
stats
-
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(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, org.apache.jackrabbit.oak.spi.blob.BlobOptions options)
Add a record with specified options.void
addTracker(BlobTracker tracker)
Registers a tracker in the data store.void
clearCache()
void
clearInUse()
void
close()
@Nullable org.apache.jackrabbit.oak.api.Blob
completeBlobUpload(@NotNull java.lang.String uploadToken)
long
countDeleteChunks(java.util.List<java.lang.String> chunkIds, long maxLastModifiedTime)
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)
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)
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)
long
getBlobLength(java.lang.String encodedBlobId)
long
getBlockSizeMin()
org.apache.jackrabbit.oak.cache.CacheStats
getCacheStats()
protected DataRecord
getDataRecord(java.lang.String blobId)
DataStore
getDataStore()
@Nullable java.net.URI
getDownloadURI(@NotNull org.apache.jackrabbit.oak.api.Blob blob, @NotNull org.apache.jackrabbit.oak.api.blob.BlobDownloadOptions downloadOptions)
java.io.InputStream
getInputStream(java.lang.String encodedBlobId)
DataRecord
getMetadataRecord(java.lang.String name)
Retrieves the metadata record with the given nameint
getMinRecordLength()
DataRecord
getRecord(DataIdentifier identifier)
DataRecord
getRecordForId(DataIdentifier identifier)
Retrieves the record for the given identifierDataRecord
getRecordFromReference(java.lang.String reference)
DataRecord
getRecordIfStored(DataIdentifier identifier)
java.lang.String
getReference(@NotNull java.lang.String encodedBlobId)
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 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(java.lang.String name)
Checks if the metadata record with the name existsint
readBlob(java.lang.String encodedBlobId, long pos, byte[] buff, int off, int length)
java.util.Iterator<java.lang.String>
resolveChunks(java.lang.String blobId)
void
setBlobStatsCollector(org.apache.jackrabbit.oak.spi.blob.stats.BlobStatsCollector stats)
void
setBlockSize(int x)
void
setMaxCachedBinarySize(int maxCachedBinarySize)
void
setRepositoryId(java.lang.String repositoryId)
Sets the repository id to identify repository in the DataStorevoid
startMark()
int
sweep()
java.lang.String
toString()
void
updateModifiedDateOnAccess(long before)
java.lang.String
writeBlob(java.io.InputStream stream)
java.lang.String
writeBlob(java.io.InputStream stream, org.apache.jackrabbit.oak.spi.blob.BlobOptions options)
java.lang.String
writeBlob(java.lang.String tempFileName)
-
-
-
Field Detail
-
delegate
protected final DataStore delegate
-
stats
protected org.apache.jackrabbit.oak.spi.blob.stats.BlobStatsCollector stats
-
cache
protected final org.apache.jackrabbit.guava.common.cache.LoadingCache<java.lang.String,byte[]> cache
-
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
- Specified by:
getRecordIfStored
in interfaceDataStore
- Throws:
DataStoreException
-
getRecord
public DataRecord getRecord(DataIdentifier identifier) throws DataStoreException
- Specified by:
getRecord
in interfaceDataStore
- Throws:
DataStoreException
-
getRecordFromReference
public DataRecord getRecordFromReference(java.lang.String reference) throws DataStoreException
- Specified by:
getRecordFromReference
in interfaceDataStore
- Throws:
DataStoreException
-
addRecord
public DataRecord addRecord(java.io.InputStream stream) throws DataStoreException
- Specified by:
addRecord
in interfaceDataStore
- Throws:
DataStoreException
-
updateModifiedDateOnAccess
public void updateModifiedDateOnAccess(long before)
- Specified by:
updateModifiedDateOnAccess
in interfaceDataStore
-
deleteAllOlderThan
public int deleteAllOlderThan(long min) throws DataStoreException
- Specified by:
deleteAllOlderThan
in interfaceDataStore
- Throws:
DataStoreException
-
getAllIdentifiers
public java.util.Iterator<DataIdentifier> getAllIdentifiers() throws DataStoreException
- Specified by:
getAllIdentifiers
in interfaceDataStore
- Throws:
DataStoreException
-
init
public void init(java.lang.String homeDir) throws javax.jcr.RepositoryException
-
getMinRecordLength
public int getMinRecordLength()
- Specified by:
getMinRecordLength
in interfaceDataStore
-
close
public void close() throws DataStoreException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceDataStore
- Throws:
DataStoreException
-
writeBlob
public java.lang.String writeBlob(java.io.InputStream stream) throws java.io.IOException
- Specified by:
writeBlob
in interfaceorg.apache.jackrabbit.oak.spi.blob.BlobStore
- Throws:
java.io.IOException
-
writeBlob
public java.lang.String writeBlob(java.io.InputStream stream, org.apache.jackrabbit.oak.spi.blob.BlobOptions options) throws java.io.IOException
- Specified by:
writeBlob
in interfaceorg.apache.jackrabbit.oak.spi.blob.BlobStore
- Throws:
java.io.IOException
-
readBlob
public int readBlob(java.lang.String encodedBlobId, long pos, byte[] buff, int off, int length) throws java.io.IOException
- Specified by:
readBlob
in interfaceorg.apache.jackrabbit.oak.spi.blob.BlobStore
- Throws:
java.io.IOException
-
getBlobLength
public long getBlobLength(java.lang.String encodedBlobId) throws java.io.IOException
- Specified by:
getBlobLength
in interfaceorg.apache.jackrabbit.oak.spi.blob.BlobStore
- Throws:
java.io.IOException
-
getBlobId
public java.lang.String getBlobId(@NotNull @NotNull java.lang.String reference)
- Specified by:
getBlobId
in interfaceorg.apache.jackrabbit.oak.spi.blob.BlobStore
-
getReference
public java.lang.String getReference(@NotNull @NotNull java.lang.String encodedBlobId)
- Specified by:
getReference
in interfaceorg.apache.jackrabbit.oak.spi.blob.BlobStore
-
getInputStream
public java.io.InputStream getInputStream(java.lang.String encodedBlobId) throws java.io.IOException
- Specified by:
getInputStream
in interfaceorg.apache.jackrabbit.oak.spi.blob.BlobStore
- Throws:
java.io.IOException
-
setBlockSize
public void setBlockSize(int x)
- Specified by:
setBlockSize
in interfaceorg.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore
-
writeBlob
public java.lang.String writeBlob(java.lang.String tempFileName) throws java.io.IOException
- Specified by:
writeBlob
in interfaceorg.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore
- Throws:
java.io.IOException
-
sweep
public int sweep() throws java.io.IOException
- Specified by:
sweep
in interfaceorg.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore
- Throws:
java.io.IOException
-
startMark
public void startMark() throws java.io.IOException
- Specified by:
startMark
in interfaceorg.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore
- Throws:
java.io.IOException
-
clearInUse
public void clearInUse()
- Specified by:
clearInUse
in interfaceDataStore
- Specified by:
clearInUse
in interfaceorg.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore
-
clearCache
public void clearCache()
- Specified by:
clearCache
in interfaceorg.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore
-
getBlockSizeMin
public long getBlockSizeMin()
- Specified by:
getBlockSizeMin
in interfaceorg.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore
-
getAllChunkIds
public java.util.Iterator<java.lang.String> getAllChunkIds(long maxLastModifiedTime) throws java.lang.Exception
- Specified by:
getAllChunkIds
in interfaceorg.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore
- Throws:
java.lang.Exception
-
deleteChunks
public boolean deleteChunks(java.util.List<java.lang.String> chunkIds, long maxLastModifiedTime) throws java.lang.Exception
- Specified by:
deleteChunks
in interfaceorg.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore
- Throws:
java.lang.Exception
-
countDeleteChunks
public long countDeleteChunks(java.util.List<java.lang.String> chunkIds, long maxLastModifiedTime) throws java.lang.Exception
- Specified by:
countDeleteChunks
in interfaceorg.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore
- Throws:
java.lang.Exception
-
resolveChunks
public java.util.Iterator<java.lang.String> resolveChunks(java.lang.String blobId) throws java.io.IOException
- Specified by:
resolveChunks
in interfaceorg.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore
- Throws:
java.io.IOException
-
addMetadataRecord
public void addMetadataRecord(java.io.InputStream stream, java.lang.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(java.io.File f, java.lang.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(java.lang.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(java.lang.String name)
Description copied from interface:SharedDataStore
Checks if the metadata record with the name exists- Specified by:
metadataRecordExists
in interfaceSharedDataStore
- Returns:
-
getAllMetadataRecords
public java.util.List<DataRecord> getAllMetadataRecords(java.lang.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(java.lang.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(java.lang.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(java.lang.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 java.lang.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 java.util.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(java.io.InputStream input, org.apache.jackrabbit.oak.spi.blob.BlobOptions options) throws DataStoreException
Description copied from interface:TypedDataStore
Add a record with specified options.- Specified by:
addRecord
in interfaceTypedDataStore
- Returns:
- Throws:
DataStoreException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getDataStore
public DataStore getDataStore()
-
getCacheStats
public org.apache.jackrabbit.oak.cache.CacheStats getCacheStats()
-
setMaxCachedBinarySize
public void setMaxCachedBinarySize(int maxCachedBinarySize)
-
setBlobStatsCollector
public void setBlobStatsCollector(org.apache.jackrabbit.oak.spi.blob.stats.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
-
getStream
protected java.io.InputStream getStream(java.lang.String blobId) throws java.io.IOException
- Throws:
java.io.IOException
-
getDataRecord
protected DataRecord getDataRecord(java.lang.String blobId) throws DataStoreException
- Throws:
DataStoreException
-
extractBlobId
protected java.lang.String extractBlobId(java.lang.String encodedBlobId)
-
initiateBlobUpload
@Nullable public @Nullable org.apache.jackrabbit.oak.api.blob.BlobUpload initiateBlobUpload(long maxUploadSizeInBytes, int maxNumberOfURIs) throws java.lang.IllegalArgumentException
- Specified by:
initiateBlobUpload
in 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:
initiateBlobUpload
in interfaceorg.apache.jackrabbit.oak.api.blob.BlobAccessProvider
- Throws:
java.lang.IllegalArgumentException
-
completeBlobUpload
@Nullable public @Nullable org.apache.jackrabbit.oak.api.Blob completeBlobUpload(@NotNull @NotNull java.lang.String uploadToken) throws java.lang.IllegalArgumentException
- Specified by:
completeBlobUpload
in interfaceorg.apache.jackrabbit.oak.api.blob.BlobAccessProvider
- Throws:
java.lang.IllegalArgumentException
-
getDownloadURI
@Nullable public @Nullable java.net.URI getDownloadURI(@NotNull @NotNull org.apache.jackrabbit.oak.api.Blob blob, @NotNull @NotNull org.apache.jackrabbit.oak.api.blob.BlobDownloadOptions downloadOptions)
- Specified by:
getDownloadURI
in interfaceorg.apache.jackrabbit.oak.api.blob.BlobAccessProvider
-
-