]> source.dussan.org Git - jgit.git/commitdiff
Add a DfsPackFile method to get the number of cached bytes 43/4543/3
authorDave Borowitz <dborowitz@google.com>
Thu, 3 Nov 2011 19:54:21 +0000 (12:54 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Fri, 4 Nov 2011 18:14:32 +0000 (11:14 -0700)
The counter is actually stored in the DfsPackKey so it can be
manipulated by the cache.

Change-Id: I10cee76c92d65c68d1aa1a9dd0c4fd7173c4cede

org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsBlockCache.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackFile.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackKey.java

index 871a2c503464942b19e87f95818ed0ae08bebf01..bd68ae520d10e10597ab59f67f888d70c67edc86 100644 (file)
@@ -115,8 +115,12 @@ public final class DfsBlockCache {
                DfsBlockCache oc = cache;
                cache = nc;
 
-               if (oc != null && oc.readAheadService != null)
-                       oc.readAheadService.shutdown();
+               if (oc != null) {
+                       if (oc.readAheadService != null)
+                               oc.readAheadService.shutdown();
+                       for (DfsPackFile pack : oc.getPackFiles())
+                               pack.key.cachedSize.set(0);
+               }
        }
 
        /** @return the currently active DfsBlockCache. */
@@ -343,6 +347,7 @@ public final class DfsBlockCache {
                                e2 = table.get(slot);
                        }
 
+                       key.cachedSize.addAndGet(v.size());
                        Ref<DfsBlock> ref = new Ref<DfsBlock>(key, position, v.size(), v);
                        ref.hot = true;
                        for (;;) {
@@ -389,6 +394,7 @@ public final class DfsBlockCache {
                                dead.next = null;
                                dead.value = null;
                                live -= dead.size;
+                               dead.pack.cachedSize.addAndGet(-dead.size);
                                statEvict++;
                        } while (maxBytes < live);
                        clockHand = prev;
@@ -438,6 +444,7 @@ public final class DfsBlockCache {
                                }
                        }
 
+                       key.cachedSize.addAndGet(size);
                        ref = new Ref<T>(key, pos, size, v);
                        ref.hot = true;
                        for (;;) {
index 02ba0a0b2051040b299dcc98ebafaa76a5737a15..573e8e7067dcc34de9b40928316909aa55414f81 100644 (file)
@@ -171,6 +171,11 @@ public final class DfsPackFile {
                return packDesc;
        }
 
+       /** @return bytes cached in memory for this pack, excluding the index. */
+       public long getCachedSize() {
+               return key.cachedSize.get();
+       }
+
        private String getPackName() {
                return packDesc.getPackName();
        }
index 8e77dbaa27340e3f363c8c3807ea2da5b1122080..880ac9909a05726b7c496442c7e6c6d11746e9b6 100644 (file)
 
 package org.eclipse.jgit.storage.dfs;
 
+import java.util.concurrent.atomic.AtomicLong;
+
 final class DfsPackKey {
        final int hash;
 
+       final AtomicLong cachedSize;
+
        DfsPackKey() {
                // Multiply by 31 here so we can more directly combine with another
                // value without doing the multiply there.
                //
                hash = System.identityHashCode(this) * 31;
+               cachedSize = new AtomicLong();
        }
 }