Class ArchiveCacheStorage
- java.lang.Object
-
- fr.gouv.vitam.storage.offers.tape.cas.ArchiveCacheStorage
-
@ThreadSafe public class ArchiveCacheStorage extends java.lang.Object
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 ORcancelReservedArchive()
on failure - At any time, try read an archive from disk using thetryReadFile()
method. When initialized, the cache loads all existing archive files from storage directory. This class is Thread-Safe.
-
-
Constructor Summary
Constructors Constructor Description ArchiveCacheStorage(java.lang.String cacheDirectory, BucketTopologyHelper bucketTopologyHelper, ArchiveCacheEvictionController archiveCacheEvictionController, long maxStorageSpace, long evictionStorageSpaceThreshold, long safeStorageSpaceThreshold)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancelReservedArchive(java.lang.String fileBucketId, java.lang.String tarId)
boolean
containsArchive(java.lang.String fileBucketId, java.lang.String tarId)
long
getCurrentStorageSpaceUsage()
long
getEvictionStorageSpaceThreshold()
long
getMaxStorageSpace()
long
getSafeStorageSpaceThreshold()
boolean
isArchiveReserved(java.lang.String fileBucketId, java.lang.String tarId)
boolean
isCacheEvictionRunning()
void
moveArchiveToCache(java.nio.file.Path initialFilePath, java.lang.String fileBucketId, java.lang.String tarId)
void
reserveArchiveStorageSpace(java.lang.String fileBucketId, java.lang.String tarId, long fileSize)
java.util.Optional<java.io.FileInputStream>
tryReadArchive(java.lang.String fileBucketId, java.lang.String tarId)
-
-
-
Constructor Detail
-
ArchiveCacheStorage
public ArchiveCacheStorage(java.lang.String cacheDirectory, BucketTopologyHelper bucketTopologyHelper, ArchiveCacheEvictionController archiveCacheEvictionController, long maxStorageSpace, long evictionStorageSpaceThreshold, long safeStorageSpaceThreshold) throws IllegalPathException, java.io.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.java.io.IOException
- if an I/O error is thrown when accessing disk.
-
-
Method Detail
-
reserveArchiveStorageSpace
public void reserveArchiveStorageSpace(java.lang.String fileBucketId, java.lang.String tarId, long fileSize) throws IllegalPathException
- Throws:
IllegalPathException
-
moveArchiveToCache
public void moveArchiveToCache(java.nio.file.Path initialFilePath, java.lang.String fileBucketId, java.lang.String tarId) throws IllegalPathException, java.io.IOException
- Throws:
IllegalPathException
java.io.IOException
-
cancelReservedArchive
public void cancelReservedArchive(java.lang.String fileBucketId, java.lang.String tarId)
-
tryReadArchive
public java.util.Optional<java.io.FileInputStream> tryReadArchive(java.lang.String fileBucketId, java.lang.String tarId) throws IllegalPathException
- Throws:
IllegalPathException
-
containsArchive
public boolean containsArchive(java.lang.String fileBucketId, java.lang.String tarId)
-
isArchiveReserved
public boolean isArchiveReserved(java.lang.String fileBucketId, java.lang.String tarId)
-
getMaxStorageSpace
public long getMaxStorageSpace()
-
getEvictionStorageSpaceThreshold
public long getEvictionStorageSpaceThreshold()
-
getSafeStorageSpaceThreshold
public long getSafeStorageSpaceThreshold()
-
getCurrentStorageSpaceUsage
public long getCurrentStorageSpaceUsage()
-
isCacheEvictionRunning
public boolean isCacheEvictionRunning()
-
-