]> source.dussan.org Git - jgit.git/commitdiff
Make streamFileThreshold configurable 01/70601/4
authorKevin Corcoran <kevin.corcoran@puppetlabs.com>
Wed, 13 Apr 2016 22:55:08 +0000 (15:55 -0700)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Mon, 24 Oct 2016 05:00:02 +0000 (14:00 +0900)
Previously, the streamFileThreshold, the threshold at which a file
would be streamed rather than loaded entirely into memory, was only
configurable on a global basis.

This commit makes this threshold configurable on a per-loader basis.

Bug: 490404
Change-Id: I492c18c3155dbf56eedda9044a61d76120fd75f9
Signed-off-by: Kevin Corcoran <kevin.corcoran@puppetlabs.com>
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileTest.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java

index ba07d6842f1f85c0ad4a67de703cddc74eeb9922..1c10bb335ab0c8e5cd7b5dd9224093fea134b60b 100644 (file)
@@ -310,6 +310,27 @@ public class PackFileTest extends LocalDiskRepositoryTestCase {
                }
        }
 
+       @Test
+       public void testConfigurableStreamFileThreshold() throws Exception {
+               byte[] data = getRng().nextBytes(300);
+               RevBlob id = tr.blob(data);
+               tr.branch("master").commit().add("A", id).create();
+               tr.packAndPrune();
+               assertTrue("has blob", wc.has(id));
+
+               ObjectLoader ol = wc.open(id);
+               ObjectStream in = ol.openStream();
+               assertTrue(in instanceof ObjectStream.SmallStream);
+               assertEquals(300, in.available());
+               in.close();
+
+               wc.setStreamFileThreshold(299);
+               ol = wc.open(id);
+               in = ol.openStream();
+               assertTrue(in instanceof ObjectStream.Filter);
+               assertEquals(1, in.available());
+       }
+
        private static byte[] clone(int first, byte[] base) {
                byte[] r = new byte[base.length];
                System.arraycopy(base, 1, r, 1, r.length - 1);
index 2f61dea0d5b753e34531207c7a4c49d8ee2a8354..8c9329503fb5eeabb8f9445c1ca3ef3051da46f5 100644 (file)
@@ -113,6 +113,7 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs {
 
        DfsReader(DfsObjDatabase db) {
                this.db = db;
+               this.streamFileThreshold = db.getReaderOptions().getStreamFileThreshold();
        }
 
        DfsReaderOptions getOptions() {
@@ -125,10 +126,6 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs {
                return baseCache;
        }
 
-       int getStreamFileThreshold() {
-               return getOptions().getStreamFileThreshold();
-       }
-
        @Override
        public ObjectReader newReader() {
                return new DfsReader(db);
index a2c0561ae19169e00fae46b9b253f0404c03eac5..a742d1747e69e599c6b7033822ba802be6ceb7dc 100644 (file)
@@ -94,12 +94,14 @@ final class WindowCursor extends ObjectReader implements ObjectReuseAsIs {
        WindowCursor(FileObjectDatabase db) {
                this.db = db;
                this.createdFromInserter = null;
+               this.streamFileThreshold = WindowCache.getStreamFileThreshold();
        }
 
        WindowCursor(FileObjectDatabase db,
                        @Nullable ObjectDirectoryInserter createdFromInserter) {
                this.db = db;
                this.createdFromInserter = createdFromInserter;
+               this.streamFileThreshold = WindowCache.getStreamFileThreshold();
        }
 
        DeltaBaseCache getDeltaBaseCache() {
@@ -337,10 +339,6 @@ final class WindowCursor extends ObjectReader implements ObjectReuseAsIs {
                }
        }
 
-       int getStreamFileThreshold() {
-               return WindowCache.getStreamFileThreshold();
-       }
-
        @Override
        @Nullable
        public ObjectInserter getCreatedFromInserter() {
index b23145d7983d04827665541b5edfe16e6a09aff3..263fc997451d262a8f217e70ee957f798b7d3cf8 100644 (file)
@@ -65,6 +65,12 @@ public abstract class ObjectReader implements AutoCloseable {
        /** Type hint indicating the caller doesn't know the type. */
        public static final int OBJ_ANY = -1;
 
+       /**
+        * The threshold at which a file will be streamed rather than
+        * loaded entirely into memory.
+        */
+       protected int streamFileThreshold;
+
        /**
         * Construct a new reader from the same data.
         * <p>
@@ -444,6 +450,29 @@ public abstract class ObjectReader implements AutoCloseable {
        @Override
        public abstract void close();
 
+       /**
+        * Sets the threshold at which a file will be streamed rather than loaded
+        * entirely into memory
+        *
+        * @param threshold
+        *            the new threshold
+        * @since 4.6
+        */
+       public void setStreamFileThreshold(int threshold) {
+               streamFileThreshold = threshold;
+       }
+
+       /**
+        * Returns the threshold at which a file will be streamed rather than loaded
+        * entirely into memory
+        *
+        * @return the threshold in bytes
+        * @since 4.6
+        */
+       public int getStreamFileThreshold() {
+               return streamFileThreshold;
+       }
+
        /**
         * Wraps a delegate ObjectReader.
         *