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

feat: Broadcast min_commit_ts for pipelined transactions #1458

Merged
merged 24 commits into from
Sep 25, 2024

Conversation

ekexium
Copy link
Contributor

@ekexium ekexium commented Sep 5, 2024

Ref: tikv/tikv#17459
Prerequires pingcap/kvproto#1265

Changes

  1. Periodic updates of min_commit_ts
  2. Broadcast min_commit_ts
  3. Periodic updates of full store list

@ti-chi-bot ti-chi-bot bot added dco-signoff: yes Indicates the PR's author has signed the dco. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 5, 2024
@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 5, 2024
txnkv/transaction/2pc.go Outdated Show resolved Hide resolved
txnkv/transaction/2pc.go Show resolved Hide resolved
txnkv/transaction/2pc.go Outdated Show resolved Hide resolved
txnkv/transaction/2pc.go Outdated Show resolved Hide resolved
@ekexium ekexium force-pushed the feat-resolved-ts-for-large-txn branch from 1789ae4 to ad0302e Compare September 19, 2024 07:36
Copy link
Contributor

@you06 you06 left a comment

Choose a reason for hiding this comment

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

BTW, this is not related to this PR, can you change the RLock/RUnlock to Lock/Unlock here?

I have a question about the future plan, have you considered apply this broadcast also for slow or large 2pc transactions?

internal/locate/region_cache.go Outdated Show resolved Hide resolved
txnkv/transaction/2pc.go Outdated Show resolved Hide resolved
txnkv/transaction/pipelined_flush.go Show resolved Hide resolved
@ekexium
Copy link
Contributor Author

ekexium commented Sep 20, 2024

BTW, this is not related to this PR, can you change the RLock/RUnlock to Lock/Unlock here?

Done.

I have a question about the future plan, have you considered apply this broadcast also for slow or large 2pc transactions?

It's possible. But I think we need more empirical data before implementing that. It's unclear now how this optimization would benefit normal large transactions.

Comment on lines 751 to 757
if store == nil || store.GetState() == metapb.StoreState_Tombstone {
s.setResolveState(tombstone)
continue
}
addr := store.GetAddress()
if addr == "" {
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to explain in the comments when the pdClient.GetAllStores(ctx) may return a store list containg nil store and emptry address and how should they be treated. For example, dose it mean the returned store list is invalid and pdClient.GetAllStores(ctx) should be retried when there invalid element in the list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe that GetAllStores is supposed to return only stores in Up and Offline states. This additional check serves as a defensive measure and ensures consistency with the store resolve procedure

internal/locate/region_cache.go Outdated Show resolved Hide resolved
internal/locate/region_cache.go Outdated Show resolved Hide resolved
wg.Wait()
}

if err := txn.spawnWithStorePool(broadcastFunc); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we've already used a goroutine pool, how about spawning broadcast tasks like the following:

	stores := store.GetRegionCache().GetStoresByType(tikvrpc.TiKV)
	rateLimit := make(chan struct{}, min(broadcastMaxConcurrency, len(stores)))
	for _, s := range stores {
		rateLimit <- struct{}{}
		target := s
		err := txn.spawnWithStorePool(func() {
			defer func() {
				<-rateLimit
			}()
			// send request to target
		})
		if err != nil {
			<-rateLimit
		}
	}

@ekexium ekexium force-pushed the feat-resolved-ts-for-large-txn branch from afbcb64 to 4aada7a Compare September 24, 2024 08:33
@ekexium ekexium force-pushed the feat-resolved-ts-for-large-txn branch from 3e9a4ec to 012425a Compare September 24, 2024 08:45
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Sep 24, 2024
@ti-chi-bot ti-chi-bot bot added the lgtm label Sep 25, 2024
Copy link

ti-chi-bot bot commented Sep 25, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfzjywxk, zyguan

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

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Sep 25, 2024
Copy link

ti-chi-bot bot commented Sep 25, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-09-24 12:53:30.169772239 +0000 UTC m=+1570479.910196175: ☑️ agreed by zyguan.
  • 2024-09-25 01:31:10.938538581 +0000 UTC m=+1615940.678962520: ☑️ agreed by cfzjywxk.

@ti-chi-bot ti-chi-bot bot merged commit 527f80a into tikv:master Sep 25, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved dco-signoff: yes Indicates the PR's author has signed the dco. lgtm size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants