Top Description Inners Fields Constructors Methods
org.eclipse.jgit.internal.storage.dfs

public final Class DfsBlockCache

extends Object
Class Inheritance
Static Imports
org.eclipse.jgit.internal.storage.dfs.DfsBlockCacheTable.BlockCacheStats

Caches slices of a org.eclipse.jgit.internal.storage.dfs.BlockBasedFile in memory for faster read access.

The DfsBlockCache serves as a Java based "buffer cache", loading segments of a BlockBasedFile into the JVM heap prior to use. As JGit often wants to do reads of only tiny slices of a file, the DfsBlockCache tries to smooth out these tiny reads into larger block-sized IO operations.

Its too expensive during object access to be accurate with a least recently used (LRU) algorithm. Strictly ordering every read is a lot of overhead that typically doesn't yield a corresponding benefit to the application.

The key tuple is passed through to methods as a pair of parameters rather than as a single Object, thus reducing the transient memory allocations of callers. It is more efficient to avoid the allocation, as we can't be 100% sure that a JIT would be able to stack-allocate a key tuple.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static interface
DfsBlockCache.ReadableChannelSupplier

Supplier for readable channel

pack-priv static class
pack-priv static interface

Field Summary

Modifier and TypeField and Description
private final int
blockSize

Suggested block size to read from pack files in.

If a pack file does not have a native block size, this size will be used.

private static volatile DfsBlockCache
private final int[]
cacheHotLimits

Limits of cache hot count per pack file extension.

private final DfsBlockCacheTable
private final long
maxBytes

Maximum number of bytes the cache should hold.

private final long
maxStreamThroughCache

Pack files smaller than this size can be copied through the cache.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
contains(DfsStreamKey key, long position)

pack-priv <T> T
get(DfsStreamKey key, long position)

private DfsBlockCacheTable.BlockCacheStats
public List<DfsBlockCacheTable.BlockCacheStats>

Returns:

the list of BlockCacheStats for all underlying caches.
getAllBlockCacheStats
()

Get the list of BlockCacheStats for all underlying caches.

pack-priv int
public long[]

Returns:

total number of bytes in the cache, per pack file extension.
getCurrentSize
()

Get total number of bytes in the cache, per pack file extension.

public long[]

Returns:

number of evictions performed due to cache being full, per pack file extension.
getEvictions
()

Get number of evictions performed due to cache being full, per pack file extension.

public long

Returns:

0..100, defining how full the cache is.
getFillPercentage
()

Get 0..100, defining how full the cache is.

public long[]

Returns:

number of requests for items in the cache, per pack file extension.
getHitCount
()

Get number of requests for items in the cache, per pack file extension.

public long[]

Returns:

hit ratios
getHitRatio
()

Get hit ratios

public static DfsBlockCache

Returns:

the currently active DfsBlockCache.
getInstance
()

Get the currently active DfsBlockCache.

public long[]

Returns:

number of requests for items not in the cache, per pack file extension.
getMissCount
()

Get number of requests for items not in the cache, per pack file extension.

pack-priv DfsBlock

Returns:

the object reference.
getOrLoad
(BlockBasedFile
the pack that "contains" the cached object.
file
,
long
offset within pack of the object.
position
,
DfsReader
current thread's reader.
ctx
,
DfsBlockCache.ReadableChannelSupplier
supplier for channel to read pack.
fileChannel
)

Look up a cached object, creating and loading it if it doesn't exist.

pack-priv <T> DfsBlockCache.Ref<T>

Returns:

the object reference.
getOrLoadRef
(DfsStreamKey
the stream key of the pack.
key
,
long
the position in the key. The default should be 0.
position
,
DfsBlockCache.RefLoader<T>
the function to load the reference.
loader
)

Look up a cached object, creating and loading it if it doesn't exist.

public long[]

Returns:

total number of requests (hit + miss), per pack file extension.
getTotalRequestCount
()

Get total number of requests (hit + miss), per pack file extension.

public boolean

Returns:

true if block 0 (the first block) is in the cache.
hasBlock0
(DfsStreamKey
the file to check.
key
)

Quickly check if the cache contains block 0 of the given stream.

pack-priv void
pack-priv <T> DfsBlockCache.Ref<T>
put(DfsStreamKey key, long pos, long size, T v)

pack-priv <T> DfsBlockCache.Ref<T>
putRef(DfsStreamKey key, long size, T v)

public static void
reconfigure(DfsBlockCacheConfig
the new window cache configuration.
cfg
)

Modify the configuration of the window cache.

pack-priv boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

blockSizeback to summary
private final int blockSize

Suggested block size to read from pack files in.

If a pack file does not have a native block size, this size will be used.

If a pack file has a native size, a whole multiple of the native size will be used until it matches this size.

The value for blockSize must be a power of 2.

cacheback to summary
private static volatile DfsBlockCache cache
cacheHotLimitsback to summary
private final int[] cacheHotLimits

Limits of cache hot count per pack file extension.

dfsBlockCacheTableback to summary
private final DfsBlockCacheTable dfsBlockCacheTable
maxBytesback to summary
private final long maxBytes

Maximum number of bytes the cache should hold.

maxStreamThroughCacheback to summary
private final long maxStreamThroughCache

Pack files smaller than this size can be copied through the cache.

Constructor Detail

DfsBlockCacheback to summary
private DfsBlockCache(DfsBlockCacheConfig cfg)

Method Detail

containsback to summary
pack-priv boolean contains(DfsStreamKey key, long position)
getback to summary
pack-priv <T> T get(DfsStreamKey key, long position)
getAggregatedBlockCacheStatsback to summary
private DfsBlockCacheTable.BlockCacheStats getAggregatedBlockCacheStats()
getAllBlockCacheStatsback to summary
public List<DfsBlockCacheTable.BlockCacheStats> getAllBlockCacheStats()

Get the list of BlockCacheStats for all underlying caches.

Useful in monitoring caches with breakdown.

Returns:List<DfsBlockCacheTable.BlockCacheStats>

the list of BlockCacheStats for all underlying caches.

getBlockSizeback to summary
pack-priv int getBlockSize()
getCurrentSizeback to summary
public long[] getCurrentSize()

Get total number of bytes in the cache, per pack file extension.

Returns:long[]

total number of bytes in the cache, per pack file extension.

getEvictionsback to summary
public long[] getEvictions()

Get number of evictions performed due to cache being full, per pack file extension.

Returns:long[]

number of evictions performed due to cache being full, per pack file extension.

getFillPercentageback to summary
public long getFillPercentage()

Get 0..100, defining how full the cache is.

Returns:long

0..100, defining how full the cache is.

getHitCountback to summary
public long[] getHitCount()

Get number of requests for items in the cache, per pack file extension.

Returns:long[]

number of requests for items in the cache, per pack file extension.

getHitRatioback to summary
public long[] getHitRatio()

Get hit ratios

Returns:long[]

hit ratios

getInstanceback to summary
public static DfsBlockCache getInstance()

Get the currently active DfsBlockCache.

Returns:DfsBlockCache

the currently active DfsBlockCache.

getMissCountback to summary
public long[] getMissCount()

Get number of requests for items not in the cache, per pack file extension.

Returns:long[]

number of requests for items not in the cache, per pack file extension.

getOrLoadback to summary
pack-priv DfsBlock getOrLoad(BlockBasedFile file, long position, DfsReader ctx, DfsBlockCache.ReadableChannelSupplier fileChannel) throws IOException

Look up a cached object, creating and loading it if it doesn't exist.

Parameters
file:BlockBasedFile

the pack that "contains" the cached object.

position:long

offset within pack of the object.

ctx:DfsReader

current thread's reader.

fileChannel:DfsBlockCache.ReadableChannelSupplier

supplier for channel to read pack.

Returns:DfsBlock

the object reference.

Exceptions
IOException:
the reference was not in the cache and could not be loaded.
getOrLoadRefback to summary
pack-priv <T> DfsBlockCache.Ref<T> getOrLoadRef(DfsStreamKey key, long position, DfsBlockCache.RefLoader<T> loader) throws IOException

Look up a cached object, creating and loading it if it doesn't exist.

Parameters
key:DfsStreamKey

the stream key of the pack.

position:long

the position in the key. The default should be 0.

loader:DfsBlockCache.RefLoader<T>

the function to load the reference.

Returns:DfsBlockCache.Ref<T>

the object reference.

Exceptions
IOException:
the reference was not in the cache and could not be loaded.
getTotalRequestCountback to summary
public long[] getTotalRequestCount()

Get total number of requests (hit + miss), per pack file extension.

Returns:long[]

total number of requests (hit + miss), per pack file extension.

hasBlock0back to summary
public boolean hasBlock0(DfsStreamKey key)

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.

Parameters
key:DfsStreamKey

the file to check.

Returns:boolean

true if block 0 (the first block) is in the cache.

putback to summary
pack-priv void put(DfsBlock v)
putback to summary
pack-priv <T> DfsBlockCache.Ref<T> put(DfsStreamKey key, long pos, long size, T v)
putRefback to summary
pack-priv <T> DfsBlockCache.Ref<T> putRef(DfsStreamKey key, long size, T v)
reconfigureback to summary
public static void reconfigure(DfsBlockCacheConfig cfg)

Modify the configuration of the window cache.

The new configuration is applied immediately, and the existing cache is cleared.

Parameters
cfg:DfsBlockCacheConfig

the new window cache configuration.

Exceptions
IllegalArgumentException:
the cache configuration contains one or more invalid settings, usually too low of a limit.
shouldCopyThroughCacheback to summary
pack-priv boolean shouldCopyThroughCache(long length)
org.eclipse.jgit.internal.storage.dfs back to summary

pack-priv Interface DfsBlockCache.ReadableChannelSupplier

Known Direct Implementers
org.eclipse.jgit.internal.storage.dfs.BlockBasedFile.LazyChannel
Annotations
@FunctionalInterface

Supplier for readable channel

Method Summary

Modifier and TypeMethod and Description
public ReadableChannel

Returns:

ReadableChannel
get
()

Get ReadableChannel

Method Detail

getback to summary
public ReadableChannel get() throws IOException

Get ReadableChannel

Returns:ReadableChannel

ReadableChannel

Exceptions
IOException:
if an IO error occurred
org.eclipse.jgit.internal.storage.dfs back to summary

pack-priv final Class DfsBlockCache.Ref<T>

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private volatile int
pack-priv final DfsStreamKey
pack-priv DfsBlockCache.Ref<T>
pack-priv final long
pack-priv final long
private final AtomicInteger
pack-priv volatile T

Constructor Summary

AccessConstructor and Description
pack-priv
Ref(DfsStreamKey key, long position, long size, T v)

Method Summary

Modifier and TypeMethod and Description
pack-priv T
get()

pack-priv int
pack-priv boolean
has()

pack-priv boolean
pack-priv void
pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

hotCountback to summary
private volatile int hotCount
keyback to summary
pack-priv final DfsStreamKey key
nextback to summary
pack-priv DfsBlockCache.Ref<T> next
positionback to summary
pack-priv final long position
sizeback to summary
pack-priv final long size
totalHitCountback to summary
private final AtomicInteger totalHitCount
valueback to summary
pack-priv volatile T value

Constructor Detail

Refback to summary
pack-priv Ref(DfsStreamKey key, long position, long size, T v)

Method Detail

getback to summary
pack-priv T get()
getTotalHitCountback to summary
pack-priv int getTotalHitCount()
hasback to summary
pack-priv boolean has()
isHotback to summary
pack-priv boolean isHot()
markColderback to summary
pack-priv void markColder()
markHotterback to summary
pack-priv void markHotter()
org.eclipse.jgit.internal.storage.dfs back to summary

pack-priv Interface DfsBlockCache.RefLoader<T>

Annotations
@FunctionalInterface

Method Summary

Modifier and TypeMethod and Description
public DfsBlockCache.Ref<T>
load()

Method Detail

loadback to summary
public DfsBlockCache.Ref<T> load() throws IOException