Class 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 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 Detail

      • ArchiveCacheStorage

        public ArchiveCacheStorage​(java.lang.String cacheDirectory,
                                   BucketTopologyHelper bucketTopologyHelper,
                                   ArchiveCacheEvictionController archiveCacheEvictionController,
                                   long maxStorageSpace,
                                   long evictionStorageSpaceThreshold,
                                   long safeStorageSpaceThreshold)
                            throws IllegalPathException,
        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.
        IllegalPathException - if provided cache directory contains unsafe or illegal archive names. - 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
      • moveArchiveToCache

        public void moveArchiveToCache​(java.nio.file.Path initialFilePath,
                                       java.lang.String fileBucketId,
                                       java.lang.String tarId)
                                throws IllegalPathException,
      • cancelReservedArchive

        public void cancelReservedArchive​(java.lang.String fileBucketId,
                                          java.lang.String tarId)
      • tryReadArchive

        public java.util.Optional<> tryReadArchive​(java.lang.String fileBucketId,
                                                                          java.lang.String tarId)
                                                                   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()