Skip to content

kv: unify the BeginWith... function into one#23130

Merged
ti-chi-bot merged 6 commits intopingcap:masterfrom
Yisaer:unify_begin
Mar 5, 2021
Merged

kv: unify the BeginWith... function into one#23130
ti-chi-bot merged 6 commits intopingcap:masterfrom
Yisaer:unify_begin

Conversation

@Yisaer
Copy link
Contributor

@Yisaer Yisaer commented Mar 5, 2021

Signed-off-by: Song Gao disxiaofei@163.com

What problem does this PR solve?

Currently, we have serval BeginWithXXX functions in kv.Storage. In future, we are going to support time-bounded staleness transaction which may continue to add more BeginWithXXX functions.

What is changed and how it works?

This request unify all the BeginWithXXX functions into one and only leave 2 function like following:

	Begin() (Transaction, error)
	BeginWithOption(option TransactionOption) (Transaction, error)

Release note

  • No release note

Signed-off-by: Song Gao <disxiaofei@163.com>
@ti-chi-bot ti-chi-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 5, 2021
@Yisaer
Copy link
Contributor Author

Yisaer commented Mar 5, 2021

/sig sql-infra

@ti-chi-bot ti-chi-bot added the sig/sql-infra SIG: SQL Infra label Mar 5, 2021
@Yisaer
Copy link
Contributor Author

Yisaer commented Mar 5, 2021

/cc @xhebox

@ti-chi-bot ti-chi-bot requested a review from xhebox March 5, 2021 05:23
Signed-off-by: Song Gao <disxiaofei@163.com>
@Yisaer

This comment has been minimized.

@Yisaer
Copy link
Contributor Author

Yisaer commented Mar 5, 2021

/sig transaction

@ti-chi-bot ti-chi-bot added the sig/transaction SIG:Transaction label Mar 5, 2021
@Yisaer
Copy link
Contributor Author

Yisaer commented Mar 5, 2021

/cc @longfangsong

@ti-chi-bot
Copy link
Member

@Yisaer: GitHub didn't allow me to request PR reviews from the following users: longfangsong.

Note that only pingcap members and repo collaborators can review this PR, and authors cannot review their own PRs.

Details

In response to this:

/cc @longfangsong

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@longfangsong
Copy link
Contributor

longfangsong commented Mar 5, 2021

IMO Scope should be part of the TransactionOption.
I wonder would it be better if we make it something like:

type TransactionOption struct {
	StartTS *uint64
	PrevSec *uint64
	Scope *string
}

Then we could do something like (is it possible to have all these options set in the future?)

BeginWithOption(TransactionOption{}.SetStartTs(xxx).SetScope(yyy).SetPrevSec(zzz))

and implement BeginWithTxnScope with BeginWithOption

@xhebox
Copy link
Contributor

xhebox commented Mar 5, 2021

is it possible to have all these options set in the future?

For now, it is exclusive. That is why there is an TransactionOptionType.

But I agree that only left one Begin(...Options) may be a good idea.

Copy link
Contributor

@xhebox xhebox left a comment

Choose a reason for hiding this comment

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

LGTM. If you don't want to address the comment of @longfangsong , i.e. unify the api more aggressively. or want to address it in the next PR, I will give a lgtm.

@ti-chi-bot
Copy link
Member

@xhebox: Please use /LGTM instead of LGTM when you want to approve the pull request by comment.
If you use the GitHub review feature, please approve the PR directly, the comment will not take effect in the GitHub review feature.
If you have any qustions please refer to lgtm command help or lgtm plugin design.

If you have approved this PR, please ignore this reply. This reply is being used as a temporary reply during the migration of the new bot and will be removed on April 1.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

Copy link
Contributor

@longfangsong longfangsong left a comment

Choose a reason for hiding this comment

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

/lgtm

We may discuss about more agressive refactoring later.

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 5, 2021
Yisaer added 2 commits March 5, 2021 15:13
Signed-off-by: Song Gao <disxiaofei@163.com>
@Yisaer
Copy link
Contributor Author

Yisaer commented Mar 5, 2021

IMO Scope should be part of the TransactionOption.
I wonder would it be better if we make it something like:

type TransactionOption struct {
	StartTS *uint64
	PrevSec *uint64
	Scope *string
}

Then we could do something like (is it possible to have all these options set in the future?)

BeginWithOption(TransactionOption{}.SetStartTs(xxx).SetScope(yyy).SetPrevSec(zzz))

and implement BeginWithTxnScope with BeginWithOption

This advice LGTM. updated.

Signed-off-by: Song Gao <disxiaofei@163.com>
Copy link
Contributor

@xhebox xhebox 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

Comment on lines +472 to +474
TxnScope string
StartTS *uint64
PrevSec *uint64
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it is a good idea to use pointers for integers in go. It may bring another two escaped memory. Copying a slice of string or integers is free.


// no need to get txn from txnFutureCh since txn should init with startTs
txn, err := s.store.BeginWithOption(s.GetSessionVars().CheckAndGetTxnScope(), kv.WithStartTSOption(startTS))
txn, err := s.store.BeginWithOption(kv.TransactionOption{}.SetTxnScope(s.GetSessionVars().CheckAndGetTxnScope()).SetStartTs(startTS))
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe give a NewTransactionOptionBuilder or just NewTransactionOption instead of constructing a struct by hand.

@disksing
Copy link
Contributor

disksing commented Mar 5, 2021

/run-all-tests

@xhebox
Copy link
Contributor

xhebox commented Mar 5, 2021

/lgtm

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • longfangsong
  • xhebox

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Details

Reviewer can indicate their review by writing /lgtm in a comment.
Reviewer can cancel approval by writing /lgtm cancel in a comment.

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Mar 5, 2021
@Yisaer
Copy link
Contributor Author

Yisaer commented Mar 5, 2021

/merge

@ti-chi-bot
Copy link
Member

@Yisaer: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Member

@Yisaer: /merge is only allowed for the committers in list.

Details

In response to this:

/merge

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@Yisaer

This comment has been minimized.

@xhebox
Copy link
Contributor

xhebox commented Mar 5, 2021

/merge

@ti-chi-bot
Copy link
Member

@xhebox: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

DetailsCommit hash: e81b357

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 5, 2021
@ti-chi-bot
Copy link
Member

@Yisaer: Your PR was out of date, I have automatically updated it for you.

At the same time I will also trigger all tests for you:

/run-all-tests

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@xhebox
Copy link
Contributor

xhebox commented Mar 5, 2021

/run-unit-test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sig/sql-infra SIG: SQL Infra sig/transaction SIG:Transaction size/L Denotes a PR that changes 100-499 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants