Package fr.gouv.vitam.storage.offers.tape.cas

# Class ArchiveCacheStorage

java.lang.Object
fr.gouv.vitam.storage.offers.tape.cas.ArchiveCacheStorage

@ThreadSafe public class ArchiveCacheStorage extends 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 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

  Constructors
  Constructor
  Description
  `ArchiveCacheStorage(String cacheDirectory, BucketTopologyHelper bucketTopologyHelper, ArchiveCacheEvictionController archiveCacheEvictionController, long maxStorageSpace, long evictionStorageSpaceThreshold, long safeStorageSpaceThreshold)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `cancelReservedArchive(String fileBucketId, String tarId)`
  `boolean`
  `containsArchive(String fileBucketId, String tarId)`
  `long`
  `getCurrentStorageSpaceUsage()`
  `long`
  `getEvictionStorageSpaceThreshold()`
  `long`
  `getMaxStorageSpace()`
  `long`
  `getSafeStorageSpaceThreshold()`
  `boolean`
  `isArchiveReserved(String fileBucketId, String tarId)`
  `boolean`
  `isCacheEvictionRunning()`
  `void`
  `moveArchiveToCache(Path initialFilePath, String fileBucketId, String tarId)`
  `void`
  `reserveArchiveStorageSpace(String fileBucketId, String tarId, long fileSize)`
  `Optional<FileInputStream>`
  `tryReadArchive(String fileBucketId, String tarId)`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## 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 directory
      `bucketTopologyHelper` - bucket topology helper
      `archiveCacheEvictionController` - 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 files
      `safeStorageSpaceThreshold` - 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

    public void cancelReservedArchive(String fileBucketId, String tarId)

  - ### tryReadArchive

    public Optional<FileInputStream> tryReadArchive(String fileBucketId, String tarId) throws IllegalPathException
    Throws:
      `IllegalPathException`

  - ### containsArchive

    public boolean containsArchive(String fileBucketId, String tarId)

  - ### isArchiveReserved

    public boolean isArchiveReserved(String fileBucketId, String tarId)

  - ### getMaxStorageSpace

    public long getMaxStorageSpace()

  - ### getEvictionStorageSpaceThreshold

    public long getEvictionStorageSpaceThreshold()

  - ### getSafeStorageSpaceThreshold

    public long getSafeStorageSpaceThreshold()

  - ### getCurrentStorageSpaceUsage

    public long getCurrentStorageSpaceUsage()

  - ### isCacheEvictionRunning

    public boolean isCacheEvictionRunning()