Merge "DfsGarbageCollector: provide commit graph stats"

This commit is contained in:
Jonathan Tan 2023-08-21 13:07:51 -04:00 committed by Gerrit Code Review @ Eclipse.org
commit f8f5979aa2
3 changed files with 41 additions and 2 deletions

View File

@ -20,6 +20,7 @@
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;
import org.eclipse.jgit.internal.storage.reftable.RefCursor;
import org.eclipse.jgit.internal.storage.reftable.ReftableConfig;
@ -1103,6 +1104,22 @@ public void commitGraphWithoutGCrestPack() throws Exception {
}
}
@Test
public void produceCommitGraphAndBloomFilter() throws Exception {
String head = "refs/heads/head1";
git.branch(head).commit().message("0").noParents().create();
gcWithCommitGraphAndBloomFilter();
assertEquals(1, odb.getPacks().length);
DfsPackFile pack = odb.getPacks()[0];
DfsPackDescription desc = pack.getPackDescription();
CommitGraphWriter.Stats stats = desc.getCommitGraphStats();
assertNotNull(stats);
assertEquals(1, stats.getChangedPathFiltersComputed());
}
@Test
public void objectSizeIdx_reachableBlob_bigEnough_indexed() throws Exception {
String master = "refs/heads/master";
@ -1177,6 +1194,13 @@ private void gcWithCommitGraph() throws IOException {
run(gc);
}
private void gcWithCommitGraphAndBloomFilter() throws IOException {
DfsGarbageCollector gc = new DfsGarbageCollector(repo);
gc.setWriteCommitGraph(true);
gc.setWriteBloomFilter(true);
run(gc);
}
private void gcWithObjectSizeIndex(int threshold) throws IOException {
DfsGarbageCollector gc = new DfsGarbageCollector(repo);
gc.getPackConfig().setMinBytesForObjSizeIndex(threshold);

View File

@ -36,7 +36,6 @@
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.internal.storage.commitgraph.CommitGraphWriter;
@ -789,10 +788,11 @@ private void writeCommitGraph(DfsPackDescription pack, ProgressMonitor pm)
CountingOutputStream cnt = new CountingOutputStream(out);
CommitGraphWriter writer = new CommitGraphWriter(gcs,
writeBloomFilter);
writer.write(pm, cnt);
CommitGraphWriter.Stats stats = writer.write(pm, cnt);
pack.addFileExt(COMMIT_GRAPH);
pack.setFileSize(COMMIT_GRAPH, cnt.getCount());
pack.setBlockSize(COMMIT_GRAPH, out.blockSize());
pack.setCommitGraphStats(stats);
}
}
}

View File

@ -17,6 +17,7 @@
import java.util.Comparator;
import org.eclipse.jgit.annotations.NonNull;
import org.eclipse.jgit.internal.storage.commitgraph.CommitGraphWriter;
import org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource;
import org.eclipse.jgit.internal.storage.pack.PackExt;
import org.eclipse.jgit.internal.storage.reftable.ReftableWriter;
@ -144,6 +145,7 @@ static Comparator<DfsPackDescription> reuseComparator() {
private PackStatistics packStats;
private ReftableWriter.Stats refStats;
private CommitGraphWriter.Stats commitGraphStats;
private int extensions;
private int indexVersion;
private long estimatedPackSize;
@ -480,6 +482,19 @@ void setReftableStats(ReftableWriter.Stats stats) {
setBlockSize(REFTABLE, stats.refBlockSize());
}
/**
* Get stats from the sibling commit graph, if created.
*
* @return stats from the sibling commit graph, if created.
*/
public CommitGraphWriter.Stats getCommitGraphStats() {
return commitGraphStats;
}
void setCommitGraphStats(CommitGraphWriter.Stats stats) {
this.commitGraphStats = stats;
}
/**
* Discard the pack statistics, if it was populated.
*