]> source.dussan.org Git - jgit.git/commitdiff
DfsPackFile: Enable/disable object size index via DfsReaderOptions 23/1196923/7
authorIvan Frade <ifrade@google.com>
Mon, 1 Jul 2024 19:24:36 +0000 (12:24 -0700)
committerIvan Frade <ifrade@google.com>
Wed, 10 Jul 2024 21:47:03 +0000 (14:47 -0700)
DfsPackFile always uses the object size index if available. That is
the desired final state, but for a safe rollout, we should be able to
disable using the object size index.

Add an option (dfs.useObjectSizeIndex) to enable/disable the usage of
the object size index. False by default.

This changes the default from true to false. It only makes a different
for the DFS stack when writing of the index was explicitely
enabled. This is an optimization, so it shouldn't cause any
regression. Operators can restore previous behaviour setting
"dfs.useObjectSizeIndex" to true.

Change-Id: I44bf5a57e3942a4ecfe66d58bfa9175e99f96fcc

org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsInserterTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackFileTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackParserTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsReaderTest.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReaderOptions.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java

index e193de976407fa0fd30e3bb31d2c67f21a28baf4..2be11d32ea02a4f9a65ac09a148c18f2bd17b627 100644 (file)
@@ -18,6 +18,7 @@ import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.concurrent.TimeUnit;
+
 import org.eclipse.jgit.internal.storage.commitgraph.CommitGraph;
 import org.eclipse.jgit.internal.storage.commitgraph.CommitGraphWriter;
 import org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource;
@@ -1171,6 +1172,7 @@ public class DfsGarbageCollectorTest {
 
                gcWithObjectSizeIndex(10);
 
+               odb.getReaderOptions().setUseObjectSizeIndex(true);
                DfsReader reader = odb.newReader();
                DfsPackFile gcPack = findFirstBySource(odb.getPacks(), GC);
                assertTrue(gcPack.hasObjectSizeIndex(reader));
@@ -1191,6 +1193,7 @@ public class DfsGarbageCollectorTest {
 
                gcWithObjectSizeIndex(10);
 
+               odb.getReaderOptions().setUseObjectSizeIndex(true);
                DfsReader reader = odb.newReader();
                DfsPackFile gcPack = findFirstBySource(odb.getPacks(), GC);
                assertTrue(gcPack.hasObjectSizeIndex(reader));
index b84a0b00aefda0a98fe843a98cba11cf0d71209e..0b558edf2cb9d774e63706478c26d3ba0965d204 100644 (file)
@@ -295,6 +295,7 @@ public class DfsInserterTest {
        public void testObjectSizeIndexOnInsert() throws IOException {
                db.getConfig().setInt(CONFIG_PACK_SECTION, null,
                                CONFIG_KEY_MIN_BYTES_OBJ_SIZE_INDEX, 0);
+               db.getObjectDatabase().getReaderOptions().setUseObjectSizeIndex(true);
 
                byte[] contents = Constants.encode("foo");
                ObjectId fooId;
index d21e51f2761ea6ec3d221a76f7b396ccac7d88d3..bc851f8ddeedcbe990d1a57483e9f11294c5f27d 100644 (file)
@@ -126,6 +126,7 @@ public class DfsPackFileTest {
                setObjectSizeIndexMinBytes(0);
                ObjectId blobId = setupPack(512, 800);
 
+               db.getObjectDatabase().getReaderOptions().setUseObjectSizeIndex(true);
                DfsReader reader = db.getObjectDatabase().newReader();
                DfsPackFile pack = db.getObjectDatabase().getPacks()[0];
                assertTrue(pack.hasObjectSizeIndex(reader));
index 130af277731b34879ecdecb85560cb39219a3f51..c1cd231c660eb6925f79591d7b88c7cc424425f5 100644 (file)
@@ -61,6 +61,7 @@ public class DfsPackParserTest {
                        ins.flush();
                }
 
+               repo.getObjectDatabase().getReaderOptions().setUseObjectSizeIndex(true);
                DfsReader reader = repo.getObjectDatabase().newReader();
                PackList packList = repo.getObjectDatabase().getPackList();
                assertEquals(1, packList.packs.length);
index 254184ee8000fcad258259c2b033bcc3f05c0bd6..a0c228906ee2b1a447291dd0069b27a7fc98e85c 100644 (file)
@@ -37,6 +37,8 @@ public class DfsReaderTest {
        @Before
        public void setUp() {
                db = new InMemoryRepository(new DfsRepositoryDescription("test"));
+               // These tests assume the object size index is enabled.
+               db.getObjectDatabase().getReaderOptions().setUseObjectSizeIndex(true);
        }
 
        @Test
index 3e4d4d300ca1cae215e862a5c2640c129d3808e7..b94a84a41c52c0e5bb3788117eca6b229e253d76 100644 (file)
@@ -354,6 +354,7 @@ public final class DfsPackFile extends BlockBasedFile {
                }
 
                if (objectSizeIndexLoadAttempted
+                               || !ctx.getOptions().shouldUseObjectSizeIndex()
                                || !desc.hasFileExt(OBJECT_SIZE_INDEX)) {
                        // Pack doesn't have object size index
                        return null;
index f2ac461deb8459133410b6c5a7129a3477fc9b89..5f5e81977b6a5e86ed506808287a308ab94181bc 100644 (file)
@@ -15,6 +15,7 @@ import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_DFS_SECTION;
 import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_DELTA_BASE_CACHE_LIMIT;
 import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_STREAM_BUFFER;
 import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_STREAM_FILE_THRESHOLD;
+import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_USE_OBJECT_SIZE_INDEX;
 
 import org.eclipse.jgit.lib.Config;
 import org.eclipse.jgit.storage.pack.PackConfig;
@@ -36,6 +37,8 @@ public class DfsReaderOptions {
 
        private boolean loadRevIndexInParallel;
 
+       private boolean useObjectSizeIndex;
+
        /**
         * Create a default reader configuration.
         */
@@ -136,6 +139,28 @@ public class DfsReaderOptions {
                return this;
        }
 
+       /**
+        * Use the object size index if available.
+        *
+        * @return true if the reader should try to use the object size index. if
+        *         false, the reader ignores that index.
+        */
+       public boolean shouldUseObjectSizeIndex() {
+               return useObjectSizeIndex;
+       }
+
+       /**
+        * Set if the reader should try to use the object size index
+        *
+        * @param useObjectSizeIndex true to use it, false to ignore the object size index
+        *
+        * @return {@code this}
+        */
+       public DfsReaderOptions setUseObjectSizeIndex(boolean useObjectSizeIndex) {
+               this.useObjectSizeIndex = useObjectSizeIndex;
+               return this;
+       }
+
        /**
         * Update properties by setting fields from the configuration.
         * <p>
@@ -168,6 +193,10 @@ public class DfsReaderOptions {
                                CONFIG_DFS_SECTION,
                                CONFIG_KEY_STREAM_BUFFER,
                                getStreamPackBufferSize()));
+
+               setUseObjectSizeIndex(rc.getBoolean(CONFIG_CORE_SECTION,
+                               CONFIG_DFS_SECTION, CONFIG_KEY_USE_OBJECT_SIZE_INDEX,
+                               false));
                return this;
        }
 }
index 0edf3c5ad026a9497f045715c7f5efa58fccc6f4..e9fbc6569644d1df7d477a182df2e9a4da87899c 100644 (file)
@@ -1012,4 +1012,11 @@ public final class ConfigConstants {
         * @since 6.7
         */
        public static final String CONFIG_KEY_READ_CHANGED_PATHS = "readChangedPaths";
+
+       /**
+        * The "useObjectSizeIndex" key
+        *
+        * @since 7.0
+        */
+       public static final String CONFIG_KEY_USE_OBJECT_SIZE_INDEX = "useObjectSizeIndex";
 }