Class SnapshotCache

java.lang.Object
org.apache.hadoop.ozone.om.snapshot.SnapshotCache
All Implemented Interfaces:
AutoCloseable, ReferenceCountedCallback

public class SnapshotCache extends Object implements ReferenceCountedCallback, AutoCloseable
Thread-safe custom unbounded LRU cache to manage open snapshot DB instances.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    State the reason the current thread is getting the OmSnapshot instance.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SnapshotCache(com.google.common.cache.CacheLoader<UUID,OmSnapshot> cacheLoader, int cacheSizeLimit, OMMetrics omMetrics, long cleanupInterval, boolean compactNonSnapshotDiffTables, org.apache.hadoop.ozone.om.lock.IOzoneManagerLock lock)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    callback(org.apache.hadoop.ozone.om.snapshot.ReferenceCounted referenceCounted)
    Callback method used to enqueue or dequeue ReferenceCounted from pendingEvictionList.
    void
     
    org.apache.ratis.util.function.UncheckedAutoCloseableSupplier<OmSnapshot>
    get(UUID key)
    Get or load OmSnapshot.
    void
    Immediately invalidate an entry.
    void
    Immediately invalidate all entries and close their DB instances in cache.
    org.apache.ratis.util.function.UncheckedAutoCloseableSupplier<org.apache.hadoop.ozone.om.lock.OMLockDetails>
    Acquires a write lock on the snapshot database and returns an auto-closeable supplier for lock details.
    org.apache.ratis.util.function.UncheckedAutoCloseableSupplier<org.apache.hadoop.ozone.om.lock.OMLockDetails>
    lock(UUID snapshotId)
    Acquires a write lock on a specific snapshot database and returns an auto-closeable supplier for lock details.
    void
    Release the reference count on the OmSnapshot instance.
    int
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SnapshotCache

      public SnapshotCache(com.google.common.cache.CacheLoader<UUID,OmSnapshot> cacheLoader, int cacheSizeLimit, OMMetrics omMetrics, long cleanupInterval, boolean compactNonSnapshotDiffTables, org.apache.hadoop.ozone.om.lock.IOzoneManagerLock lock)
  • Method Details

    • size

      public int size()
      Returns:
      number of DB instances currently held in cache.
    • invalidate

      public void invalidate(UUID key)
      Immediately invalidate an entry.
      Parameters:
      key - SnapshotId
    • invalidateAll

      public void invalidateAll()
      Immediately invalidate all entries and close their DB instances in cache.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • get

      public org.apache.ratis.util.function.UncheckedAutoCloseableSupplier<OmSnapshot> get(UUID key) throws IOException
      Get or load OmSnapshot. Shall be close()d after use. This would acquire a read lock on the Snapshot Database during the entire lifecycle of the returned OmSnapshot instance. TODO: [SNAPSHOT] Can add reason enum to param list later.
      Parameters:
      key - SnapshotId
      Returns:
      an OmSnapshot instance, or null on error
      Throws:
      IOException
    • release

      public void release(UUID key)
      Release the reference count on the OmSnapshot instance.
      Parameters:
      key - SnapshotId
    • lock

      public org.apache.ratis.util.function.UncheckedAutoCloseableSupplier<org.apache.hadoop.ozone.om.lock.OMLockDetails> lock()
      Acquires a write lock on the snapshot database and returns an auto-closeable supplier for lock details. The lock ensures that the operations accessing the snapshot database are performed in a thread-safe manner. The returned supplier automatically releases the lock when closed, preventing potential resource contention or deadlocks.
    • lock

      public org.apache.ratis.util.function.UncheckedAutoCloseableSupplier<org.apache.hadoop.ozone.om.lock.OMLockDetails> lock(UUID snapshotId)
      Acquires a write lock on a specific snapshot database and returns an auto-closeable supplier for lock details. The lock ensures that the operations accessing the snapshot database are performed in a thread safe manner. The returned supplier automatically releases the lock acquired when closed, preventing potential resource contention or deadlocks.
    • callback

      public void callback(org.apache.hadoop.ozone.om.snapshot.ReferenceCounted referenceCounted)
      Callback method used to enqueue or dequeue ReferenceCounted from pendingEvictionList.
      Specified by:
      callback in interface ReferenceCountedCallback
      Parameters:
      referenceCounted - ReferenceCounted object