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:
authorJustin Tobler <jtobler@gitlab.com>2022-11-10 18:25:16 +0300
committerJustin Tobler <jtobler@gitlab.com>2022-11-10 18:25:16 +0300
commit658f79a7dedc449d3bf8278784e8fda593e769ac (patch)
treea0ed23f75d1bdcccd1aa9cdbe9ff496b5d62d2c8
parent1e9c49fe63942cf425ce08499b22dbd2de06b00f (diff)
parent6c4c312c381145f95bdb3418a6bfd5588c2e0933 (diff)
Merge branch 'kn-fix-dst-bug-housekeeping' into 'master'
housekeeping: Remove usage of `Time.AddDate(...)` See merge request https://gitlab.com/gitlab-org/gitaly/-/merge_requests/5035 Merged-by: Justin Tobler <jtobler@gitlab.com> Approved-by: Quang-Minh Nguyen <qmnguyen@gitlab.com> Approved-by: Justin Tobler <jtobler@gitlab.com> Co-authored-by: Karthik Nayak <knayak@gitlab.com>
-rw-r--r--internal/git/housekeeping/optimization_strategy.go6
-rw-r--r--internal/git/housekeeping/optimization_strategy_test.go2
-rw-r--r--internal/git/housekeeping/optimize_repository_test.go4
3 files changed, 8 insertions, 4 deletions
diff --git a/internal/git/housekeeping/optimization_strategy.go b/internal/git/housekeeping/optimization_strategy.go
index 30a402664..eb436f8d6 100644
--- a/internal/git/housekeeping/optimization_strategy.go
+++ b/internal/git/housekeeping/optimization_strategy.go
@@ -32,6 +32,10 @@ type OptimizationStrategy interface {
ShouldWriteCommitGraph() (bool, WriteCommitGraphConfig)
}
+// CutOffTime is time delta that is used to indicate cutoff wherein an object would be considered
+// old. Currently this is set to being 2 weeks (2 * 7days * 24hours).
+const CutOffTime = -14 * 24 * time.Hour
+
// HeuristicalOptimizationStrategy is an optimization strategy that is based on a set of
// heuristics.
type HeuristicalOptimizationStrategy struct {
@@ -91,7 +95,7 @@ func NewHeuristicalOptimizationStrategy(ctx context.Context, repo *localrepo.Rep
return strategy, fmt.Errorf("estimating loose object count: %w", err)
}
- strategy.oldLooseObjectCount, err = estimateLooseObjectCount(repo, time.Now().AddDate(0, 0, -14))
+ strategy.oldLooseObjectCount, err = estimateLooseObjectCount(repo, time.Now().Add(CutOffTime))
if err != nil {
return strategy, fmt.Errorf("estimating old loose object count: %w", err)
}
diff --git a/internal/git/housekeeping/optimization_strategy_test.go b/internal/git/housekeeping/optimization_strategy_test.go
index f9b293267..b1db18b57 100644
--- a/internal/git/housekeeping/optimization_strategy_test.go
+++ b/internal/git/housekeeping/optimization_strategy_test.go
@@ -74,7 +74,7 @@ func TestNewHeuristicalOptimizationStrategy_variousParameters(t *testing.T) {
// ... and one stale object.
staleObjectPath := filepath.Join(shard, "5678")
require.NoError(t, os.WriteFile(staleObjectPath, nil, 0o644))
- twoWeeksAgo := time.Now().Add(-1 * 2 * 7 * 24 * time.Hour)
+ twoWeeksAgo := time.Now().Add(CutOffTime)
require.NoError(t, os.Chtimes(staleObjectPath, twoWeeksAgo, twoWeeksAgo))
return repoProto
diff --git a/internal/git/housekeeping/optimize_repository_test.go b/internal/git/housekeeping/optimize_repository_test.go
index 67ae373e3..f69c8840b 100644
--- a/internal/git/housekeeping/optimize_repository_test.go
+++ b/internal/git/housekeeping/optimize_repository_test.go
@@ -277,7 +277,7 @@ gitaly_housekeeping_tasks_total{housekeeping_task="total", status="success"} 1
// We set the object's mtime to be almost two weeks ago. Given that
// our timeout is at exactly two weeks this shouldn't caused them to
// get pruned.
- almostTwoWeeksAgo := time.Now().AddDate(0, 0, -14).Add(time.Minute)
+ almostTwoWeeksAgo := time.Now().Add(CutOffTime).Add(time.Minute)
for i := 0; i < 10; i++ {
blobPath := filepath.Join(repoPath, "objects", "17", fmt.Sprintf("%d", i))
@@ -309,7 +309,7 @@ gitaly_housekeeping_tasks_total{housekeeping_task="total", status="success"} 1
// broken, and thus we'll retry to prune them afterwards.
require.NoError(t, os.MkdirAll(filepath.Join(repoPath, "objects", "17"), 0o755))
- moreThanTwoWeeksAgo := time.Now().AddDate(0, 0, -14).Add(-time.Minute)
+ moreThanTwoWeeksAgo := time.Now().Add(CutOffTime).Add(-time.Minute)
for i := 0; i < 10; i++ {
blobPath := filepath.Join(repoPath, "objects", "17", fmt.Sprintf("%d", i))