DfsBlockCacheTable.
This cache implements a clock replacement algorithm, giving each block at least one chance to have been accessed during a sweep of the cache to save itself from eviction. The number of swipe chances is configurable per pack extension.
Entities created by the cache are held under hard references, preventing the Java VM from clearing anything. Blocks are discarded by the replacement algorithm when adding a new block would cause the cache to exceed its configured maximum size.
Whenever a cache miss occurs, loading is invoked by exactly one thread for
the given (DfsStreamKey,position) key tuple. This is ensured by
an array of locks, with the tuple hashed to a lock instance.
The internal hash table does not expand at runtime, instead it is fixed in size at cache creation time. The internal lock table used to gate load invocations is also fixed in size.
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| private static class | |
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private final int | blockSize
Used to reserve space for blocks. |
| private DfsBlockCache. | clockHand
Current position of the clock. |
| private final ReentrantLock | clockLock
Protects the clock and its related data. |
| private final DfsBlockCacheStats | |
| private final ClockBlockCacheTable. | |
| private final DfsBlockCacheConfig. | indexEventConsumer
Consumer of loading and eviction events of indexes. |
| private final Map | indexEvictionMap
Stores timestamps of the last eviction of indexes. |
| private final ReentrantLock[] | loadLocks
Locks to prevent concurrent loads for same (PackFile,position) block. |
| private final long | maxBytes
Maximum number of bytes the cache should hold. |
| private final String | name
Table name. |
| private final ReentrantLock[][] | refLocks
A separate pool of locks per pack extension to prevent concurrent loads for same index or bitmap from PackFile. |
| private final Consumer | refLockWaitTime
A consumer of object reference lock wait time milliseconds. |
| private final AtomicReferenceArray | table
Hash bucket directory; entries are chained below. |
| private final int |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public boolean | contains(DfsStreamKey
the stream key of the pack. key, long the position in the key. position)Implements org. Check if the block cache contains an object identified by (key, position). |
| private ClockBlockCacheTable. | |
| private void | |
| public <T> T | get(DfsStreamKey
the stream key of the pack. key, long the position in the key. position)Implements org. Get the object identified by (key, position) from the block cache. |
| public List | getBlockCacheStats()
Implements org. Get the list of |
| public String | getName()
Implements org. Get the name of the table. |
| public DfsBlock | getOrLoad(BlockBasedFile
the pack that "contains" the cached object. file, long offset within position, DfsReader pack of the object.current thread's reader. ctx, DfsBlockCache.supplier for channel to read fileChannelpack.Implements org. Look up a cached object, creating and loading it if it doesn't exist. |
| public <T> DfsBlockCache. | getOrLoadRef(DfsStreamKey
the stream key of the pack. key, long the position in the key. The default should be 0. position, DfsBlockCache.the function to load the reference. loaderImplements org. Look up a cached object, creating and loading it if it doesn't exist. |
| public boolean | hasBlock0(DfsStreamKey
the file to check. key)Implements org. Quickly check if the cache contains block 0 of the given stream. |
| private static boolean | |
| private ReentrantLock | |
| private ReentrantLock | |
| public void | put(DfsBlock
the block to put in the cache. v)Implements org. Put a block in the block cache. |
| public <T> DfsBlockCache. | put(DfsStreamKey
the stream key of the pack. key, long the position in the key. pos, long the size of the object. size, T the object to put in the block cache. v)Implements org. Put a block in the block cache. |
| public <T> DfsBlockCache. | putRef(DfsStreamKey
the stream key of the pack. key, long the size of the object. size, T the object to put in the block cache. v)Implements org. Put an object in the block cache. |
| private void | |
| private void | |
| private void | |
| private <T> T | |
| private <T> DfsBlockCache. | |
| private int | |
| private static int |
| blockSize | back to summary |
|---|---|
| private final int blockSize Used to reserve space for blocks. The value for blockSize must be a power of 2. | |
| clockHand | back to summary |
|---|---|
| private DfsBlockCache. Current position of the clock. | |
| clockLock | back to summary |
|---|---|
| private final ReentrantLock clockLock Protects the clock and its related data. | |
| dfsBlockCacheStats | back to summary |
|---|---|
| private final DfsBlockCacheStats dfsBlockCacheStats | |
| hash | back to summary |
|---|---|
| private final ClockBlockCacheTable. | |
| indexEventConsumer | back to summary |
|---|---|
| private final DfsBlockCacheConfig. Consumer of loading and eviction events of indexes. | |
| indexEvictionMap | back to summary |
|---|---|
| private final Map<ClockBlockCacheTable. Stores timestamps of the last eviction of indexes. | |
| loadLocks | back to summary |
|---|---|
| private final ReentrantLock[] loadLocks Locks to prevent concurrent loads for same (PackFile,position) block. The
number of locks is | |
| maxBytes | back to summary |
|---|---|
| private final long maxBytes Maximum number of bytes the cache should hold. | |
| name | back to summary |
|---|---|
| private final String name Table name. | |
| refLocks | back to summary |
|---|---|
| private final ReentrantLock[][] refLocks A separate pool of locks per pack extension to prevent concurrent loads for same index or bitmap from PackFile. | |
| refLockWaitTime | back to summary |
|---|---|
| private final Consumer<Long> refLockWaitTime A consumer of object reference lock wait time milliseconds. May be used to build a metric. | |
| table | back to summary |
|---|---|
| private final AtomicReferenceArray<ClockBlockCacheTable. Hash bucket directory; entries are chained below. | |
| tableSize | back to summary |
|---|---|
| private final int tableSize Number of entries in | |
| ClockBlockCacheTable | back to summary |
|---|---|
| pack-priv ClockBlockCacheTable(DfsBlockCacheConfig cfg) | |
| addToClock | back to summary |
|---|---|
private void addToClock(DfsBlockCache.
| |
| contains | back to summary |
|---|---|
| public boolean contains(DfsStreamKey key, long position) Implements org. Doc from org. Check if the block cache contains an object identified by (key, position).
| |
| createEvictKey | back to summary |
|---|---|
| private ClockBlockCacheTable. | |
| creditSpace | back to summary |
|---|---|
| private void creditSpace(long credit, DfsStreamKey key) | |
| get | back to summary |
|---|---|
| public <T> T get(DfsStreamKey key, long position) Implements org. Doc from org. Get the object identified by (key, position) from the block cache.
| |
| getBlockCacheStats | back to summary |
|---|---|
| public List Implements org. Doc from org. Get the list of
The returned list has a
| |
| getName | back to summary |
|---|---|
| public String getName() Implements org. Doc from org. Get the name of the table. | |
| getOrLoad | back to summary |
|---|---|
| public DfsBlock getOrLoad(BlockBasedFile file, long position, DfsReader ctx, DfsBlockCache. Implements org. Doc from org. Look up a cached object, creating and loading it if it doesn't exist.
| |
| getOrLoadRef | back to summary |
|---|---|
| public <T> DfsBlockCache. Implements org. Doc from org. Look up a cached object, creating and loading it if it doesn't exist.
| |
| hasBlock0 | back to summary |
|---|---|
| public boolean hasBlock0(DfsStreamKey key) Implements org. Doc from org. Quickly check if the cache contains block 0 of the given stream. This can be useful for sophisticated pre-read algorithms to quickly determine if a file is likely already in cache, especially small reftables which may be smaller than a typical DFS block size.
| |
| isIndexExtPos | back to summary |
|---|---|
| private static boolean isIndexExtPos(int packExtPos) | |
| lockFor | back to summary |
|---|---|
| private ReentrantLock lockFor(DfsStreamKey key, long position) | |
| lockForRef | back to summary |
|---|---|
| private ReentrantLock lockForRef(DfsStreamKey key) | |
| put | back to summary |
|---|---|
| public void put(DfsBlock v) Implements org. Doc from org. Put a block in the block cache. | |
| put | back to summary |
|---|---|
| public <T> DfsBlockCache. Implements org. Doc from org. Put a block in the block cache.
| |
| putRef | back to summary |
|---|---|
| public <T> DfsBlockCache. Implements org. Doc from org. Put an object in the block cache.
| |
| reportIndexEvicted | back to summary |
|---|---|
| private void reportIndexEvicted(DfsBlockCache. | |
| reportIndexRequested | back to summary |
|---|---|
| private void reportIndexRequested(DfsBlockCache. | |
| reserveSpace | back to summary |
|---|---|
private void reserveSpace(long reserve, DfsStreamKey key)
| |
| scan | back to summary |
|---|---|
| private <T> T scan(ClockBlockCacheTable. | |
| scanRef | back to summary |
|---|---|
private <T> DfsBlockCache.
| |
| slot | back to summary |
|---|---|
| private int slot(DfsStreamKey key, long position) | |
| tableSize | back to summary |
|---|---|
| private static int tableSize(DfsBlockCacheConfig cfg) | |
| Modifier and Type | Field and Description |
|---|---|
| private final ClockBlockCacheTable. | hash
Provides the hash function to be used for this key's hashCode method. |
| private final int | |
| private final int | |
| private final long |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | equals(Object
the reference object with which to compare. object)Overrides java. Indicates whether some other object is "equal to" this one. |
| public int |
| hash | back to summary |
|---|---|
| private final ClockBlockCacheTable. Provides the hash function to be used for this key's hashCode method. | |
| keyHash | back to summary |
|---|---|
| private final int keyHash | |
| packExtPos | back to summary |
|---|---|
| private final int packExtPos | |
| position | back to summary |
|---|---|
| private final long position | |
| EvictKey | back to summary |
|---|---|
| pack-priv EvictKey(ClockBlockCacheTable. | |
| equals | back to summary |
|---|---|
| public boolean equals(Object object) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| Modifier and Type | Field and Description |
|---|---|
| private final int | blockSizeShift
As |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv int |
| blockSizeShift | back to summary |
|---|---|
| private final int blockSizeShift As | |
| Hash | back to summary |
|---|---|
| pack-priv Hash(int blockSizeShift) | |
| hash | back to summary |
|---|---|
| pack-priv int hash(int packHash, long off) | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final ClockBlockCacheTable. | next
Next entry in the hash table's chain list. |
| pack-priv final DfsBlockCache. | ref
The referenced object. |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| private static ClockBlockCacheTable. |
| next | back to summary |
|---|---|
| pack-priv final ClockBlockCacheTable. Next entry in the hash table's chain list. | |
| ref | back to summary |
|---|---|
| pack-priv final DfsBlockCache. The referenced object. | |
| HashEntry | back to summary |
|---|---|
| pack-priv HashEntry(ClockBlockCacheTable. | |
| clean | back to summary |
|---|---|
| private static ClockBlockCacheTable. | |