From a0f8cde9056d5852ba98ccaaf0b11b8c8e8fa75e Mon Sep 17 00:00:00 2001 From: Manan Gupta <35839558+GuptaManan100@users.noreply.github.com> Date: Fri, 18 Oct 2024 11:19:05 +0530 Subject: [PATCH] Fix `GetUnresolvedTransactions` command for Vtctld (#16961) Signed-off-by: Manan Gupta --- go/vt/vtctl/grpcvtctldserver/server.go | 9 ++++++++ go/vt/vtctl/grpcvtctldserver/server_test.go | 23 +++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/go/vt/vtctl/grpcvtctldserver/server.go b/go/vt/vtctl/grpcvtctldserver/server.go index b06886e6770..aaf13fb864a 100644 --- a/go/vt/vtctl/grpcvtctldserver/server.go +++ b/go/vt/vtctl/grpcvtctldserver/server.go @@ -2461,6 +2461,15 @@ func (s *VtctldServer) GetUnresolvedTransactions(ctx context.Context, req *vtctl if err != nil { return err } + // The metadata manager is itself not part of the list of participants. + // We should it to the list before showing it to the users. + for _, trnx := range shardTrnxs { + trnx.Participants = append(trnx.Participants, &querypb.Target{ + Keyspace: req.Keyspace, + Shard: shard, + TabletType: topodatapb.TabletType_PRIMARY, + }) + } mu.Lock() defer mu.Unlock() transactions = append(transactions, shardTrnxs...) diff --git a/go/vt/vtctl/grpcvtctldserver/server_test.go b/go/vt/vtctl/grpcvtctldserver/server_test.go index a26e2480ba7..87e465c0f7d 100644 --- a/go/vt/vtctl/grpcvtctldserver/server_test.go +++ b/go/vt/vtctl/grpcvtctldserver/server_test.go @@ -5370,6 +5370,16 @@ func TestExecuteHook(t *testing.T) { func TestGetUnresolvedTransactions(t *testing.T) { ks := "testkeyspace" + shard1Target := &querypb.Target{ + Keyspace: ks, + Shard: "-80", + TabletType: topodatapb.TabletType_PRIMARY, + } + shard2Target := &querypb.Target{ + Keyspace: ks, + Shard: "80-", + TabletType: topodatapb.TabletType_PRIMARY, + } tests := []struct { name string @@ -5382,24 +5392,25 @@ func TestGetUnresolvedTransactions(t *testing.T) { name: "unresolved transaction on both shards", tmc: &testutil.TabletManagerClient{ GetUnresolvedTransactionsResults: map[string][]*querypb.TransactionMetadata{ - "-80": {{Dtid: "aa"}}, - "80-": {{Dtid: "bb"}}, + "-80": {{Dtid: "aa", Participants: []*querypb.Target{shard2Target}}}, + "80-": {{Dtid: "bb", Participants: []*querypb.Target{shard1Target}}}, }, }, keyspace: "testkeyspace", expected: []*querypb.TransactionMetadata{ - {Dtid: "aa"}, {Dtid: "bb"}, + {Dtid: "aa", Participants: []*querypb.Target{shard2Target, shard1Target}}, + {Dtid: "bb", Participants: []*querypb.Target{shard1Target, shard2Target}}, }, }, { - name: "unresolved transaction on one sharda", + name: "unresolved transaction on one shard", tmc: &testutil.TabletManagerClient{ GetUnresolvedTransactionsResults: map[string][]*querypb.TransactionMetadata{ - "80-": {{Dtid: "bb"}}, + "80-": {{Dtid: "bb", Participants: []*querypb.Target{shard1Target}}}, }, }, keyspace: "testkeyspace", expected: []*querypb.TransactionMetadata{ - {Dtid: "bb"}, + {Dtid: "bb", Participants: []*querypb.Target{shard1Target, shard2Target}}, }, }, {