diff options
36 files changed, 148 insertions, 147 deletions
diff --git a/cmd/gitaly-hooks/hooks_test.go b/cmd/gitaly-hooks/hooks_test.go index a25837a6a..d4e14c000 100644 --- a/cmd/gitaly-hooks/hooks_test.go +++ b/cmd/gitaly-hooks/hooks_test.go @@ -28,10 +28,10 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/gitlab" gitalylog "gitlab.com/gitlab-org/gitaly/internal/log" "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testserver" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc" ) @@ -399,12 +399,12 @@ func TestHooksPostReceiveFailed(t *testing.T) { hooksPayload, err := git.NewHooksPayload( cfg, repo, - &metadata.Transaction{ + &txinfo.Transaction{ ID: 1, Node: "node", Primary: tc.primary, }, - &metadata.PraefectServer{ + &txinfo.PraefectServer{ SocketPath: "/path/to/socket", Token: "secret", }, diff --git a/internal/git/hooks_options.go b/internal/git/hooks_options.go index 84af8d627..0189e7470 100644 --- a/internal/git/hooks_options.go +++ b/internal/git/hooks_options.go @@ -11,7 +11,7 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/log" "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" ) @@ -84,7 +84,7 @@ func (cc *cmdCfg) configureHooks( return errors.New("hooks already configured") } - transaction, praefect, err := metadata.TransactionMetadataFromContext(ctx) + transaction, praefect, err := txinfo.TransactionMetadataFromContext(ctx) if err != nil { return err } diff --git a/internal/git/hooks_payload.go b/internal/git/hooks_payload.go index f98fffadd..0ba261fae 100644 --- a/internal/git/hooks_payload.go +++ b/internal/git/hooks_payload.go @@ -10,7 +10,7 @@ import ( "github.com/golang/protobuf/jsonpb" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" ) @@ -75,10 +75,10 @@ type HooksPayload struct { // Transaction is used to identify a reference transaction. This is an optional field -- if // it's not set, no transactional voting will happen. - Transaction *metadata.Transaction `json:"transaction"` + Transaction *txinfo.Transaction `json:"transaction"` // Praefect is used to identify the Praefect server which is hosting the transaction. This // field must be set if and only if `Transaction` is. - Praefect *metadata.PraefectServer `json:"praefect"` + Praefect *txinfo.PraefectServer `json:"praefect"` // ReceiveHooksPayload contains information required when executing // git-receive-pack. @@ -110,8 +110,8 @@ type jsonHooksPayload struct { func NewHooksPayload( cfg config.Cfg, repo *gitalypb.Repository, - tx *metadata.Transaction, - praefect *metadata.PraefectServer, + tx *txinfo.Transaction, + praefect *txinfo.PraefectServer, receiveHooksPayload *ReceiveHooksPayload, requestedHooks Hook, featureFlags featureflag.Raw, @@ -174,7 +174,7 @@ func HooksPayloadFromEnv(envs []string) (HooksPayload, error) { payload.Repo = &repo if payload.Transaction != nil && payload.Praefect == nil { - return HooksPayload{}, metadata.ErrPraefectServerNotFound + return HooksPayload{}, txinfo.ErrPraefectServerNotFound } // If no git path is set up as part of the serialized hooks payload, diff --git a/internal/git/hooks_payload_test.go b/internal/git/hooks_payload_test.go index 243f80df5..e8b7ed486 100644 --- a/internal/git/hooks_payload_test.go +++ b/internal/git/hooks_payload_test.go @@ -7,20 +7,20 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" ) func TestHooksPayload(t *testing.T) { cfg, repo, _ := testcfg.BuildWithRepo(t) - tx := metadata.Transaction{ + tx := txinfo.Transaction{ ID: 1234, Node: "primary", Primary: true, } - praefect := metadata.PraefectServer{ + praefect := txinfo.PraefectServer{ BackchannelID: 1, ListenAddr: "127.0.0.1:1234", TLSListenAddr: "127.0.0.1:4321", @@ -90,7 +90,7 @@ func TestHooksPayload(t *testing.T) { require.NoError(t, err) _, err = git.HooksPayloadFromEnv([]string{env}) - require.Equal(t, err, metadata.ErrPraefectServerNotFound) + require.Equal(t, err, txinfo.ErrPraefectServerNotFound) }) t.Run("receive hooks payload", func(t *testing.T) { diff --git a/internal/gitaly/hook/postreceive_test.go b/internal/gitaly/hook/postreceive_test.go index 6b16368b9..60392bd29 100644 --- a/internal/gitaly/hook/postreceive_test.go +++ b/internal/gitaly/hook/postreceive_test.go @@ -17,9 +17,9 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/gitaly/transaction" "gitlab.com/gitlab-org/gitaly/internal/gitlab" "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" ) func TestPrintAlert(t *testing.T) { @@ -83,10 +83,10 @@ func TestPostReceive_customHook(t *testing.T) { primaryPayload, err := git.NewHooksPayload( cfg, repo, - &metadata.Transaction{ + &txinfo.Transaction{ ID: 1234, Node: "primary", Primary: true, }, - &metadata.PraefectServer{ + &txinfo.PraefectServer{ SocketPath: "/path/to/socket", Token: "secret", }, @@ -99,10 +99,10 @@ func TestPostReceive_customHook(t *testing.T) { secondaryPayload, err := git.NewHooksPayload( cfg, repo, - &metadata.Transaction{ + &txinfo.Transaction{ ID: 1234, Node: "secondary", Primary: false, }, - &metadata.PraefectServer{ + &txinfo.PraefectServer{ SocketPath: "/path/to/socket", Token: "secret", }, diff --git a/internal/gitaly/hook/prereceive_test.go b/internal/gitaly/hook/prereceive_test.go index ce08ec720..2995a5e67 100644 --- a/internal/gitaly/hook/prereceive_test.go +++ b/internal/gitaly/hook/prereceive_test.go @@ -17,9 +17,9 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/gitlab" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" ) func TestPrereceive_customHooks(t *testing.T) { @@ -42,10 +42,10 @@ func TestPrereceive_customHooks(t *testing.T) { primaryPayload, err := git.NewHooksPayload( cfg, repo, - &metadata.Transaction{ + &txinfo.Transaction{ ID: 1234, Node: "primary", Primary: true, }, - &metadata.PraefectServer{ + &txinfo.PraefectServer{ SocketPath: "/path/to/socket", Token: "secret", }, @@ -58,10 +58,10 @@ func TestPrereceive_customHooks(t *testing.T) { secondaryPayload, err := git.NewHooksPayload( cfg, repo, - &metadata.Transaction{ + &txinfo.Transaction{ ID: 1234, Node: "secondary", Primary: false, }, - &metadata.PraefectServer{ + &txinfo.PraefectServer{ SocketPath: "/path/to/socket", Token: "secret", }, diff --git a/internal/gitaly/hook/transactions.go b/internal/gitaly/hook/transactions.go index ad0d53bfc..4a487d002 100644 --- a/internal/gitaly/hook/transactions.go +++ b/internal/gitaly/hook/transactions.go @@ -5,7 +5,7 @@ import ( "errors" "gitlab.com/gitlab-org/gitaly/internal/git" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/internal/transaction/voting" ) @@ -17,7 +17,7 @@ func isPrimary(payload git.HooksPayload) bool { } // transactionHandler is a callback invoked on a transaction if it exists. -type transactionHandler func(ctx context.Context, tx metadata.Transaction, praefect metadata.PraefectServer) error +type transactionHandler func(ctx context.Context, tx txinfo.Transaction, praefect txinfo.PraefectServer) error // runWithTransaction runs the given function if the payload identifies a transaction. No error // is returned if no transaction exists. If a transaction exists and the function is executed on it, @@ -37,13 +37,14 @@ func (m *GitLabHookManager) runWithTransaction(ctx context.Context, payload git. } func (m *GitLabHookManager) voteOnTransaction(ctx context.Context, vote voting.Vote, payload git.HooksPayload) error { - return m.runWithTransaction(ctx, payload, func(ctx context.Context, tx metadata.Transaction, praefect metadata.PraefectServer) error { + return m.runWithTransaction(ctx, payload, func(ctx context.Context, tx txinfo.Transaction, + praefect txinfo.PraefectServer) error { return m.txManager.Vote(ctx, tx, praefect, vote) }) } func (m *GitLabHookManager) stopTransaction(ctx context.Context, payload git.HooksPayload) error { - return m.runWithTransaction(ctx, payload, func(ctx context.Context, tx metadata.Transaction, praefect metadata.PraefectServer) error { + return m.runWithTransaction(ctx, payload, func(ctx context.Context, tx txinfo.Transaction, praefect txinfo.PraefectServer) error { return m.txManager.Stop(ctx, tx, praefect) }) } diff --git a/internal/gitaly/hook/transactions_test.go b/internal/gitaly/hook/transactions_test.go index 97fcbd78f..80083441f 100644 --- a/internal/gitaly/hook/transactions_test.go +++ b/internal/gitaly/hook/transactions_test.go @@ -16,20 +16,20 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/gitaly/transaction" "gitlab.com/gitlab-org/gitaly/internal/gitlab" "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/internal/transaction/voting" ) func TestHookManager_stopCalled(t *testing.T) { cfg, repo, repoPath := testcfg.BuildWithRepo(t) - expectedTx := metadata.Transaction{ + expectedTx := txinfo.Transaction{ ID: 1234, Node: "primary", Primary: true, } - expectedPraefect := metadata.PraefectServer{ + expectedPraefect := txinfo.PraefectServer{ SocketPath: "socket", Token: "foo", } @@ -104,7 +104,7 @@ func TestHookManager_stopCalled(t *testing.T) { } { t.Run(tc.desc, func(t *testing.T) { wasInvoked := false - mockTxMgr.StopFn = func(ctx context.Context, tx metadata.Transaction, praefect metadata.PraefectServer) error { + mockTxMgr.StopFn = func(ctx context.Context, tx txinfo.Transaction, praefect txinfo.PraefectServer) error { require.Equal(t, expectedTx, tx) require.Equal(t, expectedPraefect, praefect) wasInvoked = true @@ -122,7 +122,7 @@ func TestHookManager_contextCancellationCancelsVote(t *testing.T) { cfg, repo, _ := testcfg.BuildWithRepo(t) mockTxMgr := transaction.MockManager{ - VoteFn: func(ctx context.Context, tx metadata.Transaction, praefect metadata.PraefectServer, vote voting.Vote) error { + VoteFn: func(ctx context.Context, tx txinfo.Transaction, praefect txinfo.PraefectServer, vote voting.Vote) error { <-ctx.Done() return fmt.Errorf("mock error: %s", ctx.Err()) }, @@ -133,10 +133,10 @@ func TestHookManager_contextCancellationCancelsVote(t *testing.T) { hooksPayload, err := git.NewHooksPayload( cfg, repo, - &metadata.Transaction{ + &txinfo.Transaction{ ID: 1234, Node: "primary", Primary: true, }, - &metadata.PraefectServer{ + &txinfo.PraefectServer{ SocketPath: "does_not", Token: "matter", }, diff --git a/internal/gitaly/hook/update_test.go b/internal/gitaly/hook/update_test.go index 99ed41c5a..5ed7b8b59 100644 --- a/internal/gitaly/hook/update_test.go +++ b/internal/gitaly/hook/update_test.go @@ -14,9 +14,9 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/gitaly/transaction" "gitlab.com/gitlab-org/gitaly/internal/gitlab" "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" ) func TestUpdate_customHooks(t *testing.T) { @@ -39,10 +39,10 @@ func TestUpdate_customHooks(t *testing.T) { primaryPayload, err := git.NewHooksPayload( cfg, repo, - &metadata.Transaction{ + &txinfo.Transaction{ ID: 1234, Node: "primary", Primary: true, }, - &metadata.PraefectServer{ + &txinfo.PraefectServer{ SocketPath: "/path/to/socket", Token: "secret", }, @@ -55,10 +55,10 @@ func TestUpdate_customHooks(t *testing.T) { secondaryPayload, err := git.NewHooksPayload( cfg, repo, - &metadata.Transaction{ + &txinfo.Transaction{ ID: 1234, Node: "secondary", Primary: false, }, - &metadata.PraefectServer{ + &txinfo.PraefectServer{ SocketPath: "/path/to/socket", Token: "secret", }, diff --git a/internal/gitaly/rubyserver/proxy.go b/internal/gitaly/rubyserver/proxy.go index 69c334b9c..b10cabc37 100644 --- a/internal/gitaly/rubyserver/proxy.go +++ b/internal/gitaly/rubyserver/proxy.go @@ -6,8 +6,8 @@ import ( "os" "strings" - praefect_metadata "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" "gitlab.com/gitlab-org/gitaly/internal/storage" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/metadata" ) @@ -58,20 +58,20 @@ func setHeaders(ctx context.Context, locator storage.Locator, repo *gitalypb.Rep // Praefect server info into the context, `PraefectFromContext()` will // also resolve connection information from the context's peer info. // Thus the re-injected connection info will contain resolved addresses. - if praefectServer, err := praefect_metadata.PraefectFromContext(ctx); err == nil { + if praefectServer, err := txinfo.PraefectFromContext(ctx); err == nil { ctx, err = praefectServer.Inject(ctx) if err != nil { return nil, err } - } else if err != praefect_metadata.ErrPraefectServerNotFound { + } else if err != txinfo.ErrPraefectServerNotFound { return nil, err } // list of http/2 headers that will be forwarded as-is to gitaly-ruby proxyHeaderAllowlist := []string{ "gitaly-servers", - praefect_metadata.TransactionMetadataKey, - praefect_metadata.PraefectMetadataKey, + txinfo.TransactionMetadataKey, + txinfo.PraefectMetadataKey, } if inMD, ok := metadata.FromIncomingContext(ctx); ok { diff --git a/internal/gitaly/service/hook/post_receive_test.go b/internal/gitaly/service/hook/post_receive_test.go index 9d2ba9e96..342e86b86 100644 --- a/internal/gitaly/service/hook/post_receive_test.go +++ b/internal/gitaly/service/hook/post_receive_test.go @@ -14,10 +14,10 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/gitlab" "gitlab.com/gitlab-org/gitaly/internal/helper/text" "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testserver" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "gitlab.com/gitlab-org/gitaly/streamio" "google.golang.org/grpc/codes" @@ -99,12 +99,12 @@ func TestHooksMissingStdin(t *testing.T) { hooksPayload, err := git.NewHooksPayload( cfg, repo, - &metadata.Transaction{ + &txinfo.Transaction{ ID: 1234, Node: "node-1", Primary: tc.primary, }, - &metadata.PraefectServer{ + &txinfo.PraefectServer{ SocketPath: "/path/to/socket", Token: "secret", }, diff --git a/internal/gitaly/service/hook/pre_receive_test.go b/internal/gitaly/service/hook/pre_receive_test.go index 6cfed0aca..d534b6604 100644 --- a/internal/gitaly/service/hook/pre_receive_test.go +++ b/internal/gitaly/service/hook/pre_receive_test.go @@ -19,10 +19,10 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/gitlab" "gitlab.com/gitlab-org/gitaly/internal/helper/text" "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testserver" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "gitlab.com/gitlab-org/gitaly/streamio" "google.golang.org/grpc/codes" @@ -464,12 +464,12 @@ func TestPreReceiveHook_Primary(t *testing.T) { hooksPayload, err := git.NewHooksPayload( cfg, testRepo, - &metadata.Transaction{ + &txinfo.Transaction{ ID: 1234, Node: "node-1", Primary: tc.primary, }, - &metadata.PraefectServer{ + &txinfo.PraefectServer{ SocketPath: "/path/to/socket", Token: "secret", }, diff --git a/internal/gitaly/service/hook/reference_transaction_test.go b/internal/gitaly/service/hook/reference_transaction_test.go index 56ec746b3..4be1ee951 100644 --- a/internal/gitaly/service/hook/reference_transaction_test.go +++ b/internal/gitaly/service/hook/reference_transaction_test.go @@ -11,10 +11,10 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testserver" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -145,11 +145,11 @@ func TestReferenceTransactionHook(t *testing.T) { hooksPayload, err := git.NewHooksPayload( cfg, repo, - &metadata.Transaction{ + &txinfo.Transaction{ ID: 1234, Node: "node-1", }, - &metadata.PraefectServer{BackchannelID: backchannelID}, + &txinfo.PraefectServer{BackchannelID: backchannelID}, nil, git.ReferenceTransactionHook, featureflag.RawFromContext(ctx), diff --git a/internal/gitaly/service/operations/branches_test.go b/internal/gitaly/service/operations/branches_test.go index 488d7bb23..9c535eac2 100644 --- a/internal/gitaly/service/operations/branches_test.go +++ b/internal/gitaly/service/operations/branches_test.go @@ -16,10 +16,10 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/gitaly/service/hook" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testserver" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -136,12 +136,12 @@ func TestUserCreateBranchWithTransaction(t *testing.T) { testcases := []struct { desc string address string - server metadata.PraefectServer + server txinfo.PraefectServer }{ { desc: "explicit TCP address", address: addr, - server: metadata.PraefectServer{ + server: txinfo.PraefectServer{ ListenAddr: addr, Token: cfg.Auth.Token, }, @@ -149,7 +149,7 @@ func TestUserCreateBranchWithTransaction(t *testing.T) { { desc: "catch-all TCP address", address: addr, - server: metadata.PraefectServer{ + server: txinfo.PraefectServer{ ListenAddr: "tcp://0.0.0.0:" + port, Token: cfg.Auth.Token, }, @@ -157,7 +157,7 @@ func TestUserCreateBranchWithTransaction(t *testing.T) { { desc: "Unix socket", address: "unix://" + cfg.GitalyInternalSocketPath(), - server: metadata.PraefectServer{ + server: txinfo.PraefectServer{ SocketPath: "unix://" + cfg.GitalyInternalSocketPath(), Token: cfg.Auth.Token, }, @@ -184,7 +184,7 @@ func TestUserCreateBranchWithTransaction(t *testing.T) { ctx, err := tc.server.Inject(ctx) require.NoError(t, err) - ctx, err = metadata.InjectTransaction(ctx, 1, "node", true) + ctx, err = txinfo.InjectTransaction(ctx, 1, "node", true) require.NoError(t, err) ctx = helper.IncomingToOutgoing(ctx) @@ -500,7 +500,7 @@ func TestUserDeleteBranch_transaction(t *testing.T) { gitalypb.RegisterOperationServiceServer(srv, NewServer(deps.GetCfg(), nil, deps.GetHookManager(), deps.GetLocator(), deps.GetConnsPool(), deps.GetGitCmdFactory())) }) - praefect := metadata.PraefectServer{ + praefect := txinfo.PraefectServer{ SocketPath: fmt.Sprintf("unix://" + cfg.GitalyInternalSocketPath()), Token: cfg.Auth.Token, } @@ -510,7 +510,7 @@ func TestUserDeleteBranch_transaction(t *testing.T) { ctx, err := praefect.Inject(ctx) require.NoError(t, err) - ctx, err = metadata.InjectTransaction(ctx, 1, "node", true) + ctx, err = txinfo.InjectTransaction(ctx, 1, "node", true) require.NoError(t, err) ctx = helper.IncomingToOutgoing(ctx) diff --git a/internal/gitaly/service/operations/rebase_test.go b/internal/gitaly/service/operations/rebase_test.go index 1561b4603..51c410a38 100644 --- a/internal/gitaly/service/operations/rebase_test.go +++ b/internal/gitaly/service/operations/rebase_test.go @@ -20,9 +20,9 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/gitaly/transaction" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testserver" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/internal/transaction/voting" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -96,7 +96,7 @@ func testUserRebaseConfirmableTransaction(t *testing.T, cfg config.Cfg, rubySrv func testUserRebaseConfirmableTransactionFeatured(t *testing.T, ctx context.Context, cfg config.Cfg, rubySrv *rubyserver.Server) { var voteCount int txManager := &transaction.MockManager{ - VoteFn: func(context.Context, metadata.Transaction, metadata.PraefectServer, voting.Vote) error { + VoteFn: func(context.Context, txinfo.Transaction, txinfo.PraefectServer, voting.Vote) error { voteCount++ return nil }, @@ -149,9 +149,9 @@ func testUserRebaseConfirmableTransactionFeatured(t *testing.T, ctx context.Cont ctx = helper.OutgoingToIncoming(ctx) var err error - ctx, err = metadata.InjectTransaction(ctx, 1, "node", tc.primary) + ctx, err = txinfo.InjectTransaction(ctx, 1, "node", tc.primary) require.NoError(t, err) - ctx, err = (&metadata.PraefectServer{ + ctx, err = (&txinfo.PraefectServer{ SocketPath: "irrelevant", }).Inject(ctx) require.NoError(t, err) diff --git a/internal/gitaly/service/operations/tags_test.go b/internal/gitaly/service/operations/tags_test.go index a05b297e3..aebde8963 100644 --- a/internal/gitaly/service/operations/tags_test.go +++ b/internal/gitaly/service/operations/tags_test.go @@ -20,10 +20,10 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/helper/text" "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testserver" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -302,7 +302,7 @@ func TestUserCreateTagWithTransaction(t *testing.T) { ), ) - praefectServer := &metadata.PraefectServer{ + praefectServer := &txinfo.PraefectServer{ SocketPath: "unix://" + cfg.GitalyInternalSocketPath(), Token: cfg.Auth.Token, } @@ -352,7 +352,7 @@ func TestUserCreateTagWithTransaction(t *testing.T) { // We need to convert to an incoming context first in // order to preserve the feature flag. ctx = helper.OutgoingToIncoming(ctx) - ctx, err = metadata.InjectTransaction(ctx, 1, "node", testCase.primary) + ctx, err = txinfo.InjectTransaction(ctx, 1, "node", testCase.primary) require.NoError(t, err) ctx, err = praefectServer.Inject(ctx) require.NoError(t, err) diff --git a/internal/gitaly/service/operations/update_with_hooks.go b/internal/gitaly/service/operations/update_with_hooks.go index 75a17808d..086fa9c59 100644 --- a/internal/gitaly/service/operations/update_with_hooks.go +++ b/internal/gitaly/service/operations/update_with_hooks.go @@ -12,7 +12,7 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/gitaly/hook" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" ) @@ -52,7 +52,7 @@ func (s *Server) updateReferenceWithHooks( newrev, oldrev git.ObjectID, pushOptions ...string, ) error { - transaction, praefect, err := metadata.TransactionMetadataFromContext(ctx) + transaction, praefect, err := txinfo.TransactionMetadataFromContext(ctx) if err != nil { return err } diff --git a/internal/gitaly/service/ref/delete_refs_test.go b/internal/gitaly/service/ref/delete_refs_test.go index 74a75e388..8c243040d 100644 --- a/internal/gitaly/service/ref/delete_refs_test.go +++ b/internal/gitaly/service/ref/delete_refs_test.go @@ -12,10 +12,10 @@ import ( hookservice "gitlab.com/gitlab-org/gitaly/internal/gitaly/service/hook" "gitlab.com/gitlab-org/gitaly/internal/gitaly/transaction" "gitlab.com/gitlab-org/gitaly/internal/helper" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testserver" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/internal/transaction/voting" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc" @@ -85,7 +85,7 @@ func TestDeleteRefs_transaction(t *testing.T) { var votes int txManager := &transaction.MockManager{ - VoteFn: func(context.Context, metadata.Transaction, metadata.PraefectServer, voting.Vote) error { + VoteFn: func(context.Context, txinfo.Transaction, txinfo.PraefectServer, voting.Vote) error { votes++ return nil }, @@ -102,9 +102,9 @@ func TestDeleteRefs_transaction(t *testing.T) { ctx, cancel := testhelper.Context() t.Cleanup(cancel) - ctx, err := metadata.InjectTransaction(ctx, 1, "node", true) + ctx, err := txinfo.InjectTransaction(ctx, 1, "node", true) require.NoError(t, err) - ctx, err = (&metadata.PraefectServer{SocketPath: "i-dont-care"}).Inject(ctx) + ctx, err = (&txinfo.PraefectServer{SocketPath: "i-dont-care"}).Inject(ctx) require.NoError(t, err) ctx = helper.IncomingToOutgoing(ctx) diff --git a/internal/gitaly/service/repository/apply_gitattributes.go b/internal/gitaly/service/repository/apply_gitattributes.go index 6d7586973..92c46056e 100644 --- a/internal/gitaly/service/repository/apply_gitattributes.go +++ b/internal/gitaly/service/repository/apply_gitattributes.go @@ -11,7 +11,7 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/git/catfile" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/internal/transaction/voting" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -93,12 +93,12 @@ func (s *server) applyGitattributes(ctx context.Context, c catfile.Batch, repoPa } func (s *server) vote(ctx context.Context, oid git.ObjectID) error { - tx, err := metadata.TransactionFromContext(ctx) - if errors.Is(err, metadata.ErrTransactionNotFound) { + tx, err := txinfo.TransactionFromContext(ctx) + if errors.Is(err, txinfo.ErrTransactionNotFound) { return nil } - praefect, err := metadata.PraefectFromContext(ctx) + praefect, err := txinfo.PraefectFromContext(ctx) if err != nil { return fmt.Errorf("vote has invalid Praefect info: %w", err) } diff --git a/internal/gitaly/service/repository/apply_gitattributes_test.go b/internal/gitaly/service/repository/apply_gitattributes_test.go index abbaf5941..5f58f8572 100644 --- a/internal/gitaly/service/repository/apply_gitattributes_test.go +++ b/internal/gitaly/service/repository/apply_gitattributes_test.go @@ -16,10 +16,10 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/gitaly/service" "gitlab.com/gitlab-org/gitaly/internal/helper" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testserver" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -107,7 +107,7 @@ func TestApplyGitattributesWithTransaction(t *testing.T) { }), ) - praefect := metadata.PraefectServer{ + praefect := txinfo.PraefectServer{ SocketPath: "unix://" + cfg.GitalyInternalSocketPath(), Token: cfg.Auth.Token, } @@ -171,7 +171,7 @@ func TestApplyGitattributesWithTransaction(t *testing.T) { infoPath := filepath.Join(repoPath, "info") require.NoError(t, os.RemoveAll(infoPath)) - ctx, err := metadata.InjectTransaction(ctx, 1, "primary", true) + ctx, err := txinfo.InjectTransaction(ctx, 1, "primary", true) require.NoError(t, err) ctx, err = praefect.Inject(ctx) require.NoError(t, err) diff --git a/internal/gitaly/service/repository/create.go b/internal/gitaly/service/repository/create.go index 05a88ba16..118c95526 100644 --- a/internal/gitaly/service/repository/create.go +++ b/internal/gitaly/service/repository/create.go @@ -9,7 +9,7 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/gitaly/transaction" "gitlab.com/gitlab-org/gitaly/internal/helper" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/internal/transaction/voting" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -52,7 +52,7 @@ func (s *server) CreateRepository(ctx context.Context, req *gitalypb.CreateRepos // RPC it may be that we already do have some preexisting refs (e.g. CreateRepository is // called for a repo which already exists and has refs). In that case, voting ensures that // all replicas have the same set of preexisting refs. - if err := transaction.RunOnContext(ctx, func(tx metadata.Transaction, server metadata.PraefectServer) error { + if err := transaction.RunOnContext(ctx, func(tx txinfo.Transaction, server txinfo.PraefectServer) error { hash := voting.NewVoteHash() cmd, err := s.gitCmdFactory.New(ctx, req.GetRepository(), git.SubCmd{ diff --git a/internal/gitaly/service/repository/create_test.go b/internal/gitaly/service/repository/create_test.go index 1afa2eb93..4ebe3aba6 100644 --- a/internal/gitaly/service/repository/create_test.go +++ b/internal/gitaly/service/repository/create_test.go @@ -18,10 +18,10 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/gitaly/config/auth" "gitlab.com/gitlab-org/gitaly/internal/gitaly/transaction" "gitlab.com/gitlab-org/gitaly/internal/helper" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testserver" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/internal/transaction/voting" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -121,7 +121,7 @@ func TestCreateRepositoryTransactional(t *testing.T) { var called int mockTxManager := transaction.MockManager{ - VoteFn: func(ctx context.Context, tx metadata.Transaction, server metadata.PraefectServer, v voting.Vote) error { + VoteFn: func(ctx context.Context, tx txinfo.Transaction, server txinfo.PraefectServer, v voting.Vote) error { actualVote = v called++ return nil @@ -133,9 +133,9 @@ func TestCreateRepositoryTransactional(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - ctx, err := (&metadata.PraefectServer{SocketPath: "something"}).Inject(ctx) + ctx, err := (&txinfo.PraefectServer{SocketPath: "something"}).Inject(ctx) require.NoError(t, err) - ctx, err = metadata.InjectTransaction(ctx, 1, "node", true) + ctx, err = txinfo.InjectTransaction(ctx, 1, "node", true) require.NoError(t, err) ctx = helper.IncomingToOutgoing(ctx) diff --git a/internal/gitaly/service/repository/fetch_remote.go b/internal/gitaly/service/repository/fetch_remote.go index 1e11b70da..1aa6f5a9d 100644 --- a/internal/gitaly/service/repository/fetch_remote.go +++ b/internal/gitaly/service/repository/fetch_remote.go @@ -14,7 +14,7 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/git/localrepo" "gitlab.com/gitlab-org/gitaly/internal/gitaly/transaction" "gitlab.com/gitlab-org/gitaly/internal/helper" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/internal/transaction/voting" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -111,7 +111,7 @@ func (s *server) FetchRemote(ctx context.Context, req *gitalypb.FetchRemoteReque // is of course racy and may conflict with other mutators, causing the vote to fail. But it // is arguably preferable to accept races in favour always replicating. If loosing the race, // we'd fail this RPC and schedule a replication job afterwards. - if err := transaction.RunOnContext(ctx, func(tx metadata.Transaction, praefect metadata.PraefectServer) error { + if err := transaction.RunOnContext(ctx, func(tx txinfo.Transaction, praefect txinfo.PraefectServer) error { hash := voting.NewVoteHash() if err := repo.ExecAndWait(ctx, git.SubCmd{ diff --git a/internal/gitaly/service/repository/fetch_remote_test.go b/internal/gitaly/service/repository/fetch_remote_test.go index 676a1333c..60d0eda4b 100644 --- a/internal/gitaly/service/repository/fetch_remote_test.go +++ b/internal/gitaly/service/repository/fetch_remote_test.go @@ -23,10 +23,10 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/gitaly/transaction" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/helper/text" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testserver" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/internal/transaction/voting" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc" @@ -209,7 +209,7 @@ type mockTxManager struct { votes int } -func (m *mockTxManager) Vote(context.Context, metadata.Transaction, metadata.PraefectServer, voting.Vote) error { +func (m *mockTxManager) Vote(context.Context, txinfo.Transaction, txinfo.PraefectServer, voting.Vote) error { m.votes++ return nil } @@ -230,9 +230,9 @@ func TestFetchRemote_transaction(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - ctx, err := metadata.InjectTransaction(ctx, 1, "node", true) + ctx, err := txinfo.InjectTransaction(ctx, 1, "node", true) require.NoError(t, err) - ctx, err = (&metadata.PraefectServer{SocketPath: "i-dont-care"}).Inject(ctx) + ctx, err = (&txinfo.PraefectServer{SocketPath: "i-dont-care"}).Inject(ctx) require.NoError(t, err) ctx = helper.IncomingToOutgoing(ctx) diff --git a/internal/gitaly/service/smarthttp/receive_pack_test.go b/internal/gitaly/service/smarthttp/receive_pack_test.go index 03740a4e6..47dd6762c 100644 --- a/internal/gitaly/service/smarthttp/receive_pack_test.go +++ b/internal/gitaly/service/smarthttp/receive_pack_test.go @@ -25,10 +25,10 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/helper/text" "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" pconfig "gitlab.com/gitlab-org/gitaly/internal/praefect/config" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testserver" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "gitlab.com/gitlab-org/gitaly/streamio" "google.golang.org/grpc" @@ -557,7 +557,7 @@ func TestPostReceiveWithReferenceTransactionHook(t *testing.T) { // RefTransaction server for Gitaly itself. As this is the only Praefect // service required in this context, we can just pretend that // Gitaly is the Praefect server and inject it. - praefectServer, err := metadata.PraefectFromConfig(pconfig.Config{ + praefectServer, err := txinfo.PraefectFromConfig(pconfig.Config{ SocketPath: addr, }) require.NoError(t, err) @@ -565,7 +565,7 @@ func TestPostReceiveWithReferenceTransactionHook(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - ctx, err = metadata.InjectTransaction(ctx, 1234, "primary", true) + ctx, err = txinfo.InjectTransaction(ctx, 1234, "primary", true) require.NoError(t, err) ctx, err = praefectServer.Inject(ctx) require.NoError(t, err) diff --git a/internal/gitaly/service/ssh/receive_pack_test.go b/internal/gitaly/service/ssh/receive_pack_test.go index 745cb55cd..7a8b7c949 100644 --- a/internal/gitaly/service/ssh/receive_pack_test.go +++ b/internal/gitaly/service/ssh/receive_pack_test.go @@ -24,10 +24,10 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/gitaly/transaction" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/helper/text" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testserver" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/internal/transaction/voting" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "gitlab.com/gitlab-org/gitaly/streamio" @@ -261,8 +261,8 @@ func TestReceivePackTransactional(t *testing.T) { var votes int serverSocketPath := runSSHServer(t, cfg, testserver.WithTransactionManager( &transaction.MockManager{ - VoteFn: func(context.Context, metadata.Transaction, - metadata.PraefectServer, voting.Vote, + VoteFn: func(context.Context, txinfo.Transaction, + txinfo.PraefectServer, voting.Vote, ) error { votes++ return nil @@ -275,9 +275,9 @@ func TestReceivePackTransactional(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - ctx, err := (&metadata.PraefectServer{SocketPath: "whatever"}).Inject(ctx) + ctx, err := (&txinfo.PraefectServer{SocketPath: "whatever"}).Inject(ctx) require.NoError(t, err) - ctx, err = metadata.InjectTransaction(ctx, 1, "node", true) + ctx, err = txinfo.InjectTransaction(ctx, 1, "node", true) require.NoError(t, err) ctx = helper.IncomingToOutgoing(ctx) diff --git a/internal/gitaly/transaction/manager.go b/internal/gitaly/transaction/manager.go index 7c562ae91..4d008c037 100644 --- a/internal/gitaly/transaction/manager.go +++ b/internal/gitaly/transaction/manager.go @@ -12,7 +12,7 @@ import ( "gitlab.com/gitlab-org/gitaly/client" "gitlab.com/gitlab-org/gitaly/internal/backchannel" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/internal/transaction/voting" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" ) @@ -47,11 +47,11 @@ var ( type Manager interface { // Vote casts a vote on the given transaction which is hosted by the // given Praefect server. - Vote(context.Context, metadata.Transaction, metadata.PraefectServer, voting.Vote) error + Vote(context.Context, txinfo.Transaction, txinfo.PraefectServer, voting.Vote) error // Stop gracefully stops the given transaction which is hosted by the // given Praefect server. - Stop(context.Context, metadata.Transaction, metadata.PraefectServer) error + Stop(context.Context, txinfo.Transaction, txinfo.PraefectServer) error } // PoolManager is an implementation of the Manager interface using a pool to @@ -87,7 +87,7 @@ func (m *PoolManager) Collect(metrics chan<- prometheus.Metric) { m.votingDelayMetric.Collect(metrics) } -func (m *PoolManager) getTransactionClient(ctx context.Context, server metadata.PraefectServer) (gitalypb.RefTransactionClient, error) { +func (m *PoolManager) getTransactionClient(ctx context.Context, server txinfo.PraefectServer) (gitalypb.RefTransactionClient, error) { // Gitaly is upgraded prior to Praefect. Older Praefects may still be using non-multiplexed connections // and send dialing information for voting. To prevent failing RPCs during the upgrade, Gitaly still // needs to support the old voting approach. If multiplexed connection is in use, the backchannel ID would @@ -116,7 +116,7 @@ func (m *PoolManager) getTransactionClient(ctx context.Context, server metadata. } // Vote connects to the given server and casts vote as a vote for the transaction identified by tx. -func (m *PoolManager) Vote(ctx context.Context, tx metadata.Transaction, server metadata.PraefectServer, vote voting.Vote) error { +func (m *PoolManager) Vote(ctx context.Context, tx txinfo.Transaction, server txinfo.PraefectServer, vote voting.Vote) error { client, err := m.getTransactionClient(ctx, server) if err != nil { return err @@ -164,7 +164,7 @@ func (m *PoolManager) Vote(ctx context.Context, tx metadata.Transaction, server } // Stop connects to the given server and stops the transaction identified by tx. -func (m *PoolManager) Stop(ctx context.Context, tx metadata.Transaction, server metadata.PraefectServer) error { +func (m *PoolManager) Stop(ctx context.Context, tx txinfo.Transaction, server txinfo.PraefectServer) error { client, err := m.getTransactionClient(ctx, server) if err != nil { return err @@ -189,8 +189,8 @@ func (m *PoolManager) log(ctx context.Context) logrus.FieldLogger { } // RunOnContext runs the given function if the context identifies a transaction. -func RunOnContext(ctx context.Context, fn func(metadata.Transaction, metadata.PraefectServer) error) error { - transaction, praefect, err := metadata.TransactionMetadataFromContext(ctx) +func RunOnContext(ctx context.Context, fn func(txinfo.Transaction, txinfo.PraefectServer) error) error { + transaction, praefect, err := txinfo.TransactionMetadataFromContext(ctx) if err != nil { return err } @@ -202,7 +202,7 @@ func RunOnContext(ctx context.Context, fn func(metadata.Transaction, metadata.Pr // VoteOnContext casts the vote on a transaction identified by the context, if there is any. func VoteOnContext(ctx context.Context, m Manager, vote voting.Vote) error { - return RunOnContext(ctx, func(transaction metadata.Transaction, praefect metadata.PraefectServer) error { + return RunOnContext(ctx, func(transaction txinfo.Transaction, praefect txinfo.PraefectServer) error { return m.Vote(ctx, transaction, praefect, vote) }) } diff --git a/internal/gitaly/transaction/manager_test.go b/internal/gitaly/transaction/manager_test.go index 3cca92a89..0ed6773d0 100644 --- a/internal/gitaly/transaction/manager_test.go +++ b/internal/gitaly/transaction/manager_test.go @@ -11,10 +11,10 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/gitaly/service" "gitlab.com/gitlab-org/gitaly/internal/gitaly/transaction" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testserver" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/internal/transaction/voting" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc" @@ -53,20 +53,20 @@ func TestPoolManager_Vote(t *testing.T) { backchannelConn, err := client.Dial(ctx, praefect.ListenAddr, nil, nil) require.NoError(t, err) defer backchannelConn.Close() - praefect = metadata.PraefectServer{BackchannelID: registry.RegisterBackchannel(backchannelConn)} + praefect = txinfo.PraefectServer{BackchannelID: registry.RegisterBackchannel(backchannelConn)} manager := transaction.NewManager(cfg, registry) for _, tc := range []struct { desc string - transaction metadata.Transaction + transaction txinfo.Transaction vote voting.Vote voteFn func(*testing.T, *gitalypb.VoteTransactionRequest) (*gitalypb.VoteTransactionResponse, error) expectedErr error }{ { desc: "successful vote", - transaction: metadata.Transaction{ + transaction: txinfo.Transaction{ ID: 1, Node: "node", }, @@ -130,19 +130,19 @@ func TestPoolManager_Stop(t *testing.T) { backchannelConn, err := client.Dial(ctx, praefect.ListenAddr, nil, nil) require.NoError(t, err) defer backchannelConn.Close() - praefect = metadata.PraefectServer{BackchannelID: registry.RegisterBackchannel(backchannelConn)} + praefect = txinfo.PraefectServer{BackchannelID: registry.RegisterBackchannel(backchannelConn)} manager := transaction.NewManager(cfg, registry) for _, tc := range []struct { desc string - transaction metadata.Transaction + transaction txinfo.Transaction stopFn func(*testing.T, *gitalypb.StopTransactionRequest) (*gitalypb.StopTransactionResponse, error) expectedErr error }{ { desc: "successful stop", - transaction: metadata.Transaction{ + transaction: txinfo.Transaction{ ID: 1, Node: "node", }, @@ -170,14 +170,14 @@ func TestPoolManager_Stop(t *testing.T) { } } -func runTransactionServer(t *testing.T, cfg config.Cfg) (*testTransactionServer, metadata.PraefectServer) { +func runTransactionServer(t *testing.T, cfg config.Cfg) (*testTransactionServer, txinfo.PraefectServer) { transactionServer := &testTransactionServer{} cfg.ListenAddr = ":0" // pushes gRPC to listen on the TCP address addr := testserver.RunGitalyServer(t, cfg, nil, func(srv *grpc.Server, deps *service.Dependencies) { gitalypb.RegisterRefTransactionServer(srv, transactionServer) }, testserver.WithDisablePraefect()) - praefect := metadata.PraefectServer{ + praefect := txinfo.PraefectServer{ ListenAddr: addr, Token: cfg.Auth.Token, } diff --git a/internal/gitaly/transaction/mock.go b/internal/gitaly/transaction/mock.go index 992849dd9..a0c3ab894 100644 --- a/internal/gitaly/transaction/mock.go +++ b/internal/gitaly/transaction/mock.go @@ -4,18 +4,18 @@ import ( "context" "errors" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/internal/transaction/voting" ) // MockManager is a mock Manager for use in tests. type MockManager struct { - VoteFn func(context.Context, metadata.Transaction, metadata.PraefectServer, voting.Vote) error - StopFn func(context.Context, metadata.Transaction, metadata.PraefectServer) error + VoteFn func(context.Context, txinfo.Transaction, txinfo.PraefectServer, voting.Vote) error + StopFn func(context.Context, txinfo.Transaction, txinfo.PraefectServer) error } // Vote calls the MockManager's Vote function, if set. Otherwise, it returns an error. -func (m *MockManager) Vote(ctx context.Context, tx metadata.Transaction, praefect metadata.PraefectServer, vote voting.Vote) error { +func (m *MockManager) Vote(ctx context.Context, tx txinfo.Transaction, praefect txinfo.PraefectServer, vote voting.Vote) error { if m.VoteFn == nil { return errors.New("mock does not implement Vote function") } @@ -23,7 +23,7 @@ func (m *MockManager) Vote(ctx context.Context, tx metadata.Transaction, praefec } // Stop calls the MockManager's Stop function, if set. Otherwise, it returns an error. -func (m *MockManager) Stop(ctx context.Context, tx metadata.Transaction, praefect metadata.PraefectServer) error { +func (m *MockManager) Stop(ctx context.Context, tx txinfo.Transaction, praefect txinfo.PraefectServer) error { if m.StopFn == nil { return errors.New("mock does not implement Stop function") } diff --git a/internal/praefect/coordinator.go b/internal/praefect/coordinator.go index 043bfa7eb..45d0e29e2 100644 --- a/internal/praefect/coordinator.go +++ b/internal/praefect/coordinator.go @@ -18,11 +18,11 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/praefect/config" "gitlab.com/gitlab-org/gitaly/internal/praefect/datastore" "gitlab.com/gitlab-org/gitaly/internal/praefect/grpc-proxy/proxy" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" "gitlab.com/gitlab-org/gitaly/internal/praefect/metrics" "gitlab.com/gitlab-org/gitaly/internal/praefect/nodes" "gitlab.com/gitlab-org/gitaly/internal/praefect/protoregistry" "gitlab.com/gitlab-org/gitaly/internal/praefect/transactions" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "gitlab.com/gitlab-org/labkit/correlation" "golang.org/x/sync/errgroup" @@ -289,7 +289,7 @@ func (c *Coordinator) directRepositoryScopedMessage(ctx context.Context, call gr "relative_path": call.targetRepo.RelativePath, }) - praefectServer, err := metadata.PraefectFromConfig(c.conf) + praefectServer, err := txinfo.PraefectFromConfig(c.conf) if err != nil { return nil, fmt.Errorf("repo scoped: could not create Praefect configuration: %w", err) } @@ -458,7 +458,7 @@ func (c *Coordinator) mutatorStreamParameters(ctx context.Context, call grpcCall errByNode: make(map[string]error), } - injectedCtx, err := metadata.InjectTransaction(ctx, transaction.ID(), route.Primary.Storage, true) + injectedCtx, err := txinfo.InjectTransaction(ctx, transaction.ID(), route.Primary.Storage, true) if err != nil { return nil, err } @@ -476,7 +476,7 @@ func (c *Coordinator) mutatorStreamParameters(ctx context.Context, call grpcCall return nil, err } - injectedCtx, err := metadata.InjectTransaction(ctx, transaction.ID(), secondary.Storage, false) + injectedCtx, err := txinfo.InjectTransaction(ctx, transaction.ID(), secondary.Storage, false) if err != nil { return nil, err } diff --git a/internal/praefect/coordinator_pg_test.go b/internal/praefect/coordinator_pg_test.go index 371802966..eb769eaa3 100644 --- a/internal/praefect/coordinator_pg_test.go +++ b/internal/praefect/coordinator_pg_test.go @@ -16,12 +16,12 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/praefect/config" "gitlab.com/gitlab-org/gitaly/internal/praefect/datastore" "gitlab.com/gitlab-org/gitaly/internal/praefect/datastore/glsql" - praefect_metadata "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" "gitlab.com/gitlab-org/gitaly/internal/praefect/nodes" "gitlab.com/gitlab-org/gitaly/internal/praefect/protoregistry" "gitlab.com/gitlab-org/gitaly/internal/praefect/transactions" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/internal/testhelper/promtest" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/internal/transaction/voting" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/peer" @@ -197,7 +197,7 @@ func TestStreamDirectorMutator_Transaction(t *testing.T) { require.NoError(t, err) txCtx := peer.NewContext(streamParams.Primary().Ctx, &peer.Peer{}) - transaction, err := praefect_metadata.TransactionFromContext(txCtx) + transaction, err := txinfo.TransactionFromContext(txCtx) require.NoError(t, err) var voterWaitGroup sync.WaitGroup diff --git a/internal/praefect/coordinator_test.go b/internal/praefect/coordinator_test.go index 567735df4..69d93e8ce 100644 --- a/internal/praefect/coordinator_test.go +++ b/internal/praefect/coordinator_test.go @@ -24,13 +24,13 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/praefect/config" "gitlab.com/gitlab-org/gitaly/internal/praefect/datastore" "gitlab.com/gitlab-org/gitaly/internal/praefect/grpc-proxy/proxy" - praefect_metadata "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" "gitlab.com/gitlab-org/gitaly/internal/praefect/mock" "gitlab.com/gitlab-org/gitaly/internal/praefect/nodes" "gitlab.com/gitlab-org/gitaly/internal/praefect/protoregistry" "gitlab.com/gitlab-org/gitaly/internal/praefect/transactions" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/internal/testhelper/promtest" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/internal/transaction/voting" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "gitlab.com/gitlab-org/labkit/correlation" @@ -193,7 +193,7 @@ func TestStreamDirectorMutator(t *testing.T) { md, ok := metadata.FromOutgoingContext(streamParams.Primary().Ctx) require.True(t, ok) - require.Contains(t, md, praefect_metadata.PraefectMetadataKey) + require.Contains(t, md, txinfo.PraefectMetadataKey) mi, err := coordinator.registry.LookupMethod(fullMethod) require.NoError(t, err) @@ -299,7 +299,7 @@ func TestStreamDirectorMutator_StopTransaction(t *testing.T) { require.NoError(t, err) txCtx := peer.NewContext(streamParams.Primary().Ctx, &peer.Peer{}) - transaction, err := praefect_metadata.TransactionFromContext(txCtx) + transaction, err := txinfo.TransactionFromContext(txCtx) require.NoError(t, err) var wg sync.WaitGroup @@ -436,7 +436,7 @@ func TestStreamDirectorAccessor(t *testing.T) { md, ok := metadata.FromOutgoingContext(streamParams.Primary().Ctx) require.True(t, ok) - require.Contains(t, md, praefect_metadata.PraefectMetadataKey) + require.Contains(t, md, txinfo.PraefectMetadataKey) mi, err := coordinator.registry.LookupMethod(fullMethod) require.NoError(t, err) @@ -541,7 +541,7 @@ func TestCoordinatorStreamDirector_distributesReads(t *testing.T) { md, ok := metadata.FromOutgoingContext(streamParams.Primary().Ctx) require.True(t, ok) - require.Contains(t, md, praefect_metadata.PraefectMetadataKey) + require.Contains(t, md, txinfo.PraefectMetadataKey) mi, err := coordinator.registry.LookupMethod(fullMethod) require.NoError(t, err) @@ -590,7 +590,7 @@ func TestCoordinatorStreamDirector_distributesReads(t *testing.T) { md, ok := metadata.FromOutgoingContext(streamParams.Primary().Ctx) require.True(t, ok) - require.Contains(t, md, praefect_metadata.PraefectMetadataKey) + require.Contains(t, md, txinfo.PraefectMetadataKey) mi, err := coordinator.registry.LookupMethod(fullMethod) require.NoError(t, err) @@ -639,7 +639,7 @@ func TestCoordinatorStreamDirector_distributesReads(t *testing.T) { md, ok := metadata.FromOutgoingContext(streamParams.Primary().Ctx) require.True(t, ok) - require.Contains(t, md, praefect_metadata.PraefectMetadataKey) + require.Contains(t, md, txinfo.PraefectMetadataKey) mi, err := coordinator.registry.LookupMethod(fullMethod) require.NoError(t, err) @@ -683,7 +683,7 @@ func TestCoordinatorStreamDirector_distributesReads(t *testing.T) { md, ok := metadata.FromOutgoingContext(streamParams.Primary().Ctx) require.True(t, ok) - require.Contains(t, md, praefect_metadata.PraefectMetadataKey) + require.Contains(t, md, txinfo.PraefectMetadataKey) mi, err := coordinator.registry.LookupMethod(fullMethod) require.NoError(t, err) @@ -737,7 +737,7 @@ func TestCoordinatorStreamDirector_distributesReads(t *testing.T) { md, ok := metadata.FromOutgoingContext(streamParams.Primary().Ctx) require.True(t, ok) - require.Contains(t, md, praefect_metadata.PraefectMetadataKey) + require.Contains(t, md, txinfo.PraefectMetadataKey) mi, err := coordinator.registry.LookupMethod(fullMethod) require.NoError(t, err) @@ -921,7 +921,7 @@ func TestStreamDirector_repo_creation(t *testing.T) { md, ok := metadata.FromOutgoingContext(streamParams.Primary().Ctx) require.True(t, ok) - require.Contains(t, md, praefect_metadata.PraefectMetadataKey) + require.Contains(t, md, txinfo.PraefectMetadataKey) mi, err := coordinator.registry.LookupMethod(fullMethod) require.NoError(t, err) diff --git a/internal/praefect/server_test.go b/internal/praefect/server_test.go index c6a0975e5..99c309849 100644 --- a/internal/praefect/server_test.go +++ b/internal/praefect/server_test.go @@ -29,7 +29,6 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/praefect/config" "gitlab.com/gitlab-org/gitaly/internal/praefect/datastore" "gitlab.com/gitlab-org/gitaly/internal/praefect/grpc-proxy/proxy" - "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata" "gitlab.com/gitlab-org/gitaly/internal/praefect/mock" "gitlab.com/gitlab-org/gitaly/internal/praefect/nodes" "gitlab.com/gitlab-org/gitaly/internal/praefect/nodes/tracker" @@ -40,6 +39,7 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/testhelper/promtest" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/internal/testhelper/testserver" + "gitlab.com/gitlab-org/gitaly/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/internal/transaction/voting" "gitlab.com/gitlab-org/gitaly/internal/version" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -679,7 +679,7 @@ func (m *mockSmartHTTP) PostReceivePack(stream gitalypb.SmartHTTPService_PostRec ctx := stream.Context() - tx, err := metadata.TransactionFromContext(ctx) + tx, err := txinfo.TransactionFromContext(ctx) if err != nil { return helper.ErrInternal(err) } diff --git a/internal/praefect/metadata/server.go b/internal/transaction/txinfo/server.go index ff2fd0294..de9c2cc0a 100644 --- a/internal/praefect/metadata/server.go +++ b/internal/transaction/txinfo/server.go @@ -1,4 +1,4 @@ -package metadata +package txinfo import ( "context" diff --git a/internal/praefect/metadata/server_test.go b/internal/transaction/txinfo/server_test.go index cd4ad7067..d7b52ebe8 100644 --- a/internal/praefect/metadata/server_test.go +++ b/internal/transaction/txinfo/server_test.go @@ -1,4 +1,4 @@ -package metadata +package txinfo import ( "net" diff --git a/internal/praefect/metadata/transaction.go b/internal/transaction/txinfo/transaction.go index 1b54c0b6f..e8d6b7d88 100644 --- a/internal/praefect/metadata/transaction.go +++ b/internal/transaction/txinfo/transaction.go @@ -1,4 +1,4 @@ -package metadata +package txinfo import ( "context" |