Skip to content

Commit

Permalink
Fix GetUnresolvedTransactions command for Vtctld (#16961)
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <[email protected]>
  • Loading branch information
GuptaManan100 authored Oct 18, 2024
1 parent dc692fa commit a0f8cde
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
9 changes: 9 additions & 0 deletions go/vt/vtctl/grpcvtctldserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
23 changes: 17 additions & 6 deletions go/vt/vtctl/grpcvtctldserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}},
},
},
{
Expand Down

0 comments on commit a0f8cde

Please sign in to comment.