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>2021-02-22 14:43:08 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-02-24 16:43:30 +0300
commit8864df1e0f44dd0179600513287496a72eab66f1 (patch)
tree6c71ff925cacd4e7cb2edc4b80e1faf666af72c8
parent69a4c3262fd1033adbfb6792427b6cf4d7806627 (diff)
blob: Port GetAllLFSPointers to Go
This commit ports the Ruby implementation of the GetAllLFSPointers RPC to Go. The new implementation is hidden behind a feature flag.
-rw-r--r--internal/gitaly/service/blob/lfs_pointers.go34
-rw-r--r--internal/gitaly/service/blob/lfs_pointers_test.go31
-rw-r--r--internal/metadata/featureflag/feature_flags.go3
3 files changed, 58 insertions, 10 deletions
diff --git a/internal/gitaly/service/blob/lfs_pointers.go b/internal/gitaly/service/blob/lfs_pointers.go
index 9f78f986e..0a7dc0093 100644
--- a/internal/gitaly/service/blob/lfs_pointers.go
+++ b/internal/gitaly/service/blob/lfs_pointers.go
@@ -15,6 +15,7 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver"
+ "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
@@ -125,6 +126,8 @@ func validateGetLfsPointersByRevisionRequest(in getLFSPointerByRevisionRequest)
return git.ValidateRevision(in.GetRevision())
}
+// GetAllLFSPointers returns all LFS pointers of the git repository which are reachable by any git
+// reference. LFS pointers are streamed back in batches of lfsPointerSliceSize.
func (s *server) GetAllLFSPointers(in *gitalypb.GetAllLFSPointersRequest, stream gitalypb.BlobService_GetAllLFSPointersServer) error {
ctx := stream.Context()
@@ -132,6 +135,37 @@ func (s *server) GetAllLFSPointers(in *gitalypb.GetAllLFSPointersRequest, stream
return status.Errorf(codes.InvalidArgument, "GetAllLFSPointers: %v", err)
}
+ if featureflag.IsDisabled(ctx, featureflag.GoGetAllLFSPointers) {
+ return s.rubyGetAllLFSPointers(in, stream)
+ }
+
+ repo := localrepo.New(s.gitCmdFactory, in.Repository, s.cfg)
+
+ lfsPointers, err := findLFSPointersByRevisions(ctx, repo, s.gitCmdFactory, []git.Option{
+ git.Flag{Name: "--all"},
+ })
+ if err != nil {
+ if errors.Is(err, errInvalidRevision) {
+ return status.Errorf(codes.InvalidArgument, err.Error())
+ }
+ return err
+ }
+
+ err = sliceLFSPointers(lfsPointers, func(slice []*gitalypb.LFSPointer) error {
+ return stream.Send(&gitalypb.GetAllLFSPointersResponse{
+ LfsPointers: slice,
+ })
+ })
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+func (s *server) rubyGetAllLFSPointers(in *gitalypb.GetAllLFSPointersRequest, stream gitalypb.BlobService_GetAllLFSPointersServer) error {
+ ctx := stream.Context()
+
client, err := s.ruby.BlobServiceClient(ctx)
if err != nil {
return err
diff --git a/internal/gitaly/service/blob/lfs_pointers_test.go b/internal/gitaly/service/blob/lfs_pointers_test.go
index 263e48768..63e1ee4ae 100644
--- a/internal/gitaly/service/blob/lfs_pointers_test.go
+++ b/internal/gitaly/service/blob/lfs_pointers_test.go
@@ -1,6 +1,7 @@
package blob
import (
+ "context"
"errors"
"fmt"
"io"
@@ -12,6 +13,7 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
+ "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc/codes"
@@ -364,6 +366,12 @@ func drainNewPointers(c gitalypb.BlobService_GetNewLFSPointersClient) error {
}
func TestSuccessfulGetAllLFSPointersRequest(t *testing.T) {
+ testhelper.NewFeatureSets([]featureflag.FeatureFlag{
+ featureflag.GoGetAllLFSPointers,
+ }).Run(t, testSuccessfulGetAllLFSPointersRequest)
+}
+
+func testSuccessfulGetAllLFSPointersRequest(t *testing.T, ctx context.Context) {
stop, serverSocketPath := runBlobServer(t, testhelper.DefaultLocator())
defer stop()
@@ -373,9 +381,6 @@ func TestSuccessfulGetAllLFSPointersRequest(t *testing.T) {
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- ctx, cancel := testhelper.Context()
- defer cancel()
-
request := &gitalypb.GetAllLFSPointersRequest{
Repository: testRepo,
}
@@ -411,15 +416,18 @@ func getAllPointers(t *testing.T, c gitalypb.BlobService_GetAllLFSPointersClient
}
func TestFailedGetAllLFSPointersRequestDueToValidations(t *testing.T) {
+ testhelper.NewFeatureSets([]featureflag.FeatureFlag{
+ featureflag.GoGetAllLFSPointers,
+ }).Run(t, testFailedGetAllLFSPointersRequestDueToValidations)
+}
+
+func testFailedGetAllLFSPointersRequestDueToValidations(t *testing.T, ctx context.Context) {
stop, serverSocketPath := runBlobServer(t, testhelper.DefaultLocator())
defer stop()
client, conn := newBlobClient(t, serverSocketPath)
defer conn.Close()
- ctx, cancel := testhelper.Context()
- defer cancel()
-
testCases := []struct {
desc string
repository *gitalypb.Repository
@@ -455,9 +463,15 @@ func drainAllPointers(c gitalypb.BlobService_GetAllLFSPointersClient) error {
}
}
+func TestGetAllLFSPointersVerifyScope(t *testing.T) {
+ testhelper.NewFeatureSets([]featureflag.FeatureFlag{
+ featureflag.GoGetAllLFSPointers,
+ }).Run(t, testGetAllLFSPointersVerifyScope)
+}
+
// TestGetAllLFSPointersVerifyScope verifies that this RPC returns all LFS
// pointers in a repository, not only ones reachable from the default branch
-func TestGetAllLFSPointersVerifyScope(t *testing.T) {
+func testGetAllLFSPointersVerifyScope(t *testing.T, ctx context.Context) {
stop, serverSocketPath := runBlobServer(t, testhelper.DefaultLocator())
defer stop()
@@ -467,9 +481,6 @@ func TestGetAllLFSPointersVerifyScope(t *testing.T) {
testRepo, repoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- ctx, cancel := testhelper.Context()
- defer cancel()
-
request := &gitalypb.GetAllLFSPointersRequest{
Repository: testRepo,
}
diff --git a/internal/metadata/featureflag/feature_flags.go b/internal/metadata/featureflag/feature_flags.go
index f8f37c38a..5515afe2d 100644
--- a/internal/metadata/featureflag/feature_flags.go
+++ b/internal/metadata/featureflag/feature_flags.go
@@ -28,6 +28,8 @@ var (
GoUserUpdateSubmodule = FeatureFlag{Name: "go_user_update_submodule", OnByDefault: false}
// GoUserRevert enables the Go implementation of UserRevert
GoUserRevert = FeatureFlag{Name: "go_user_revert", OnByDefault: false}
+ // GoGetAllLFSPointers enables the Go implementation of GetAllLFSPointers
+ GoGetAllLFSPointers = FeatureFlag{Name: "go_get_all_lfs_pointers", OnByDefault: false}
// TxApplyBfgObjectMapStream enables transactions for ApplyBfgObjectMapStream
TxApplyBfgObjectMapStream = FeatureFlag{Name: "tx_apply_bfg_object_map_stream", OnByDefault: true}
@@ -108,6 +110,7 @@ var All = []FeatureFlag{
GoResolveConflicts,
GoUserUpdateSubmodule,
GoUserRevert,
+ GoGetAllLFSPointers,
TxApplyBfgObjectMapStream,
TxApplyGitattributes,
TxResolveConflicts,