Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-07-13 13:43:48 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-07-15 09:56:52 +0300
commit84e99923567045f71b90b804f07f81ea4fef977d (patch)
tree1a89c0928bc4893aa1e98261d2f6c8e02b9cd936
parentfb7991332a935cbb7c6dbea053ef669a96c6850b (diff)
housekeeping: Fix off-by-one in packfile count required to repack
The lower limit of packfiles required to exist in order to trigger a repack has been picked as five packed. It is clearly documented as such, and tests try to exercise this. There has been an off-by-one bug though, which causes us to set the lower limit to six packfiles. And the tests that intend to verify this behaviour have the same off-by-one bug. Fix this off-by-one and make the heuristic work as advertised. Changelog: fixed
-rw-r--r--internal/git/housekeeping/optimize_repository.go2
-rw-r--r--internal/git/housekeeping/optimize_repository_test.go2
2 files changed, 2 insertions, 2 deletions
diff --git a/internal/git/housekeeping/optimize_repository.go b/internal/git/housekeeping/optimize_repository.go
index eedc1571f..4bd48999a 100644
--- a/internal/git/housekeeping/optimize_repository.go
+++ b/internal/git/housekeeping/optimize_repository.go
@@ -233,7 +233,7 @@ func needsRepacking(repo *localrepo.Repo) (bool, RepackObjectsConfig, error) {
//
// This is a heuristic and thus imperfect by necessity. We may tune it as we gain experience
// with the way it behaves.
- if int64(math.Max(5, math.Log(float64(largestPackfileSize))/math.Log(1.3))) < packfileCount {
+ if int64(math.Max(5, math.Log(float64(largestPackfileSize))/math.Log(1.3))) <= packfileCount {
return true, RepackObjectsConfig{
FullRepack: true,
WriteBitmap: !hasAlternate,
diff --git a/internal/git/housekeeping/optimize_repository_test.go b/internal/git/housekeeping/optimize_repository_test.go
index 08aa7ee13..59bbd5cd1 100644
--- a/internal/git/housekeeping/optimize_repository_test.go
+++ b/internal/git/housekeeping/optimize_repository_test.go
@@ -206,7 +206,7 @@ func TestNeedsRepacking(t *testing.T) {
// And then we create one less packfile than we need to hit the boundary.
// This is done to assert that we indeed don't repack before hitting the
// boundary.
- for i := 0; i < tc.requiredPackfiles-1; i++ {
+ for i := 0; i < tc.requiredPackfiles-2; i++ {
additionalPackfile, err := os.Create(filepath.Join(packDir, fmt.Sprintf("%d.pack", i)))
require.NoError(t, err)
testhelper.MustClose(t, additionalPackfile)