Add a DfsPackFile method to get the number of cached bytes
The counter is actually stored in the DfsPackKey so it can be manipulated by the cache. Change-Id: I10cee76c92d65c68d1aa1a9dd0c4fd7173c4cede
This commit is contained in:
parent
dff9d56b94
commit
4fc1af6850
|
@ -115,8 +115,12 @@ public static void reconfigure(DfsBlockCacheConfig cfg) {
|
||||||
DfsBlockCache oc = cache;
|
DfsBlockCache oc = cache;
|
||||||
cache = nc;
|
cache = nc;
|
||||||
|
|
||||||
if (oc != null && oc.readAheadService != null)
|
if (oc != null) {
|
||||||
oc.readAheadService.shutdown();
|
if (oc.readAheadService != null)
|
||||||
|
oc.readAheadService.shutdown();
|
||||||
|
for (DfsPackFile pack : oc.getPackFiles())
|
||||||
|
pack.key.cachedSize.set(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return the currently active DfsBlockCache. */
|
/** @return the currently active DfsBlockCache. */
|
||||||
|
@ -343,6 +347,7 @@ DfsBlock getOrLoad(DfsPackFile pack, long position, DfsReader ctx)
|
||||||
e2 = table.get(slot);
|
e2 = table.get(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
key.cachedSize.addAndGet(v.size());
|
||||||
Ref<DfsBlock> ref = new Ref<DfsBlock>(key, position, v.size(), v);
|
Ref<DfsBlock> ref = new Ref<DfsBlock>(key, position, v.size(), v);
|
||||||
ref.hot = true;
|
ref.hot = true;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -389,6 +394,7 @@ private void reserveSpace(int reserve) {
|
||||||
dead.next = null;
|
dead.next = null;
|
||||||
dead.value = null;
|
dead.value = null;
|
||||||
live -= dead.size;
|
live -= dead.size;
|
||||||
|
dead.pack.cachedSize.addAndGet(-dead.size);
|
||||||
statEvict++;
|
statEvict++;
|
||||||
} while (maxBytes < live);
|
} while (maxBytes < live);
|
||||||
clockHand = prev;
|
clockHand = prev;
|
||||||
|
@ -438,6 +444,7 @@ <T> Ref<T> put(DfsPackKey key, long pos, int size, T v) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
key.cachedSize.addAndGet(size);
|
||||||
ref = new Ref<T>(key, pos, size, v);
|
ref = new Ref<T>(key, pos, size, v);
|
||||||
ref.hot = true;
|
ref.hot = true;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
|
@ -171,6 +171,11 @@ public DfsPackDescription getPackDescription() {
|
||||||
return packDesc;
|
return packDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return bytes cached in memory for this pack, excluding the index. */
|
||||||
|
public long getCachedSize() {
|
||||||
|
return key.cachedSize.get();
|
||||||
|
}
|
||||||
|
|
||||||
private String getPackName() {
|
private String getPackName() {
|
||||||
return packDesc.getPackName();
|
return packDesc.getPackName();
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,13 +43,18 @@
|
||||||
|
|
||||||
package org.eclipse.jgit.storage.dfs;
|
package org.eclipse.jgit.storage.dfs;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
final class DfsPackKey {
|
final class DfsPackKey {
|
||||||
final int hash;
|
final int hash;
|
||||||
|
|
||||||
|
final AtomicLong cachedSize;
|
||||||
|
|
||||||
DfsPackKey() {
|
DfsPackKey() {
|
||||||
// Multiply by 31 here so we can more directly combine with another
|
// Multiply by 31 here so we can more directly combine with another
|
||||||
// value without doing the multiply there.
|
// value without doing the multiply there.
|
||||||
//
|
//
|
||||||
hash = System.identityHashCode(this) * 31;
|
hash = System.identityHashCode(this) * 31;
|
||||||
|
cachedSize = new AtomicLong();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue