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 Details

    • CachingDataStore

      public CachingDataStore()
  • Method Details

    • init

      public void init(String homeDir) throws RepositoryException
      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:
      init in interface DataStore
      Parameters:
      homeDir - the home directory of the repository
      Throws:
      RepositoryException
    • addRecord

      public DataRecord addRecord(InputStream input) throws DataStoreException
      Creates a new data record in 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.
      Specified by:
      addRecord in interface DataStore
      Parameters:
      input - binary stream
      Returns:
      CachingDataRecord
      Throws:
      DataStoreException - if the record could not be created.
    • 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 interface DataStore
      Overrides:
      getRecord in class AbstractDataStore
      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

      public DataRecord getRecordIfStored(DataIdentifier identifier) throws DataStoreException
      Get a data record for the given identifier or null it data record doesn't exist in Backend
      Specified by:
      getRecordIfStored in interface DataStore
      Parameters:
      identifier - identifier of record.
      Returns:
      the CachingDataRecord or null.
      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 interface DataStore
      Parameters:
      before - - update the modified date to the current time if it is older than this value
    • getAllIdentifiers

      public Iterator<DataIdentifier> getAllIdentifiers() throws DataStoreException
      Retrieves all identifiers from Backend.
      Specified by:
      getAllIdentifiers in interface DataStore
      Returns:
      an iterator over all DataIdentifier objects
      Throws:
      DataStoreException - if the list could not be read
    • deleteRecord

      public void deleteRecord(DataIdentifier identifier) throws DataStoreException
      This method deletes record from Backend and then from LocalCache
      Specified by:
      deleteRecord in interface MultiDataStoreAware
      Parameters:
      identifier - data identifier
      Throws:
      DataStoreException - if the data store could not be accessed, or if the given identifier is invalid
    • 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 interface DataStore
      Parameters:
      min - the minimum time
      Returns:
      the number of data records deleted
      Throws:
      DataStoreException
    • getLastModified

      public long getLastModified(DataIdentifier identifier) throws DataStoreException
      Return lastModified of record from Backend assuming Backend as a single source of truth.
      Throws:
      DataStoreException
    • getLength

      public long getLength(DataIdentifier identifier) throws DataStoreException
      Return the length of record from LocalCache if available, otherwise retrieve it from Backend.
      Throws:
      DataStoreException
    • getPendingUploads

      public Set<String> getPendingUploads()
    • deleteFromCache

      public void deleteFromCache(DataIdentifier identifier) throws DataStoreException
      Throws:
      DataStoreException
    • onSuccess

      public void onSuccess(AsyncUploadResult result)
      Description copied from interface: AsyncUploadCallback
      Callback method for successful asynchronous upload.
      Specified by:
      onSuccess in interface AsyncUploadCallback
    • onFailure

      public void onFailure(AsyncUploadResult result)
      Description copied from interface: AsyncUploadCallback
      Callback method for failed asynchronous upload.
      Specified by:
      onFailure in interface AsyncUploadCallback
    • onAbort

      public void onAbort(AsyncUploadResult result)
      Description copied from interface: AsyncUploadCallback
      Callback method for aborted asynchronous upload.
      Specified by:
      onAbort in interface AsyncUploadCallback
    • onSuccess

      public void onSuccess(AsyncTouchResult result)
      Description copied from interface: AsyncTouchCallback
      Callback method for successful asynchronous touch.
      Specified by:
      onSuccess in interface AsyncTouchCallback
    • onFailure

      public void onFailure(AsyncTouchResult result)
      Description copied from interface: AsyncTouchCallback
      Callback method for failed asynchronous touch.
      Specified by:
      onFailure in interface AsyncTouchCallback
    • onAbort

      public void onAbort(AsyncTouchResult result)
      Description copied from interface: AsyncTouchCallback
      Callback method for aborted asynchronous touch.
      Specified by:
      onAbort in interface AsyncTouchCallback
    • confirmDelete

      public boolean confirmDelete(DataIdentifier identifier)
      Method to confirm that identifier can be deleted from Backend
      Parameters:
      identifier -
      Returns:
    • 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 interface DataStore
    • isInUse

      public boolean isInUse(DataIdentifier identifier)
    • close

      public void close() throws DataStoreException
      Description copied from interface: DataStore
      Close the data store
      Specified by:
      close in interface DataStore
      Throws:
      DataStoreException - if a problem occurred
    • setSecret

      public void setSecret(String secret)
      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:
      getMinRecordLength in interface DataStore
      Returns:
      the minimum size in bytes
    • getConfig

      public String getConfig()
      Return path of configuration properties.
      Returns:
      path of configuration properties.
    • setConfig

      public void setConfig(String config)
      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 of LocalCache.
      Parameters:
      cacheSize - size of LocalCache.
    • getPath

      public String getPath()
      Returns:
      path of LocalCache.
    • setPath

      public void setPath(String path)
      Set path of LocalCache.
      Parameters:
      path - of LocalCache.
    • getCachePurgeTrigFactor

      public double getCachePurgeTrigFactor()
      Returns:
      Purge trigger factor of LocalCache.
    • setCachePurgeTrigFactor

      public void setCachePurgeTrigFactor(double cachePurgeTrigFactor)
      Set purge trigger factor of LocalCache.
      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 of LocalCache.
      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

      public Backend getBackend()