public abstract class CachingDataStore extends AbstractDataStore implements MultiDataStoreAware, AsyncUploadCallback, AsyncTouchCallback
LocalCache and Backend.
Backend is single source of truth. All methods first try to fetch
information from LocalCache. If record is not available in
LocalCache, then it is fetched from Backend and saved to
LocalCache for further access. This class is designed to work without
LocalCache and then all information is fetched from Backend.
To disable LocalCache set setCacheSize(long) to 0. *
Configuration:
<DataStore class="org.apache.jackrabbit.aws.ext.ds.CachingDataStore">
<param name="path" value="/data/datastore"/>
<param name="config" value="${rep.home}/backend.properties"/>
<param name="cacheSize" value="68719476736"/>
<param name="secret" value="123456"/>
<param name="setCachePurgeTrigFactor(double)" value="0.95d"/>
<param name="cacheSize" value="0.85d"/>
<param name="minRecordLength" value="1024"/>
<param name="continueOnAsyncUploadFailure" value="false"/>
<param name="concurrentUploadsThreads" value="10"/>
<param name="asyncUploadLimit" value="100"/>
<param name="uploadRetries" value="3"/>
<param name="touchAsync" value="false"/>
<param name="proactiveCaching" value="true"/>
<param name="recLengthCacheSize" value="200"/>
</DataStore>
| Modifier and Type | Field and Description |
|---|---|
protected Map<DataIdentifier,Long> |
asyncDownloadCache
In memory map to hold in-progress asynchronous downloads.
|
protected Map<DataIdentifier,Long> |
asyncTouchCache
In memory map to hold in-progress asynchronous touch.
|
protected Backend |
backend |
protected Map<DataIdentifier,WeakReference<DataIdentifier>> |
inUse
All data identifiers that are currently in use are in this set until they
are garbage collected.
|
protected Map<DataIdentifier,Long> |
recLenCache
In memory cache to hold
DataRecord.getLength() against
DataIdentifier |
protected Map<DataIdentifier,Integer> |
uploadRetryMap
In memory map to hold failed asynchronous upload
DataIdentifier
and its retry count. |
DIGEST| Constructor and Description |
|---|
CachingDataStore() |
| Modifier and Type | Method and Description |
|---|---|
DataRecord |
addRecord(InputStream input)
Creates a new data record in
Backend. |
void |
clearInUse()
Clear the in-use list.
|
void |
close()
Close the data store
|
boolean |
confirmDelete(DataIdentifier identifier)
Method to confirm that identifier can be deleted from
Backend |
protected abstract Backend |
createBackend() |
int |
deleteAllOlderThan(long min)
Delete objects that have a modified date older than the specified date.
|
void |
deleteFromCache(DataIdentifier identifier) |
void |
deleteRecord(DataIdentifier identifier)
This method deletes record from
Backend and then from
LocalCache |
Iterator<DataIdentifier> |
getAllIdentifiers()
Retrieves all identifiers from
Backend. |
int |
getAsyncUploadLimit() |
Backend |
getBackend() |
double |
getCachePurgeResizeFactor() |
double |
getCachePurgeTrigFactor() |
long |
getCacheSize() |
int |
getConcurrentUploadsThreads() |
String |
getConfig()
Return path of configuration properties.
|
long |
getLastModified(DataIdentifier identifier)
|
long |
getLength(DataIdentifier identifier)
Return the length of record from
LocalCache if available,
otherwise retrieve it from Backend. |
protected abstract String |
getMarkerFile() |
int |
getMinRecordLength()
Return mininum object length.
|
protected byte[] |
getOrCreateReferenceKey()
Returns the reference key of this data store.
|
String |
getPath() |
Set<String> |
getPendingUploads() |
DataRecord |
getRecord(DataIdentifier identifier)
Returns the identified data record.
|
DataRecord |
getRecordIfStored(DataIdentifier identifier)
Get a data record for the given identifier or null it data record doesn't
exist in
Backend |
int |
getUploadRetries() |
void |
init(String homeDir)
Initialized the data store.
|
boolean |
isContinueOnAsyncUploadFailure() |
boolean |
isInUse(DataIdentifier identifier) |
void |
onAbort(AsyncTouchResult result)
Callback method for aborted asynchronous touch.
|
void |
onAbort(AsyncUploadResult result)
Callback method for aborted asynchronous upload.
|
void |
onFailure(AsyncTouchResult result)
Callback method for failed asynchronous touch.
|
void |
onFailure(AsyncUploadResult result)
Callback method for failed asynchronous upload.
|
void |
onSuccess(AsyncTouchResult result)
Callback method for successful asynchronous touch.
|
void |
onSuccess(AsyncUploadResult result)
Callback method for successful asynchronous upload.
|
void |
setAsyncUploadLimit(int asyncUploadLimit) |
void |
setCachePurgeResizeFactor(double cachePurgeResizeFactor)
Set purge resize factor of
LocalCache. |
void |
setCachePurgeTrigFactor(double cachePurgeTrigFactor)
Set purge trigger factor of
LocalCache. |
void |
setCacheSize(long cacheSize)
Set size of
LocalCache. |
void |
setConcurrentUploadsThreads(int concurrentUploadsThreads) |
void |
setConfig(String config)
Set the configuration properties path.
|
void |
setContinueOnAsyncUploadFailure(boolean continueOnAsyncUploadFailure) |
void |
setMinRecordLength(int minRecordLength)
Set the minimum object length.
|
void |
setPath(String path)
Set path of
LocalCache. |
void |
setProactiveCaching(boolean proactiveCaching) |
void |
setRecLengthCacheSize(int recLengthCacheSize) |
void |
setSecret(String secret)
Setter for configuration based secret
|
void |
setTouchAsync(boolean touchAsync) |
void |
setUploadRetries(int uploadRetries) |
void |
updateModifiedDateOnAccess(long before)
From now on, update the modified date of an object even when accessing it.
|
encodeHexString, getRecordFromReference, getReferenceFromIdentifierprotected Map<DataIdentifier,WeakReference<DataIdentifier>> inUse
protected final Map<DataIdentifier,Integer> uploadRetryMap
DataIdentifier
and its retry count. Once if all retries are exhausted or file is
successfully uploaded, then corresponding entry is flushed from the map.
As all failed uploads are synchronously uploaded at startup, this map
is not required to be persisted.protected final Map<DataIdentifier,Long> asyncTouchCache
protected final Map<DataIdentifier,Long> asyncDownloadCache
protected Map<DataIdentifier,Long> recLenCache
DataRecord.getLength() against
DataIdentifierprotected Backend backend
protected abstract Backend createBackend()
protected abstract String getMarkerFile()
public void init(String homeDir) throws RepositoryException
init in interface DataStorehomeDir - the home directory of the repositoryRepositoryExceptionpublic DataRecord addRecord(InputStream input) throws DataStoreException
Backend. The stream is first
consumed and the contents are saved in a temporary file and the AbstractDataStore.DIGEST
message digest of the stream is calculated. If a record with the same
AbstractDataStore.DIGEST digest (and length) is found then it is returned. Otherwise new
record is created in Backend and the temporary file is moved in
place to LocalCache.addRecord in interface DataStoreinput - binary streamCachingDataRecordDataStoreException - if the record could not be created.public DataRecord getRecord(DataIdentifier identifier) throws DataStoreException
DataStoregetRecord in interface DataStoregetRecord in class AbstractDataStoreidentifier - data identifierDataStoreException - if the data store could not be accessed,
or if the given identifier is invalidpublic DataRecord getRecordIfStored(DataIdentifier identifier) throws DataStoreException
BackendgetRecordIfStored in interface DataStoreidentifier - identifier of record.CachingDataRecord or null.DataStoreException - if the data store could not be accessedpublic void updateModifiedDateOnAccess(long before)
DataStoreupdateModifiedDateOnAccess in interface DataStorebefore - - update the modified date to the current time if it is older than this valuepublic Iterator<DataIdentifier> getAllIdentifiers() throws DataStoreException
Backend.getAllIdentifiers in interface DataStoreDataStoreException - if the list could not be readpublic void deleteRecord(DataIdentifier identifier) throws DataStoreException
Backend and then from
LocalCachedeleteRecord in interface MultiDataStoreAwareidentifier - data identifierDataStoreException - if the data store could not be accessed, or if the given
identifier is invalidpublic int deleteAllOlderThan(long min)
throws DataStoreException
DataStoredeleteAllOlderThan in interface DataStoremin - the minimum timeDataStoreExceptionpublic long getLastModified(DataIdentifier identifier) throws DataStoreException
DataStoreExceptionpublic long getLength(DataIdentifier identifier) throws DataStoreException
LocalCache if available,
otherwise retrieve it from Backend.DataStoreExceptionprotected byte[] getOrCreateReferenceKey()
throws DataStoreException
AbstractDataStoreThis method is called only once during the lifetime of a data store instance and the return value is cached in memory, so it's no problem if the implementation is slow.
getOrCreateReferenceKey in class AbstractDataStoreDataStoreException - if the key is not availablepublic void deleteFromCache(DataIdentifier identifier) throws DataStoreException
DataStoreExceptionpublic void onSuccess(AsyncUploadResult result)
AsyncUploadCallbackonSuccess in interface AsyncUploadCallbackpublic void onFailure(AsyncUploadResult result)
AsyncUploadCallbackonFailure in interface AsyncUploadCallbackpublic void onAbort(AsyncUploadResult result)
AsyncUploadCallbackonAbort in interface AsyncUploadCallbackpublic void onSuccess(AsyncTouchResult result)
AsyncTouchCallbackonSuccess in interface AsyncTouchCallbackpublic void onFailure(AsyncTouchResult result)
AsyncTouchCallbackonFailure in interface AsyncTouchCallbackpublic void onAbort(AsyncTouchResult result)
AsyncTouchCallbackonAbort in interface AsyncTouchCallbackpublic boolean confirmDelete(DataIdentifier identifier)
Backendidentifier - public void clearInUse()
DataStoreclearInUse in interface DataStorepublic boolean isInUse(DataIdentifier identifier)
public void close()
throws DataStoreException
DataStoreclose in interface DataStoreDataStoreException - if a problem occurredpublic void setSecret(String secret)
secret - the secret used to sign reference binariespublic void setMinRecordLength(int minRecordLength)
minRecordLength - the lengthpublic int getMinRecordLength()
getMinRecordLength in interface DataStorepublic String getConfig()
public void setConfig(String config)
config - path of configuration properties.public long getCacheSize()
LocalCache.public void setCacheSize(long cacheSize)
LocalCache.cacheSize - size of LocalCache.public String getPath()
LocalCache.public void setPath(String path)
LocalCache.path - of LocalCache.public double getCachePurgeTrigFactor()
LocalCache.public void setCachePurgeTrigFactor(double cachePurgeTrigFactor)
LocalCache.cachePurgeTrigFactor - purge trigger factor.public double getCachePurgeResizeFactor()
LocalCache.public void setCachePurgeResizeFactor(double cachePurgeResizeFactor)
LocalCache.cachePurgeResizeFactor - purge resize factor.public int getConcurrentUploadsThreads()
public void setConcurrentUploadsThreads(int concurrentUploadsThreads)
public int getAsyncUploadLimit()
public void setAsyncUploadLimit(int asyncUploadLimit)
public boolean isContinueOnAsyncUploadFailure()
public void setContinueOnAsyncUploadFailure(boolean continueOnAsyncUploadFailure)
public int getUploadRetries()
public void setUploadRetries(int uploadRetries)
public void setTouchAsync(boolean touchAsync)
public void setProactiveCaching(boolean proactiveCaching)
public void setRecLengthCacheSize(int recLengthCacheSize)
public Backend getBackend()
Copyright © 2004–2022 The Apache Software Foundation. All rights reserved.