diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-01-26 12:19:59 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-01-26 12:19:59 +0300 |
commit | 3669e7b87917d62b8de19d8ee2a55ce0ffef4b13 (patch) | |
tree | 60d1eb3f6f95ec8262f7f47582dc3b0ba37c779f | |
parent | 0c13491e1ad7330e5d6151c043e3ca7967f212b6 (diff) |
housekeeping: Move `IsPoolRepository()` into `git/stats`
The `housekeeping` package currently hosts the logic to decide whether a
repository is a pool repository or not. This is not a particularly good
fit, but was done in the past to avoid an import cycle. There is another
import cycle coming up though between `git/stats` and `housekeeping`, as
we want to migrate some the information into the `RepositoryInfo`
struct.
Move the functionality into `git/stats` to avoid this import cycle. It's
a much better fit anyway given that this package is responsible for
reporting various different bits about repositories already. So adding
information about whether a repository is an object pool or not feels
natural.
-rw-r--r-- | internal/git/housekeeping/objects.go | 3 | ||||
-rw-r--r-- | internal/git/housekeeping/objects_test.go | 3 | ||||
-rw-r--r-- | internal/git/housekeeping/optimization_strategy.go | 4 | ||||
-rw-r--r-- | internal/git/housekeeping/optimization_strategy_test.go | 4 | ||||
-rw-r--r-- | internal/git/housekeeping/optimize_repository_test.go | 2 | ||||
-rw-r--r-- | internal/git/objectpool/pool.go | 3 | ||||
-rw-r--r-- | internal/git/stats/object_pool.go (renamed from internal/git/housekeeping/object_pool.go) | 2 | ||||
-rw-r--r-- | internal/git/stats/object_pool_test.go (renamed from internal/git/housekeeping/object_pool_test.go) | 2 | ||||
-rw-r--r-- | internal/gitaly/service/objectpool/create.go | 4 | ||||
-rw-r--r-- | internal/praefect/delete_object_pool.go | 4 | ||||
-rw-r--r-- | internal/praefect/router_per_repository.go | 4 |
11 files changed, 19 insertions, 16 deletions
diff --git a/internal/git/housekeeping/objects.go b/internal/git/housekeeping/objects.go index e66aaf475..3e4fbaeab 100644 --- a/internal/git/housekeeping/objects.go +++ b/internal/git/housekeeping/objects.go @@ -7,6 +7,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v15/internal/git" "gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo" "gitlab.com/gitlab-org/gitaly/v15/internal/git/repository" + "gitlab.com/gitlab-org/gitaly/v15/internal/git/stats" "gitlab.com/gitlab-org/gitaly/v15/internal/metadata/featureflag" "gitlab.com/gitlab-org/gitaly/v15/internal/structerr" ) @@ -71,7 +72,7 @@ func GetRepackGitConfig(ctx context.Context, repo repository.GitRepo, bitmap boo {Key: "pack.writeBitmapLookupTable", Value: strconv.FormatBool(featureflag.WriteBitmapLookupTable.IsEnabled(ctx))}, } - if IsPoolRepository(repo) { + if stats.IsPoolRepository(repo) { config = append(config, git.ConfigPair{Key: "pack.island", Value: git.ObjectPoolRefNamespace + "/he(a)ds"}, git.ConfigPair{Key: "pack.island", Value: git.ObjectPoolRefNamespace + "/t(a)gs"}, diff --git a/internal/git/housekeeping/objects_test.go b/internal/git/housekeeping/objects_test.go index 93a8f4f88..c8005e911 100644 --- a/internal/git/housekeeping/objects_test.go +++ b/internal/git/housekeeping/objects_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo" + "gitlab.com/gitlab-org/gitaly/v15/internal/git/stats" "gitlab.com/gitlab-org/gitaly/v15/internal/metadata/featureflag" "gitlab.com/gitlab-org/gitaly/v15/internal/structerr" "gitlab.com/gitlab-org/gitaly/v15/internal/testhelper" @@ -301,7 +302,7 @@ func testRepackObjects(t *testing.T, ctx context.Context) { }) repo := localrepo.NewTestRepo(t, cfg, repoProto) - gittest.TestDeltaIslands(t, cfg, repoPath, repoPath, IsPoolRepository(repoProto), func() error { + gittest.TestDeltaIslands(t, cfg, repoPath, repoPath, stats.IsPoolRepository(repoProto), func() error { return RepackObjects(ctx, repo, RepackObjectsConfig{ FullRepack: true, }) diff --git a/internal/git/housekeeping/optimization_strategy.go b/internal/git/housekeeping/optimization_strategy.go index 39aa004ca..7790664d5 100644 --- a/internal/git/housekeeping/optimization_strategy.go +++ b/internal/git/housekeeping/optimization_strategy.go @@ -41,7 +41,7 @@ func NewHeuristicalOptimizationStrategy(ctx context.Context, repo *localrepo.Rep var strategy HeuristicalOptimizationStrategy var err error - strategy.isObjectPool = IsPoolRepository(repo) + strategy.isObjectPool = stats.IsPoolRepository(repo) strategy.info, err = stats.RepositoryInfoForRepository(repo) if err != nil { return HeuristicalOptimizationStrategy{}, fmt.Errorf("deriving repository info: %w", err) @@ -263,7 +263,7 @@ func NewEagerOptimizationStrategy(ctx context.Context, repo *localrepo.Repo) (Ea return EagerOptimizationStrategy{ hasAlternate: hasAlternate, - isObjectPool: IsPoolRepository(repo), + isObjectPool: stats.IsPoolRepository(repo), }, nil } diff --git a/internal/git/housekeeping/optimization_strategy_test.go b/internal/git/housekeeping/optimization_strategy_test.go index 093e68336..4c4bb7f75 100644 --- a/internal/git/housekeeping/optimization_strategy_test.go +++ b/internal/git/housekeeping/optimization_strategy_test.go @@ -315,7 +315,7 @@ func TestNewHeuristicalOptimizationStrategy_variousParameters(t *testing.T) { repoProto := tc.setup(t, relativePath) repo := localrepo.NewTestRepo(t, cfg, repoProto) - tc.expectedStrategy.isObjectPool = IsPoolRepository(repo) + tc.expectedStrategy.isObjectPool = stats.IsPoolRepository(repo) strategy, err := NewHeuristicalOptimizationStrategy(ctx, repo) require.NoError(t, err) @@ -888,7 +888,7 @@ func TestNewEagerOptimizationStrategy(t *testing.T) { repoProto := tc.setup(t, relativePath) repo := localrepo.NewTestRepo(t, cfg, repoProto) - tc.expectedStrategy.isObjectPool = IsPoolRepository(repo) + tc.expectedStrategy.isObjectPool = stats.IsPoolRepository(repo) strategy, err := NewEagerOptimizationStrategy(ctx, repo) require.NoError(t, err) diff --git a/internal/git/housekeeping/optimize_repository_test.go b/internal/git/housekeeping/optimize_repository_test.go index 78e0a790b..7906b4887 100644 --- a/internal/git/housekeeping/optimize_repository_test.go +++ b/internal/git/housekeeping/optimize_repository_test.go @@ -398,7 +398,7 @@ gitaly_housekeeping_tasks_total{housekeeping_task="total", status="success"} 1 require.Equal(t, tc.expectedErr, err) expectedMetrics := tc.expectedMetrics - if IsPoolRepository(repoProto) && tc.expectedMetricsForPool != "" { + if stats.IsPoolRepository(repoProto) && tc.expectedMetricsForPool != "" { expectedMetrics = tc.expectedMetricsForPool } diff --git a/internal/git/objectpool/pool.go b/internal/git/objectpool/pool.go index bdde64629..2243a76f7 100644 --- a/internal/git/objectpool/pool.go +++ b/internal/git/objectpool/pool.go @@ -15,6 +15,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile" "gitlab.com/gitlab-org/gitaly/v15/internal/git/housekeeping" "gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo" + "gitlab.com/gitlab-org/gitaly/v15/internal/git/stats" "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/storage" "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/transaction" "gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb" @@ -57,7 +58,7 @@ func FromProto( return nil, err } - if !housekeeping.IsPoolRepository(proto.GetRepository()) { + if !stats.IsPoolRepository(proto.GetRepository()) { // When creating repositories in the ObjectPool service we will first create the // repository in a temporary directory. So we need to check whether the path we see // here is in such a temporary directory and let it pass. diff --git a/internal/git/housekeeping/object_pool.go b/internal/git/stats/object_pool.go index 732045e09..3235f6d06 100644 --- a/internal/git/housekeeping/object_pool.go +++ b/internal/git/stats/object_pool.go @@ -1,4 +1,4 @@ -package housekeeping +package stats import ( "regexp" diff --git a/internal/git/housekeeping/object_pool_test.go b/internal/git/stats/object_pool_test.go index f534ab7ee..1737c5a80 100644 --- a/internal/git/housekeeping/object_pool_test.go +++ b/internal/git/stats/object_pool_test.go @@ -1,4 +1,4 @@ -package housekeeping +package stats import ( "testing" diff --git a/internal/gitaly/service/objectpool/create.go b/internal/gitaly/service/objectpool/create.go index 94a614a62..7f432c901 100644 --- a/internal/gitaly/service/objectpool/create.go +++ b/internal/gitaly/service/objectpool/create.go @@ -3,8 +3,8 @@ package objectpool import ( "context" - "gitlab.com/gitlab-org/gitaly/v15/internal/git/housekeeping" "gitlab.com/gitlab-org/gitaly/v15/internal/git/objectpool" + "gitlab.com/gitlab-org/gitaly/v15/internal/git/stats" "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/repoutil" "gitlab.com/gitlab-org/gitaly/v15/internal/structerr" "gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb" @@ -25,7 +25,7 @@ func (s *server) CreateObjectPool(ctx context.Context, in *gitalypb.CreateObject return nil, errMissingPool } - if !housekeeping.IsPoolRepository(poolRepo) { + if !stats.IsPoolRepository(poolRepo) { return nil, errInvalidPoolDir } diff --git a/internal/praefect/delete_object_pool.go b/internal/praefect/delete_object_pool.go index bc45dfcf5..e30f07d53 100644 --- a/internal/praefect/delete_object_pool.go +++ b/internal/praefect/delete_object_pool.go @@ -4,8 +4,8 @@ import ( "context" "fmt" - "gitlab.com/gitlab-org/gitaly/v15/internal/git/housekeeping" "gitlab.com/gitlab-org/gitaly/v15/internal/git/objectpool" + "gitlab.com/gitlab-org/gitaly/v15/internal/git/stats" objectpoolsvc "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service/objectpool" "gitlab.com/gitlab-org/gitaly/v15/internal/praefect/datastore" "gitlab.com/gitlab-org/gitaly/v15/internal/structerr" @@ -29,7 +29,7 @@ func DeleteObjectPoolHandler(rs datastore.RepositoryStore, conns Connections) gr return nil, err } - if !housekeeping.IsRailsPoolRepository(repo) { + if !stats.IsRailsPoolRepository(repo) { return nil, structerr.NewInvalidArgument("%w", objectpool.ErrInvalidPoolDir) } diff --git a/internal/praefect/router_per_repository.go b/internal/praefect/router_per_repository.go index d9cc071fa..c64da8f7a 100644 --- a/internal/praefect/router_per_repository.go +++ b/internal/praefect/router_per_repository.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - "gitlab.com/gitlab-org/gitaly/v15/internal/git/housekeeping" + "gitlab.com/gitlab-org/gitaly/v15/internal/git/stats" "gitlab.com/gitlab-org/gitaly/v15/internal/praefect/datastore" "gitlab.com/gitlab-org/gitaly/v15/internal/praefect/nodes" "gitlab.com/gitlab-org/gitaly/v15/internal/praefect/praefectutil" @@ -311,7 +311,7 @@ func (r *PerRepositoryRouter) RouteRepositoryCreation(ctx context.Context, virtu } replicaPath := praefectutil.DeriveReplicaPath(id) - if housekeeping.IsRailsPoolRepository(&gitalypb.Repository{ + if stats.IsRailsPoolRepository(&gitalypb.Repository{ StorageName: virtualStorage, RelativePath: relativePath, }) { |