aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/lib
diff options
context:
space:
mode:
authorTerry Parker <tparker@google.com>2021-01-24 22:18:21 -0800
committerTerry Parker <tparker@google.com>2021-01-28 22:17:26 -0800
commitdbd05433ecc77d8044e567f512bb721ff259d7f8 (patch)
tree1ac4351f44e572f794264bc5e8857ed82cf83286 /org.eclipse.jgit/src/org/eclipse/jgit/lib
parent84dbc2d43169cdd41c79d853b75483cfd76ce7d6 (diff)
downloadjgit-dbd05433ecc77d8044e567f512bb721ff259d7f8.tar.gz
jgit-dbd05433ecc77d8044e567f512bb721ff259d7f8.zip
Move reachability checker generation into the ObjectReader object
Reachability checkers are retrieved from RevWalk and ObjectWalk objects: * RevWalk.createReachabilityChecker() * ObjectWalk.createObjectReachabilityChecker() Since RevWalks and ObjectWalks are themselves directly instantiated in hundreds of places (e.g. UploadPack...) overriding them in a consistent way requires overloading 100s of methods, which isn't feasible. Moving reachability checker generation to a more central place solves that problem. The ObjectReader object seems a good place from which to get reachability checkers, because reachability checkers return information about relationships between objects. ObjectDatabases delegate many operations to ObjectReaders, and reachability bitmaps are attached to ObjectReaders. The Bitmapped and Pedestrian reachability checker objects were package private in the org.eclipse.jgit.revwalk package. This change makes them public and moves them to the org.eclipse.jgit.internal.revwalk package. Corresponding tests are also moved. Motivation: 1) Reachability checking algorithms need to scale. One of the internal Android repositories has ~2.4 million refs/changes/* references, causing bad long tail performance in reachability checks. 2) Reachability check performance is impacted by repository topography: number of refs, number of objects, amounts of related vs. unrelated history. 3) Reachability check performance is also affected by per-branch access (Gerrit branch permissions) since different users can see different branches. 4) Reachability check performance isn't affected by any state in a RevWalk or ObjectWalk. I don't yet know if a single algorithm will work for all cases in #2 and #3. We may need to evolve the ReachabilityChecker interfaces over time to solve the Gerrit branch permissions case, or use Gerrit-specific identity information to solve that in an efficient way. This change takes the existing public API and moves it to the ObjectReader/whole repository level, which is where we can do consistent customizations for #2 and #3. We intend to upstream the best of whatever works, but anticipate the need for multiple rounds of experimentation. Change-Id: I9185feff43551fb387957c436112d5250486833d Signed-off-by: Terry Parker <tparker@google.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/lib')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java57
1 files changed, 57 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java
index 6bb6ae590a..718ed89142 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java
@@ -17,9 +17,18 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import org.eclipse.jgit.annotations.NonNull;
import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
+import org.eclipse.jgit.internal.revwalk.BitmappedObjectReachabilityChecker;
+import org.eclipse.jgit.internal.revwalk.BitmappedReachabilityChecker;
+import org.eclipse.jgit.internal.revwalk.PedestrianObjectReachabilityChecker;
+import org.eclipse.jgit.internal.revwalk.PedestrianReachabilityChecker;
+import org.eclipse.jgit.revwalk.ObjectReachabilityChecker;
+import org.eclipse.jgit.revwalk.ObjectWalk;
+import org.eclipse.jgit.revwalk.ReachabilityChecker;
+import org.eclipse.jgit.revwalk.RevWalk;
/**
* Reads an {@link org.eclipse.jgit.lib.ObjectDatabase} for a single thread.
@@ -408,6 +417,54 @@ public abstract class ObjectReader implements AutoCloseable {
}
/**
+ * Create a reachability checker that will use bitmaps if possible.
+ *
+ * @param rw
+ * revwalk for use by the reachability checker
+ * @return the most efficient reachability checker for this repository.
+ * @throws IOException
+ * if it cannot open any of the underlying indices.
+ *
+ * @since 5.11
+ */
+ @NonNull
+ public ReachabilityChecker createReachabilityChecker(RevWalk rw)
+ throws IOException {
+ if (getBitmapIndex() != null) {
+ return new BitmappedReachabilityChecker(rw);
+ }
+
+ return new PedestrianReachabilityChecker(true, rw);
+ }
+
+ /**
+ * Create an object reachability checker that will use bitmaps if possible.
+ *
+ * This reachability checker accepts any object as target. For checks
+ * exclusively between commits, use
+ * {@link #createReachabilityChecker(RevWalk)}.
+ *
+ * @param ow
+ * objectwalk for use by the reachability checker
+ * @return the most efficient object reachability checker for this
+ * repository.
+ *
+ * @throws IOException
+ * if it cannot open any of the underlying indices.
+ *
+ * @since 5.11
+ */
+ @NonNull
+ public ObjectReachabilityChecker createObjectReachabilityChecker(
+ ObjectWalk ow) throws IOException {
+ if (getBitmapIndex() != null) {
+ return new BitmappedObjectReachabilityChecker(ow);
+ }
+
+ return new PedestrianObjectReachabilityChecker(ow);
+ }
+
+ /**
* Get the {@link org.eclipse.jgit.lib.ObjectInserter} from which this
* reader was created using {@code inserter.newReader()}
*