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, getReferenceFromIdentifier
protected 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
DataIdentifier
protected Backend backend
protected abstract Backend createBackend()
protected abstract String getMarkerFile()
public void init(String homeDir) throws RepositoryException
init
in interface DataStore
homeDir
- the home directory of the repositoryRepositoryException
public 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 DataStore
input
- binary streamCachingDataRecord
DataStoreException
- if the record could not be created.public DataRecord getRecord(DataIdentifier identifier) throws DataStoreException
DataStore
getRecord
in interface DataStore
getRecord
in class AbstractDataStore
identifier
- data identifierDataStoreException
- if the data store could not be accessed,
or if the given identifier is invalidpublic DataRecord getRecordIfStored(DataIdentifier identifier) throws DataStoreException
Backend
getRecordIfStored
in interface DataStore
identifier
- identifier of record.CachingDataRecord
or null.DataStoreException
- if the data store could not be accessedpublic void updateModifiedDateOnAccess(long before)
DataStore
updateModifiedDateOnAccess
in interface DataStore
before
- - update the modified date to the current time if it is older than this valuepublic Iterator<DataIdentifier> getAllIdentifiers() throws DataStoreException
Backend
.getAllIdentifiers
in interface DataStore
DataStoreException
- if the list could not be readpublic void deleteRecord(DataIdentifier identifier) throws DataStoreException
Backend
and then from
LocalCache
deleteRecord
in interface MultiDataStoreAware
identifier
- data identifierDataStoreException
- if the data store could not be accessed, or if the given
identifier is invalidpublic int deleteAllOlderThan(long min) throws DataStoreException
DataStore
deleteAllOlderThan
in interface DataStore
min
- the minimum timeDataStoreException
public long getLastModified(DataIdentifier identifier) throws DataStoreException
DataStoreException
public long getLength(DataIdentifier identifier) throws DataStoreException
LocalCache
if available,
otherwise retrieve it from Backend
.DataStoreException
protected byte[] getOrCreateReferenceKey() throws DataStoreException
AbstractDataStore
This 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 AbstractDataStore
DataStoreException
- if the key is not availablepublic void deleteFromCache(DataIdentifier identifier) throws DataStoreException
DataStoreException
public void onSuccess(AsyncUploadResult result)
AsyncUploadCallback
onSuccess
in interface AsyncUploadCallback
public void onFailure(AsyncUploadResult result)
AsyncUploadCallback
onFailure
in interface AsyncUploadCallback
public void onAbort(AsyncUploadResult result)
AsyncUploadCallback
onAbort
in interface AsyncUploadCallback
public void onSuccess(AsyncTouchResult result)
AsyncTouchCallback
onSuccess
in interface AsyncTouchCallback
public void onFailure(AsyncTouchResult result)
AsyncTouchCallback
onFailure
in interface AsyncTouchCallback
public void onAbort(AsyncTouchResult result)
AsyncTouchCallback
onAbort
in interface AsyncTouchCallback
public boolean confirmDelete(DataIdentifier identifier)
Backend
identifier
- public void clearInUse()
DataStore
clearInUse
in interface DataStore
public boolean isInUse(DataIdentifier identifier)
public void close() throws DataStoreException
DataStore
close
in interface DataStore
DataStoreException
- 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 DataStore
public 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–2021 The Apache Software Foundation. All rights reserved.