Class ArchiveCacheStorage
java.lang.Object
fr.gouv.vitam.storage.offers.tape.cas.ArchiveCacheStorage
Cache for archive storage on disk with Least Recently Used (LRU) eviction policy.
Archives are stored as files on a cache directory in the following topology {cacheDirectory}/{fileBucketId}/{tarId}.
Cache is configured with storage capacity thresholds :
- Max storage space : max capacity that cannot be exceeded by archive cache.
- An eviction storage space threshold : triggers background delete of old unused archive files.
- Safe storage capacity threshold : causes background delete process to stop when enough disk space is available.
Typical use would be :
-
reserveArchiveStorageSpace()
to ensure enough disk space is available
- Write data to temporary archive in a dedicated folder (different from cache directory which is managed by the cache), but on same file system partition (to ensure atomic file move is available)
- moveArchiveToCache()
to move atomically temporary archive to cache directory and add it to cache OR cancelReservedArchive()
on failure
- At any time, try read an archive from disk using the tryReadFile()
method.
When initialized, the cache loads all existing archive files from storage directory.
This class is Thread-Safe.-
Constructor Summary
ConstructorDescriptionArchiveCacheStorage
(String cacheDirectory, BucketTopologyHelper bucketTopologyHelper, ArchiveCacheEvictionController archiveCacheEvictionController, long maxStorageSpace, long evictionStorageSpaceThreshold, long safeStorageSpaceThreshold) -
Method Summary
Modifier and TypeMethodDescriptionvoid
cancelReservedArchive
(String fileBucketId, String tarId) boolean
containsArchive
(String fileBucketId, String tarId) long
long
long
long
boolean
isArchiveReserved
(String fileBucketId, String tarId) boolean
void
moveArchiveToCache
(Path initialFilePath, String fileBucketId, String tarId) void
reserveArchiveStorageSpace
(String fileBucketId, String tarId, long fileSize) tryReadArchive
(String fileBucketId, String tarId)
-
Constructor Details
-
ArchiveCacheStorage
public ArchiveCacheStorage(String cacheDirectory, BucketTopologyHelper bucketTopologyHelper, ArchiveCacheEvictionController archiveCacheEvictionController, long maxStorageSpace, long evictionStorageSpaceThreshold, long safeStorageSpaceThreshold) throws IllegalPathException, IOException - Parameters:
cacheDirectory
- the cache storage directorybucketTopologyHelper
- bucket topology helperarchiveCacheEvictionController
- controller of archive cache eviction.maxStorageSpace
- max capacity (in bytes) that cannot be exceeded by archive cache.evictionStorageSpaceThreshold
- : storage space capacity (in bytes) that triggers background delete of old unused archive filessafeStorageSpaceThreshold
- safe storage space capacity level (in bytes). When enough storage space is available, background cache delete process ends.- Throws:
IllegalPathException
- if provided cache directory contains unsafe or illegal archive names.IOException
- if an I/O error is thrown when accessing disk.
-
-
Method Details
-
reserveArchiveStorageSpace
public void reserveArchiveStorageSpace(String fileBucketId, String tarId, long fileSize) throws IllegalPathException - Throws:
IllegalPathException
-
moveArchiveToCache
public void moveArchiveToCache(Path initialFilePath, String fileBucketId, String tarId) throws IllegalPathException, IOException - Throws:
IllegalPathException
IOException
-
cancelReservedArchive
-
tryReadArchive
public Optional<FileInputStream> tryReadArchive(String fileBucketId, String tarId) throws IllegalPathException - Throws:
IllegalPathException
-
containsArchive
-
isArchiveReserved
-
getMaxStorageSpace
public long getMaxStorageSpace() -
getEvictionStorageSpaceThreshold
public long getEvictionStorageSpaceThreshold() -
getSafeStorageSpaceThreshold
public long getSafeStorageSpaceThreshold() -
getCurrentStorageSpaceUsage
public long getCurrentStorageSpaceUsage() -
isCacheEvictionRunning
public boolean isCacheEvictionRunning()
-