Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conclude transaction command to vtctld service #16693

Merged
merged 10 commits into from
Sep 16, 2024

Conversation

harshit-gangal
Copy link
Member

@harshit-gangal harshit-gangal commented Sep 2, 2024

Description

This PR adds support for vtctld server and vtctld client to Conclude open distributed transactions.
It also changes the command usage for Distributed Transactions

Command Usage
List:
DistributedTransaction list <keyspace>
Conclude:
DistributedTransaction conclude <dtid> [<keyspace/shard> ...]

Related Issue(s)

Checklist

  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Copy link
Contributor

vitess-bot bot commented Sep 2, 2024

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot vitess-bot bot added NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Sep 2, 2024
@harshit-gangal harshit-gangal added Type: Feature Component: vtctl Skip CI Skip CI actions from running Component: vtctldclient and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Sep 2, 2024
@github-actions github-actions bot added this to the v21.0.0 milestone Sep 2, 2024
Copy link

codecov bot commented Sep 2, 2024

Codecov Report

Attention: Patch coverage is 39.53488% with 78 lines in your changes missing coverage. Please review.

Project coverage is 68.93%. Comparing base (fd18ae4) to head (3ed6b66).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
go/cmd/vtctldclient/command/transactions.go 8.88% 41 Missing ⚠️
go/vt/vttablet/grpctmclient/client.go 0.00% 10 Missing ⚠️
go/vt/vttablet/grpctmserver/server.go 0.00% 7 Missing ⚠️
go/vt/vtctl/grpcvtctldserver/server.go 84.84% 5 Missing ⚠️
go/vt/vtctl/grpcvtctldclient/client_gen.go 0.00% 4 Missing ⚠️
go/vt/vttablet/tmrpctest/test_tm_rpc.go 0.00% 4 Missing ⚠️
go/vt/vtcombo/tablet_map.go 0.00% 2 Missing ⚠️
go/vt/vtctl/localvtctldclient/client_gen.go 0.00% 2 Missing ⚠️
go/vt/vttablet/faketmclient/fake_client.go 0.00% 2 Missing ⚠️
go/vt/vttablet/tabletmanager/rpc_query.go 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16693      +/-   ##
==========================================
- Coverage   68.93%   68.93%   -0.01%     
==========================================
  Files        1565     1566       +1     
  Lines      201741   201855     +114     
==========================================
+ Hits       139076   139152      +76     
- Misses      62665    62703      +38     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@harshit-gangal harshit-gangal force-pushed the vtctld-conclude-transactions branch 2 times, most recently from 048e39c to ca4c140 Compare September 3, 2024 10:06
@harshit-gangal harshit-gangal removed the Skip CI Skip CI actions from running label Sep 3, 2024
@harshit-gangal harshit-gangal force-pushed the vtctld-conclude-transactions branch from 84c5238 to 73f1a84 Compare September 4, 2024 16:49
@harshit-gangal harshit-gangal marked this pull request as ready for review September 4, 2024 16:53
@rohit-nayak-ps
Copy link
Contributor

Instead of the two current commands GetUnresolvedTransactions and ConcludeTransaction what do you think about a single umbrella command similar to those we have in vreplication like https://vitess.io/docs/20.0/reference/programs/vtctldclient/vtctldclient_workflow/.

Like
DistributedTransactions -k <keyspace> Show —unresolved // --unresolved could be default
DistributedTransactions -k <keyspace> Conclude [—shards <shard1,shard2>] —dtid <dtid>

The advantage of this approach is that we minimize the new commands required for additional functionality like (just brainstorming here)
DistributedTransactions -k <keyspace> Show —pending

Not sure if it is an overkill here and we will not have any more operations for DTs, but thought I would mention it.

@harshit-gangal
Copy link
Member Author

Instead of the two current commands GetUnresolvedTransactions and ConcludeTransaction what do you think about a single umbrella command similar to those we have in vreplication like https://vitess.io/docs/20.0/reference/programs/vtctldclient/vtctldclient_workflow/.

Like DistributedTransactions -k <keyspace> Show —unresolved // --unresolved could be default DistributedTransactions -k <keyspace> Conclude [—shards <shard1,shard2>] —dtid <dtid>

The advantage of this approach is that we minimize the new commands required for additional functionality like (just brainstorming here) DistributedTransactions -k <keyspace> Show —pending

Not sure if it is an overkill here and we will not have any more operations for DTs, but thought I would mention it.

This is a reasonable ask, at the moment we know of 2 commands but it can grow over time.
It will ensure that commands are tied together.

I will make the required changes.

@harshit-gangal harshit-gangal marked this pull request as draft September 10, 2024 15:32
@harshit-gangal harshit-gangal marked this pull request as ready for review September 11, 2024 14:48
@harshit-gangal harshit-gangal force-pushed the vtctld-conclude-transactions branch from b79484d to 5facda3 Compare September 11, 2024 14:51
// ConcludeTransaction makes a ConcludeTransaction gRPC call to a vtctld.
ConcludeTransaction = &cobra.Command{
Use: "conclude <dtid> [<keyspace/shard> ...]",
Short: "Concludes the unresolved transaction by rolling back the prepared transaction on all participating shards and removing the transaction metadata record.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Short: "Concludes the unresolved transaction by rolling back the prepared transaction on all participating shards and removing the transaction metadata record.",
Short: "Concludes the unresolved transaction by rolling back prepared transactions on all participating shards and removing the transaction metadata record.",

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

every shard will have at most 1 prepared transaction.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it is how we see this distributed transaction.
one transaction that spans multiple shards
or multiple independent transactions on the shards.

For user, it is one transaction.
Internally it is multiple transactions.

Copy link
Member

@deepthi deepthi Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you want to use singular, you can use each

Concludes the unresolved transaction by rolling back the prepared transaction on each participating shard and removing the transaction metadata record

OR

Concludes the unresolved transaction by rolling back prepared transactions on all participating shards and removing the transaction metadata record

are both grammatically correct. Using the singular with "all" is not. Ask ChatGPT and you will see.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will take the first one

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deepthi could you also approve the PR if everything else looks good?

@@ -28,6 +28,7 @@ Available Commands:
DeleteShards Deletes the specified shards from the topology.
DeleteSrvVSchema Deletes the SrvVSchema object in the given cell.
DeleteTablets Deletes tablet(s) from the topology.
DistributedTransaction Perform commands on distributed transaction
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be plural? I see from the discussion below that there is just one dt per shard: is that for all users and connections?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plural makes more sense to me too, especially for DistributedTransactions list since there can be multiple transactions that are listed.

Use: "conclude <dtid> [<keyspace/shard> ...]",
Short: "Concludes the unresolved transaction by rolling back the prepared transaction on all participating shards and removing the transaction metadata record.",
Aliases: []string{"Conclude"},
Args: cobra.MinimumNArgs(1),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the examples it is not entirely clear to me what the arguments to conclude will look like. But we have found it more useful to specify the parameters as flags rather than depend on args because it is easy to forget the order or delimiters etc. We had that problem a lot with the earlier vreplication commands. It is a bit more typing

For example it could be
DistributedTransactions Conclude --keyspace ks1 --shards -40,a0- --dtid 82345 OR with shorthand codes

DistributedTransactions Conclude -k ks1 -s -40,a0- --dtid 82345

You can decide if this works better or not ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A transaction can span multiple keyspaces so keyspace and shard will go in pair like keyspace/shard

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not find a good way to record the participants list.
We keep it like this for now.

go/vt/vtctl/grpcvtctldserver/server.go Show resolved Hide resolved
Signed-off-by: Harshit Gangal <[email protected]>
Copy link
Member

@GuptaManan100 GuptaManan100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest LGTM


// ConcludeTransaction makes a ConcludeTransaction gRPC call to a vtctld.
ConcludeTransaction = &cobra.Command{
Use: "conclude <dtid> [<keyspace/shard> ...]",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we even take in <keyspace/shard> list? Why don't we just conclude the transaction everywhere. Like the user only has one option, which is to conclude the transaction on all the shards, not on some shards.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thinking about it that if the list of keyspace/shard is not provided we will get it and then conclude on all.
This is more from if the user gets the unresolved transactions list then it knows which all shards are involved and can provide the list to conclude.

We can make the flow better. Let's do that in a follow up PR.

Comment on lines +2463 to +2471
for _, rm := range req.Participants {
eg.Go(func() error {
primary, err := s.getPrimaryTablet(newCtx, rm)
if err != nil {
return err
}
return s.tmc.ConcludeTransaction(newCtx, primary.Tablet, req.Dtid, false)
})
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the ss.Target tablet is part of the requested participants. Would we not end up calling ConcludeTransaction on it twice? First with the last argument being false, and the next time with true.

Also, if the ss.Target is not part of the requested participants, should we even do the second ConcludeTransaction call?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is the Metadata Manager Shard, it's conclude is about deleting the Transaction record once everything is resolved in other participating shards.

Participating shards is exclusive of Metadata Manager shard.

@harshit-gangal harshit-gangal merged commit 8b57e7c into vitessio:main Sep 16, 2024
100 checks passed
@harshit-gangal harshit-gangal deleted the vtctld-conclude-transactions branch September 16, 2024 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants