コード例 #1
0
 private static int tableSize(final WindowCacheConfig cfg) {
   final int wsz = cfg.getPackedGitWindowSize();
   final long limit = cfg.getPackedGitLimit();
   if (wsz <= 0) throw new IllegalArgumentException("Invalid window size");
   if (limit < wsz) throw new IllegalArgumentException("Window size must be < limit");
   return (int) Math.min(5 * (limit / wsz) / 2, 2000000000);
 }
コード例 #2
0
 public void testConfigureCache_PackedGitOpenFiles_0() {
   try {
     final WindowCacheConfig cfg = new WindowCacheConfig();
     cfg.setPackedGitOpenFiles(0);
     WindowCache.reconfigure(cfg);
     fail("incorrectly permitted PackedGitOpenFiles = 0");
   } catch (IllegalArgumentException e) {
     assertEquals("Open files must be >= 1", e.getMessage());
   }
 }
コード例 #3
0
 public void testConfigureCache_PackedGitWindowSize_4097() {
   try {
     final WindowCacheConfig cfg = new WindowCacheConfig();
     cfg.setPackedGitWindowSize(4097);
     WindowCache.reconfigure(cfg);
     fail("incorrectly permitted PackedGitWindowSize = 4097");
   } catch (IllegalArgumentException e) {
     assertEquals("Window size must be power of 2", e.getMessage());
   }
 }
コード例 #4
0
 public void testConfigureCache_PackedGitWindowSize_512() {
   try {
     final WindowCacheConfig cfg = new WindowCacheConfig();
     cfg.setPackedGitWindowSize(512);
     WindowCache.reconfigure(cfg);
     fail("incorrectly permitted PackedGitWindowSize = 512");
   } catch (IllegalArgumentException e) {
     assertEquals("Invalid window size", e.getMessage());
   }
 }
コード例 #5
0
 public void testConfigureCache_PackedGitLimit_0() {
   try {
     final WindowCacheConfig cfg = new WindowCacheConfig();
     cfg.setPackedGitLimit(0);
     WindowCache.reconfigure(cfg);
     fail("incorrectly permitted PackedGitLimit = 0");
   } catch (IllegalArgumentException e) {
     //
   }
 }
コード例 #6
0
 public void testConfigureCache_PackedGitWindowSizeAbovePackedGitLimit() {
   try {
     final WindowCacheConfig cfg = new WindowCacheConfig();
     cfg.setPackedGitLimit(1024);
     cfg.setPackedGitWindowSize(8192);
     WindowCache.reconfigure(cfg);
     fail("incorrectly permitted PackedGitWindowSize > PackedGitLimit");
   } catch (IllegalArgumentException e) {
     assertEquals("Window size must be < limit", e.getMessage());
   }
 }
コード例 #7
0
 public void testConfigureCache_Limits1() {
   // This test is just to force coverage over some lower bounds for
   // the table. We don't want the table to wind up with too small
   // of a size. This is highly dependent upon the table allocation
   // algorithm actually implemented in WindowCache.
   //
   final WindowCacheConfig cfg = new WindowCacheConfig();
   cfg.setPackedGitLimit(6 * 4096 / 5);
   cfg.setPackedGitWindowSize(4096);
   WindowCache.reconfigure(cfg);
 }
コード例 #8
0
 /**
  * Modify the configuration of the window cache.
  *
  * <p>The new configuration is applied immediately. If the new limits are smaller than what what
  * is currently cached, older entries will be purged as soon as possible to allow the cache to
  * meet the new limit.
  *
  * @param packedGitLimit maximum number of bytes to hold within this instance.
  * @param packedGitWindowSize number of bytes per window within the cache.
  * @param packedGitMMAP true to enable use of mmap when creating windows.
  * @param deltaBaseCacheLimit number of bytes to hold in the delta base cache.
  * @deprecated Use {@link WindowCacheConfig} instead.
  */
 public static void reconfigure(
     final int packedGitLimit,
     final int packedGitWindowSize,
     final boolean packedGitMMAP,
     final int deltaBaseCacheLimit) {
   final WindowCacheConfig c = new WindowCacheConfig();
   c.setPackedGitLimit(packedGitLimit);
   c.setPackedGitWindowSize(packedGitWindowSize);
   c.setPackedGitMMAP(packedGitMMAP);
   c.setDeltaBaseCacheLimit(deltaBaseCacheLimit);
   reconfigure(c);
 }
コード例 #9
0
  private WindowCache(final WindowCacheConfig cfg) {
    super(tableSize(cfg), lockCount(cfg));
    maxFiles = cfg.getPackedGitOpenFiles();
    maxBytes = cfg.getPackedGitLimit();
    mmap = cfg.isPackedGitMMAP();
    windowSizeShift = bits(cfg.getPackedGitWindowSize());
    windowSize = 1 << windowSizeShift;

    openFiles = new AtomicInteger();
    openBytes = new AtomicLong();

    if (maxFiles < 1) throw new IllegalArgumentException("Open files must be >= 1");
    if (maxBytes < windowSize) throw new IllegalArgumentException("Window size must be < limit");
  }
コード例 #10
0
 private static int lockCount(final WindowCacheConfig cfg) {
   return Math.max(cfg.getPackedGitOpenFiles(), 32);
 }