From 6e90b48ee1c271e244615eb255070fe451a1f3e7 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Wed, 30 Mar 2022 08:00:44 +0200 Subject: housekeeping: Skip repacking empty repositories When a repository does not have any bitmaps or in case it is missing bloom filters in the commit graph we always try to do a full repack in order to generate these data structures. This logic is required because: - Bitmaps are only generated by git-repack(1) for full repacks. This limitation exists because there can only be one bitmap per repository. - In case commit-graphs exist but missing bloom filters we need to completely rewrite them in order to enable this extension. While the logic makes sense, it also causes us to repack repositories which are empty: they don't contain either of these data structures, and consequentially we think we need a full repack. While this is not a huge problem because git-repack(1) would finish fast anyway in case the repo doesn't contain any objects, we still needlessly spawn a process. Also, our metrics report that we're doing a lot of full repacks, which can be confusing. Improve our heuristics by taking into account whether the repository has objects at all. If there aren't any, we can avoid all this busywork and just skip repacking altogether. Changelog: changed --- internal/gitaly/service/repository/optimize_test.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'internal/gitaly/service') diff --git a/internal/gitaly/service/repository/optimize_test.go b/internal/gitaly/service/repository/optimize_test.go index 0bc1932d5..a843b5668 100644 --- a/internal/gitaly/service/repository/optimize_test.go +++ b/internal/gitaly/service/repository/optimize_test.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "strings" "testing" "time" @@ -107,6 +108,11 @@ func TestOptimizeRepository(t *testing.T) { ) } + // Write a blob whose OID is known to have a "17" prefix, which is required such that + // OptimizeRepository would try to repack at all. + blobOIDWith17Prefix := gittest.WriteBlob(t, cfg, testRepoPath, []byte("32")) + require.True(t, strings.HasPrefix(blobOIDWith17Prefix.String(), "17")) + bitmaps, err := filepath.Glob(filepath.Join(testRepoPath, "objects", "pack", "*.bitmap")) require.NoError(t, err) require.Empty(t, bitmaps) -- cgit v1.2.3