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

Support txn file transaction #1119

Merged
merged 15 commits into from
May 8, 2024
Merged

Support txn file transaction #1119

merged 15 commits into from
May 8, 2024

Conversation

coocood
Copy link

@coocood coocood commented Jan 17, 2024

Txn File transaction is used for transactions of big size (>= 16MiB). By building chunks on external worker and then ingesting to TiKV, txn file transactions will reduce cost and load of TiKV comparing to normal transactions.

pingyu and others added 9 commits April 11, 2024 09:36
…1285)

* *: update pd client to latest master (#1283)

Signed-off-by: disksing <[email protected]>

* fix go.mod

Signed-off-by: Ping Yu <[email protected]>

* loop of LocateKey to get overlapping regions

Signed-off-by: Ping Yu <[email protected]>

* polish

Signed-off-by: Ping Yu <[email protected]>

---------

Signed-off-by: disksing <[email protected]>
Signed-off-by: Ping Yu <[email protected]>
Co-authored-by: disksing <[email protected]>
* pick primary batch by primary key

Signed-off-by: Ping Yu <[email protected]>

* sort batches by region

Signed-off-by: Ping Yu <[email protected]>

---------

Signed-off-by: Ping Yu <[email protected]>
* remove retry

Signed-off-by: Ping Yu <[email protected]>

* polish

Signed-off-by: Ping Yu <[email protected]>

* revert ignore pre split error

Signed-off-by: Ping Yu <[email protected]>

---------

Signed-off-by: Ping Yu <[email protected]>
Signed-off-by: Ping Yu <[email protected]>
@pingyu pingyu changed the title [WIP] support txn file transaction Support txn file transaction May 1, 2024
@pingyu pingyu marked this pull request as ready for review May 1, 2024 03:14
"github.com/stretchr/testify/require"
)

func TestMergeRangesSearchOverlapped(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about add some comments to the test case?

kv/variables.go Outdated
@@ -57,6 +60,7 @@ func NewVariables(killed *uint32) *Variables {
BackoffLockFast: DefBackoffLockFast,
BackOffWeight: DefBackOffWeight,
Killed: killed,
EnableTxnFile: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

it’s better to use GLOBAL variables to control whether txn file transaction is enabled or not.
It allows user to try it out on some clusters first. We have serverless version in TiDB which is very convenient to turn on all switches.
You can see serverless version in
https://github.com/tidbcloud/tidb-cse/blob/release-7.1-keyspace/session/bootstrap_serverless.go

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes it's designed to be used for variables. And here is the client-go part.

The tidb-cse part will be added after here:

	{Scope: ScopeGlobal | ScopeSession, Name: TiDBBackoffLockFast, Value: strconv.Itoa(tikvstore.DefBackoffLockFast), Type: TypeUnsigned, MinValue: 1, MaxValue: math.MaxInt32, SetSession: func(s *SessionVars, val string) error {
		s.KVVars.BackoffLockFast = tidbOptPositiveInt32(val, tikvstore.DefBackoffLockFast)
		return nil
	}},
	{Scope: ScopeGlobal | ScopeSession, Name: TiDBBackOffWeight, Value: strconv.Itoa(tikvstore.DefBackOffWeight), Type: TypeUnsigned, MinValue: 0, MaxValue: math.MaxInt32, SetSession: func(s *SessionVars, val string) error {
		s.KVVars.BackOffWeight = tidbOptPositiveInt32(val, tikvstore.DefBackOffWeight)
		return nil
	}},

return mark, false
}

func (m *MergeRanges) Covered(start []byte, end []byte) bool {
Copy link
Contributor

@ystaticy ystaticy May 8, 2024

Choose a reason for hiding this comment

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

Suggested change
func (m *MergeRanges) Covered(start []byte, end []byte) bool {
// Covered returns true if m.ranges completely covers the startkey to endkey range.
func (m *MergeRanges) Covered(start []byte, end []byte) bool {

Signed-off-by: Ping Yu <[email protected]>
)

var (
// BuildTxnFileMaxBackoff is max sleep time to build TxnFile.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// BuildTxnFileMaxBackoff is max sleep time to build TxnFile.
// BuildTxnFileMaxBackoff is max sleep Millisecond to build TxnFile.

}

// chunkBatch.txnChunkSlice should be sorted by smallest.
func (b *chunkBatch) getSampleKeys() [][]byte {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about rename to getSortedChunkSliceSmallestKeys, which better represents what the function returns.

Copy link
Contributor

Choose a reason for hiding this comment

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

The method is named as its purpose, not implementation.

And the implementation would be changed in the future, e.g, we can store extra keys in the middle of chunk and use here, if necessary.

@coocood coocood merged commit 6bfb15c into tidb-cse-7.5 May 8, 2024
9 checks passed
@coocood coocood deleted the txn-file branch May 8, 2024 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants