Package org.apache.jackrabbit.core.data
Class CachingDataStore
java.lang.Object
org.apache.jackrabbit.core.data.AbstractDataStore
org.apache.jackrabbit.core.data.CachingDataStore
- All Implemented Interfaces:
AsyncTouchCallback,AsyncUploadCallback,DataStore,MultiDataStoreAware
- Direct Known Subclasses:
CachingFDS
public abstract class CachingDataStore
extends AbstractDataStore
implements MultiDataStoreAware, AsyncUploadCallback, AsyncTouchCallback
A caching data store that consists of
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>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddRecord(InputStream input) Creates a new data record inBackend.voidClear the in-use list.voidclose()Close the data storebooleanconfirmDelete(DataIdentifier identifier) Method to confirm that identifier can be deleted fromBackendintdeleteAllOlderThan(long min) Delete objects that have a modified date older than the specified date.voiddeleteFromCache(DataIdentifier identifier) voiddeleteRecord(DataIdentifier identifier) This method deletes record fromBackendand then fromLocalCacheRetrieves all identifiers fromBackend.intdoubledoublelongintReturn path of configuration properties.longgetLastModified(DataIdentifier identifier) longgetLength(DataIdentifier identifier) Return the length of record fromLocalCacheif available, otherwise retrieve it fromBackend.intReturn mininum object length.getPath()getRecord(DataIdentifier identifier) Returns the identified data record.getRecordIfStored(DataIdentifier identifier) Get a data record for the given identifier or null it data record doesn't exist inBackendintvoidInitialized the data store.booleanbooleanisInUse(DataIdentifier identifier) voidonAbort(AsyncTouchResult result) Callback method for aborted asynchronous touch.voidonAbort(AsyncUploadResult result) Callback method for aborted asynchronous upload.voidonFailure(AsyncTouchResult result) Callback method for failed asynchronous touch.voidonFailure(AsyncUploadResult result) Callback method for failed asynchronous upload.voidonSuccess(AsyncTouchResult result) Callback method for successful asynchronous touch.voidonSuccess(AsyncUploadResult result) Callback method for successful asynchronous upload.voidsetAsyncUploadLimit(int asyncUploadLimit) voidsetCachePurgeResizeFactor(double cachePurgeResizeFactor) Set purge resize factor ofLocalCache.voidsetCachePurgeTrigFactor(double cachePurgeTrigFactor) Set purge trigger factor ofLocalCache.voidsetCacheSize(long cacheSize) Set size ofLocalCache.voidsetConcurrentUploadsThreads(int concurrentUploadsThreads) voidSet the configuration properties path.voidsetContinueOnAsyncUploadFailure(boolean continueOnAsyncUploadFailure) voidsetMinRecordLength(int minRecordLength) Set the minimum object length.voidSet path ofLocalCache.voidsetProactiveCaching(boolean proactiveCaching) voidsetRecLengthCacheSize(int recLengthCacheSize) voidSetter for configuration based secretvoidsetTouchAsync(boolean touchAsync) voidsetUploadRetries(int uploadRetries) voidupdateModifiedDateOnAccess(long before) From now on, update the modified date of an object even when accessing it.Methods inherited from class org.apache.jackrabbit.core.data.AbstractDataStore
getRecordFromReference
-
Constructor Details
-
CachingDataStore
public CachingDataStore()
-
-
Method Details
-
init
Initialized the data store. If the path is not set, <repository home>/repository/datastore is used. This directory is automatically created if it does not yet exist. During first initialization, it upload all files from local datastore to backed and local datastore act as a local cache.- Specified by:
initin interfaceDataStore- Parameters:
homeDir- the home directory of the repository- Throws:
RepositoryException
-
addRecord
Creates a new data record inBackend. The stream is first consumed and the contents are saved in a temporary file and theAbstractDataStore.DIGESTmessage digest of the stream is calculated. If a record with the sameAbstractDataStore.DIGESTdigest (and length) is found then it is returned. Otherwise new record is created inBackendand the temporary file is moved in place toLocalCache.- Specified by:
addRecordin interfaceDataStore- Parameters:
input- binary stream- Returns:
CachingDataRecord- Throws:
DataStoreException- if the record could not be created.
-
getRecord
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- Overrides:
getRecordin classAbstractDataStore- 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
-
getRecordIfStored
Get a data record for the given identifier or null it data record doesn't exist inBackend- Specified by:
getRecordIfStoredin interfaceDataStore- Parameters:
identifier- identifier of record.- Returns:
- the
CachingDataRecordor null. - 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
-
getAllIdentifiers
Retrieves all identifiers fromBackend.- Specified by:
getAllIdentifiersin interfaceDataStore- Returns:
- an iterator over all DataIdentifier objects
- Throws:
DataStoreException- if the list could not be read
-
deleteRecord
This method deletes record fromBackendand then fromLocalCache- Specified by:
deleteRecordin interfaceMultiDataStoreAware- Parameters:
identifier- data identifier- Throws:
DataStoreException- if the data store could not be accessed, or if the given identifier is invalid
-
deleteAllOlderThan
Description 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
-
getLastModified
- Throws:
DataStoreException
-
getLength
Return the length of record fromLocalCacheif available, otherwise retrieve it fromBackend.- Throws:
DataStoreException
-
getPendingUploads
-
deleteFromCache
- Throws:
DataStoreException
-
onSuccess
Description copied from interface:AsyncUploadCallbackCallback method for successful asynchronous upload.- Specified by:
onSuccessin interfaceAsyncUploadCallback
-
onFailure
Description copied from interface:AsyncUploadCallbackCallback method for failed asynchronous upload.- Specified by:
onFailurein interfaceAsyncUploadCallback
-
onAbort
Description copied from interface:AsyncUploadCallbackCallback method for aborted asynchronous upload.- Specified by:
onAbortin interfaceAsyncUploadCallback
-
onSuccess
Description copied from interface:AsyncTouchCallbackCallback method for successful asynchronous touch.- Specified by:
onSuccessin interfaceAsyncTouchCallback
-
onFailure
Description copied from interface:AsyncTouchCallbackCallback method for failed asynchronous touch.- Specified by:
onFailurein interfaceAsyncTouchCallback
-
onAbort
Description copied from interface:AsyncTouchCallbackCallback method for aborted asynchronous touch.- Specified by:
onAbortin interfaceAsyncTouchCallback
-
confirmDelete
Method to confirm that identifier can be deleted fromBackend- Parameters:
identifier-- Returns:
-
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
-
isInUse
-
close
Description copied from interface:DataStoreClose the data store- Specified by:
closein interfaceDataStore- Throws:
DataStoreException- if a problem occurred
-
setSecret
Setter for configuration based secret- Parameters:
secret- the secret used to sign reference binaries
-
setMinRecordLength
public void setMinRecordLength(int minRecordLength) Set the minimum object length.- Parameters:
minRecordLength- the length
-
getMinRecordLength
public int getMinRecordLength()Return mininum object length.- Specified by:
getMinRecordLengthin interfaceDataStore- Returns:
- the minimum size in bytes
-
getConfig
Return path of configuration properties.- Returns:
- path of configuration properties.
-
setConfig
Set the configuration properties path.- Parameters:
config- path of configuration properties.
-
getCacheSize
public long getCacheSize()- Returns:
- size of
LocalCache.
-
setCacheSize
public void setCacheSize(long cacheSize) Set size ofLocalCache.- Parameters:
cacheSize- size ofLocalCache.
-
getPath
- Returns:
- path of
LocalCache.
-
setPath
Set path ofLocalCache.- Parameters:
path- ofLocalCache.
-
getCachePurgeTrigFactor
public double getCachePurgeTrigFactor()- Returns:
- Purge trigger factor of
LocalCache.
-
setCachePurgeTrigFactor
public void setCachePurgeTrigFactor(double cachePurgeTrigFactor) Set purge trigger factor ofLocalCache.- Parameters:
cachePurgeTrigFactor- purge trigger factor.
-
getCachePurgeResizeFactor
public double getCachePurgeResizeFactor()- Returns:
- Purge resize factor of
LocalCache.
-
setCachePurgeResizeFactor
public void setCachePurgeResizeFactor(double cachePurgeResizeFactor) Set purge resize factor ofLocalCache.- Parameters:
cachePurgeResizeFactor- purge resize factor.
-
getConcurrentUploadsThreads
public int getConcurrentUploadsThreads() -
setConcurrentUploadsThreads
public void setConcurrentUploadsThreads(int concurrentUploadsThreads) -
getAsyncUploadLimit
public int getAsyncUploadLimit() -
setAsyncUploadLimit
public void setAsyncUploadLimit(int asyncUploadLimit) -
isContinueOnAsyncUploadFailure
public boolean isContinueOnAsyncUploadFailure() -
setContinueOnAsyncUploadFailure
public void setContinueOnAsyncUploadFailure(boolean continueOnAsyncUploadFailure) -
getUploadRetries
public int getUploadRetries() -
setUploadRetries
public void setUploadRetries(int uploadRetries) -
setTouchAsync
public void setTouchAsync(boolean touchAsync) -
setProactiveCaching
public void setProactiveCaching(boolean proactiveCaching) -
setRecLengthCacheSize
public void setRecLengthCacheSize(int recLengthCacheSize) -
getBackend
-