Package org.apache.jackrabbit.core.data
Class FileDataStore
- java.lang.Object
-
- org.apache.jackrabbit.core.data.AbstractDataStore
-
- org.apache.jackrabbit.core.data.FileDataStore
-
- All Implemented Interfaces:
DataStore,MultiDataStoreAware
public class FileDataStore extends AbstractDataStore implements MultiDataStoreAware
Simple file-based data store. Data records are stored as normal files named using a message digest of the contained binary stream. Configuration:<DataStore class="org.apache.jackrabbit.core.data.FileDataStore"> <param name="path" value="/data/datastore"/> <param name="minRecordLength" value="1024"/> </DataStore>If the directory is not set, the directory <repository home>/repository/datastore is used.
A three level directory structure is used to avoid placing too many files in a single directory. The chosen structure is designed to scale up to billions of distinct records.
This implementation relies on the underlying file system to support atomic O(1) move operations with
Files.move(Path, Path, CopyOption...).
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<DataIdentifier,WeakReference<DataIdentifier>>inUseAll data identifiers that are currently in use are in this set until they are garbage collected.-
Fields inherited from class org.apache.jackrabbit.core.data.AbstractDataStore
DIGEST
-
-
Constructor Summary
Constructors Constructor Description FileDataStore()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DataRecordaddRecord(InputStream input)Creates a new data record.voidclearInUse()Clear the in-use list.voidclose()Close the data storeintdeleteAllOlderThan(long min)Delete objects that have a modified date older than the specified date.voiddeleteRecord(DataIdentifier identifier)Deletes a single DataRecord based on the given identifier.Iterator<DataIdentifier>getAllIdentifiers()Get all identifiers.intgetMinRecordLength()Get the minimum size of an object that should be stored in this data store.protected byte[]getOrCreateReferenceKey()Returns the reference key of this data store.StringgetPath()Get the name of the directory where this data store keeps the files.DataRecordgetRecordIfStored(DataIdentifier identifier)Get a data record for the given identifier.voidinit(String homeDir)Initialized the data store.voidsetMinRecordLength(int minRecordLength)Set the minimum object length.voidsetPath(String directoryName)Set the name of the directory where this data store keeps the files.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
encodeHexString, getRecord, getRecordFromReference, getReferenceFromIdentifier
-
-
-
-
Field Detail
-
inUse
protected Map<DataIdentifier,WeakReference<DataIdentifier>> inUse
All data identifiers that are currently in use are in this set until they are garbage collected.
-
-
Method Detail
-
init
public void init(String homeDir)
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.
-
getRecordIfStored
public DataRecord getRecordIfStored(DataIdentifier identifier) throws DataStoreException
Get a data record for the given identifier.- Specified by:
getRecordIfStoredin interfaceDataStore- Parameters:
identifier- the identifier- Returns:
- the data record or null
- Throws:
DataStoreException- if the data store could not be accessed
-
addRecord
public DataRecord addRecord(InputStream input) throws DataStoreException
Creates a new data record. 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 the temporary file is moved in place to become the new data record that gets returned.- Specified by:
addRecordin interfaceDataStore- Parameters:
input- binary stream- Returns:
- data record that contains the given stream
- Throws:
DataStoreException- if the record could not be created
-
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
-
deleteRecord
public void deleteRecord(DataIdentifier identifier) throws DataStoreException
Description copied from interface:MultiDataStoreAwareDeletes a single DataRecord based on the given identifier. Delete will only be used by theMultiDataStore.MoveDataTask.- 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
public int deleteAllOlderThan(long min)
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
-
getAllIdentifiers
public Iterator<DataIdentifier> getAllIdentifiers()
Description copied from interface:DataStoreGet all identifiers.- Specified by:
getAllIdentifiersin interfaceDataStore- Returns:
- an iterator over all DataIdentifier objects
-
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
-
getPath
public String getPath()
Get the name of the directory where this data store keeps the files.- Returns:
- the full path name
-
setPath
public void setPath(String directoryName)
Set the name of the directory where this data store keeps the files.- Parameters:
directoryName- the path name
-
getMinRecordLength
public int getMinRecordLength()
Description copied from interface:DataStoreGet the minimum size of an object that should be stored in this data store. Depending on the overhead and configuration, each store may return a different value.- Specified by:
getMinRecordLengthin interfaceDataStore- Returns:
- the minimum size in bytes
-
setMinRecordLength
public void setMinRecordLength(int minRecordLength)
Set the minimum object length.- Parameters:
minRecordLength- the length
-
close
public void close()
Description copied from interface:DataStoreClose the data store
-
getOrCreateReferenceKey
protected byte[] getOrCreateReferenceKey() throws DataStoreExceptionDescription copied from class:AbstractDataStoreReturns the reference key of this data store. If one does not already exist, it is automatically created in an implementation-specific way. The default implementation simply creates a temporary random key that's valid only until the data store gets restarted. Subclasses can override and/or decorate this method to support a more persistent reference key.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.
- Overrides:
getOrCreateReferenceKeyin classAbstractDataStore- Returns:
- reference key
- Throws:
DataStoreException- if the key is not available
-
-