diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2024-11-20 12:36:42 +0000 |
---|---|---|
committer | Gerrit Code Review <support@gerrithub.io> | 2024-11-20 12:36:42 +0000 |
commit | 2c86ef2427ad3c65bfa4dee90311408255869638 (patch) | |
tree | e6856cc95ac3f21545101a3629a781ca90d57306 | |
parent | f6fd48bef948f0bae1afbe207ddf98b2af9565d5 (diff) | |
parent | 469928898db10d4b19bd34658d3b2f93f12952b3 (diff) | |
download | jgit-2c86ef2427ad3c65bfa4dee90311408255869638.tar.gz jgit-2c86ef2427ad3c65bfa4dee90311408255869638.zip |
Merge "Add numberOfObjectsSinceBitmap to RepoStatistics" into stable-6.10
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcSinceBitmapStatisticsTest.java (renamed from org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcNumberOfPackFilesSinceBitmapStatisticsTest.java) | 82 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java | 18 |
2 files changed, 93 insertions, 7 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcNumberOfPackFilesSinceBitmapStatisticsTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcSinceBitmapStatisticsTest.java index fa13bb57c8..3cd766c4e9 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcNumberOfPackFilesSinceBitmapStatisticsTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcSinceBitmapStatisticsTest.java @@ -14,17 +14,21 @@ import static org.junit.Assert.assertEquals; import java.io.IOException; import java.nio.file.Files; +import java.util.Collection; import java.util.stream.StreamSupport; +import org.eclipse.jgit.internal.storage.file.GC.RepoStatistics; import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.revwalk.RevCommit; import org.junit.Test; -public class GcNumberOfPackFilesSinceBitmapStatisticsTest extends GcTestCase { +public class GcSinceBitmapStatisticsTest extends GcTestCase { @Test - public void testShouldReportZeroObjectsForInitializedRepo() + public void testShouldReportZeroPacksAndObjectsForInitializedRepo() throws IOException { - assertEquals(0L, gc.getStatistics().numberOfPackFilesSinceBitmap); + RepoStatistics s = gc.getStatistics(); + assertEquals(0L, s.numberOfPackFilesSinceBitmap); + assertEquals(0L, s.numberOfObjectsSinceBitmap); } @Test @@ -37,7 +41,17 @@ public class GcNumberOfPackFilesSinceBitmapStatisticsTest extends GcTestCase { } @Test - public void testShouldReportNoObjectsDirectlyAfterGc() throws Exception { + public void testShouldReportAllObjectsWhenNoGcWasPerformed() + throws Exception { + tr.packAndPrune(); + + assertEquals( + getNumberOfObjectsInPacks(repo.getObjectDatabase().getPacks()), + gc.getStatistics().numberOfObjectsSinceBitmap); + } + + @Test + public void testShouldReportNoPacksDirectlyAfterGc() throws Exception { // given addCommit(null); gc.gc().get(); @@ -46,7 +60,17 @@ public class GcNumberOfPackFilesSinceBitmapStatisticsTest extends GcTestCase { } @Test - public void testShouldReportNewObjectsSinceGcWhenRepositoryProgresses() + public void testShouldReportNoObjectsDirectlyAfterGc() throws Exception { + // given + addCommit(null); + assertEquals(2L, gc.getStatistics().numberOfObjectsSinceBitmap); + + gc.gc().get(); + assertEquals(0L, gc.getStatistics().numberOfObjectsSinceBitmap); + } + + @Test + public void testShouldReportNewPacksSinceGcWhenRepositoryProgresses() throws Exception { // commit & gc RevCommit parent = addCommit(null); @@ -61,7 +85,23 @@ public class GcNumberOfPackFilesSinceBitmapStatisticsTest extends GcTestCase { } @Test - public void testShouldReportNewObjectsFromTheLatestBitmapWhenRepositoryProgresses() + public void testShouldReportNewObjectsSinceGcWhenRepositoryProgresses() + throws Exception { + // commit & gc + RevCommit parent = addCommit(null); + gc.gc().get(); + assertEquals(0L, gc.getStatistics().numberOfObjectsSinceBitmap); + + // progress & pack + addCommit(parent); + assertEquals(1L, gc.getStatistics().numberOfObjectsSinceBitmap); + + tr.packAndPrune(); + assertEquals(3L, gc.getStatistics().numberOfObjectsSinceBitmap); + } + + @Test + public void testShouldReportNewPacksFromTheLatestBitmapWhenRepositoryProgresses() throws Exception { // commit & gc RevCommit parent = addCommit(null); @@ -80,6 +120,26 @@ public class GcNumberOfPackFilesSinceBitmapStatisticsTest extends GcTestCase { assertEquals(1L, gc.getStatistics().numberOfPackFilesSinceBitmap); } + @Test + public void testShouldReportNewObjectsFromTheLatestBitmapWhenRepositoryProgresses() + throws Exception { + // commit & gc + RevCommit parent = addCommit(null); + gc.gc().get(); + + // progress & gc + parent = addCommit(parent); + gc.gc().get(); + assertEquals(0L, gc.getStatistics().numberOfObjectsSinceBitmap); + + // progress & pack + addCommit(parent); + assertEquals(1L, gc.getStatistics().numberOfObjectsSinceBitmap); + + tr.packAndPrune(); + assertEquals(4L, gc.getStatistics().numberOfObjectsSinceBitmap); + } + private RevCommit addCommit(RevCommit parent) throws Exception { return tr.branch("master").commit() .author(new PersonIdent("repo-metrics", "repo@metrics.com")) @@ -94,4 +154,14 @@ public class GcNumberOfPackFilesSinceBitmapStatisticsTest extends GcTestCase { .spliterator(), false) .count(); } + + private long getNumberOfObjectsInPacks(Collection<Pack> packs) { + return packs.stream().mapToLong(pack -> { + try { + return pack.getObjectCount(); + } catch (IOException e) { + throw new RuntimeException(e); + } + }).sum(); + } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java index 9494057a60..b33afed131 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java @@ -1515,6 +1515,12 @@ public class GC { public long numberOfPackFilesSinceBitmap; /** + * The number of objects stored in pack files and as loose object + * created after the last bitmap generation. + */ + public long numberOfObjectsSinceBitmap; + + /** * The number of objects stored as loose objects. */ public long numberOfLooseObjects; @@ -1551,6 +1557,8 @@ public class GC { b.append(", numberOfPackFiles=").append(numberOfPackFiles); //$NON-NLS-1$ b.append(", numberOfPackFilesSinceBitmap=") //$NON-NLS-1$ .append(numberOfPackFilesSinceBitmap); + b.append(", numberOfObjectsSinceBitmap=") //$NON-NLS-1$ + .append(numberOfObjectsSinceBitmap); b.append(", numberOfLooseObjects=").append(numberOfLooseObjects); //$NON-NLS-1$ b.append(", numberOfLooseRefs=").append(numberOfLooseRefs); //$NON-NLS-1$ b.append(", numberOfPackedRefs=").append(numberOfPackedRefs); //$NON-NLS-1$ @@ -1571,14 +1579,19 @@ public class GC { public RepoStatistics getStatistics() throws IOException { RepoStatistics ret = new RepoStatistics(); Collection<Pack> packs = repo.getObjectDatabase().getPacks(); + long latestBitmapTime = Long.MIN_VALUE; for (Pack p : packs) { - ret.numberOfPackedObjects += p.getIndex().getObjectCount(); + long packedObjects = p.getIndex().getObjectCount(); + ret.numberOfPackedObjects += packedObjects; ret.numberOfPackFiles++; ret.sizeOfPackedObjects += p.getPackFile().length(); if (p.getBitmapIndex() != null) { ret.numberOfBitmaps += p.getBitmapIndex().getBitmapCount(); + latestBitmapTime = p.getFileSnapshot().lastModifiedInstant() + .toEpochMilli(); } else { ret.numberOfPackFilesSinceBitmap++; + ret.numberOfObjectsSinceBitmap += packedObjects; } } File objDir = repo.getObjectsDirectory(); @@ -1595,6 +1608,9 @@ public class GC { continue; ret.numberOfLooseObjects++; ret.sizeOfLooseObjects += f.length(); + if (f.lastModified() > latestBitmapTime) { + ret.numberOfObjectsSinceBitmap ++; + } } } } |