Class SnapshotCache
java.lang.Object
org.apache.hadoop.ozone.om.snapshot.SnapshotCache
- All Implemented Interfaces:
AutoCloseable,ReferenceCountedCallback
Thread-safe custom unbounded LRU cache to manage open snapshot DB instances.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumState the reason the current thread is getting the OmSnapshot instance. -
Constructor Summary
ConstructorsConstructorDescriptionSnapshotCache(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 TypeMethodDescriptionvoidcallback(org.apache.hadoop.ozone.om.snapshot.ReferenceCounted referenceCounted) Callback method used to enqueue or dequeue ReferenceCounted from pendingEvictionList.voidclose()org.apache.ratis.util.function.UncheckedAutoCloseableSupplier<OmSnapshot> Get or load OmSnapshot.voidinvalidate(UUID key) Immediately invalidate an entry.voidImmediately invalidate all entries and close their DB instances in cache.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.org.apache.ratis.util.function.UncheckedAutoCloseableSupplier<org.apache.hadoop.ozone.om.lock.OMLockDetails> Acquires a write lock on a specific snapshot database and returns an auto-closeable supplier for lock details.voidRelease the reference count on the OmSnapshot instance.intsize()
-
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
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:
closein interfaceAutoCloseable
-
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
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:
callbackin interfaceReferenceCountedCallback- Parameters:
referenceCounted- ReferenceCounted object
-