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:
authorJohn Cai <jcai@gitlab.com>2022-03-24 23:11:47 +0300
committerJohn Cai <jcai@gitlab.com>2022-03-30 18:03:50 +0300
commit4db3e40e6cbaaa4af743393113328872622bc243 (patch)
tree07e1d80471b0474d607dbb873fe001546443d9c5
parentbb3bdf90f3c5b1476b18b7a8b6458934b0a031dc (diff)
repository: Use Size() to calculate repo size behind feature flagjc-accurate-calculation-of-repo-size
In the previous commit, we added a Size() method in localrepo that calls git rev-list --all --objects --disk-usage to calculate the size of the repository. Add a feature flag that, when toggled on, will cause RepositorySize to use this new way of calculating repository size. Changelog: added
-rw-r--r--internal/gitaly/service/repository/size.go22
-rw-r--r--internal/gitaly/service/repository/size_test.go31
-rw-r--r--internal/metadata/featureflag/ff_repo_size_revlist.go5
3 files changed, 46 insertions, 12 deletions
diff --git a/internal/gitaly/service/repository/size.go b/internal/gitaly/service/repository/size.go
index 261bb0417..94cf5a7c8 100644
--- a/internal/gitaly/service/repository/size.go
+++ b/internal/gitaly/service/repository/size.go
@@ -10,16 +10,30 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
"gitlab.com/gitlab-org/gitaly/v14/internal/command"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/metadata/featureflag"
"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
)
func (s *server) RepositorySize(ctx context.Context, in *gitalypb.RepositorySizeRequest) (*gitalypb.RepositorySizeResponse, error) {
- path, err := s.locator.GetPath(in.Repository)
- if err != nil {
- return nil, err
+ repo := s.localrepo(in.GetRepository())
+ var size int64
+ var err error
+
+ if featureflag.RevlistForRepoSize.IsEnabled(ctx) {
+ size, err = repo.Size(ctx)
+ if err != nil {
+ return nil, err
+ }
+ size = size / 1024
+ } else {
+ path, err := repo.Path()
+ if err != nil {
+ return nil, err
+ }
+ size = getPathSize(ctx, path)
}
- return &gitalypb.RepositorySizeResponse{Size: getPathSize(ctx, path)}, nil
+ return &gitalypb.RepositorySizeResponse{Size: size}, nil
}
func (s *server) GetObjectDirectorySize(ctx context.Context, in *gitalypb.GetObjectDirectorySizeRequest) (*gitalypb.GetObjectDirectorySizeResponse, error) {
diff --git a/internal/gitaly/service/repository/size_test.go b/internal/gitaly/service/repository/size_test.go
index 5aa51da73..b9c752723 100644
--- a/internal/gitaly/service/repository/size_test.go
+++ b/internal/gitaly/service/repository/size_test.go
@@ -1,12 +1,14 @@
package repository
import (
+ "context"
"testing"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v14/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v14/internal/git/quarantine"
"gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/metadata/featureflag"
"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
"google.golang.org/grpc/codes"
@@ -17,10 +19,13 @@ import (
// repository, even in optimally packed state, is greater than this.
const testRepoMinSizeKB = 10000
-func TestSuccessfulRepositorySizeRequest(t *testing.T) {
+func TestRepositorySize_SuccessfulRequest(t *testing.T) {
t.Parallel()
+ testhelper.NewFeatureSets(featureflag.RevlistForRepoSize).
+ Run(t, testSuccessfulRepositorySizeRequest)
+}
- ctx := testhelper.Context(t)
+func testSuccessfulRepositorySizeRequest(t *testing.T, ctx context.Context) {
_, repo, _, client := setupRepositoryService(ctx, t)
request := &gitalypb.RepositorySizeRequest{Repository: repo}
@@ -33,8 +38,13 @@ func TestSuccessfulRepositorySizeRequest(t *testing.T) {
)
}
-func TestFailedRepositorySizeRequest(t *testing.T) {
+func TestRepositorySixe_FailedRequest(t *testing.T) {
t.Parallel()
+ testhelper.NewFeatureSets(featureflag.RevlistForRepoSize).
+ Run(t, testFailedRepositorySizeRequest)
+}
+
+func testFailedRepositorySizeRequest(t *testing.T, ctx context.Context) {
_, client := setupRepositoryServiceWithoutRepo(t)
testCases := []struct {
@@ -52,17 +62,19 @@ func TestFailedRepositorySizeRequest(t *testing.T) {
request := &gitalypb.RepositorySizeRequest{
Repository: testCase.repo,
}
- ctx := testhelper.Context(t)
_, err := client.RepositorySize(ctx, request)
testhelper.RequireGrpcCode(t, err, codes.InvalidArgument)
})
}
}
-func TestSuccessfulGetObjectDirectorySizeRequest(t *testing.T) {
+func TestRepositorySize_SuccessfulGetObjectDirectorySizeRequest(t *testing.T) {
t.Parallel()
+ testhelper.NewFeatureSets(featureflag.RevlistForRepoSize).
+ Run(t, testSuccessfulGetObjectDirectorySizeRequest)
+}
- ctx := testhelper.Context(t)
+func testSuccessfulGetObjectDirectorySizeRequest(t *testing.T, ctx context.Context) {
_, repo, _, client := setupRepositoryService(ctx, t)
repo.GitObjectDirectory = "objects/"
@@ -76,12 +88,15 @@ func TestSuccessfulGetObjectDirectorySizeRequest(t *testing.T) {
)
}
-func TestGetObjectDirectorySize_quarantine(t *testing.T) {
+func TestRepositorySize_GetObjectDirectorySize_quarantine(t *testing.T) {
t.Parallel()
+ testhelper.NewFeatureSets(featureflag.RevlistForRepoSize).
+ Run(t, testGetObjectDirectorySizeQuarantine)
+}
+func testGetObjectDirectorySizeQuarantine(t *testing.T, ctx context.Context) {
cfg, client := setupRepositoryServiceWithoutRepo(t)
locator := config.NewLocator(cfg)
- ctx := testhelper.Context(t)
t.Run("quarantined repo", func(t *testing.T) {
repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
diff --git a/internal/metadata/featureflag/ff_repo_size_revlist.go b/internal/metadata/featureflag/ff_repo_size_revlist.go
new file mode 100644
index 000000000..8be87e482
--- /dev/null
+++ b/internal/metadata/featureflag/ff_repo_size_revlist.go
@@ -0,0 +1,5 @@
+package featureflag
+
+// RevlistForRepoSize enables the RepositorySize RPC to use git rev-list to
+// calculate the disk usage of the repository.
+var RevlistForRepoSize = NewFeatureFlag("revlist_for_repo_size", false)