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

pump/: Accelerat transaction status queries throught GetMvccByEncodeKey #632

Merged
merged 12 commits into from
Jun 18, 2019

Conversation

july2993
Copy link
Contributor

@july2993 july2993 commented Jun 10, 2019

What problem does this PR solve?

Avoid some case that we wait 10 minutes after the transaction and call GetTxnStatus which send the CleanupRequest that will get the commit ts of transaction or rollback the transaction.

What is changed and how it works?

Query txn info by GetMvccByEncodeKey.
we can know if the txn if committed or rollback as quick as possible.

If we can't get the status we will fallback to the case call GetTxnStatus after 10 minute of the transaction.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
    • using sysbench tps = 10k
    • kill -9 tidb
      log of the pump with this pr
[tidb@ip-172-16-4-74 tikv]$ tail  -f log/pump.log | grep "known txn"
[2019/06/10 17:24:59.192 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244264] ["commit ts"=408986240913244423]
[2019/06/10 17:25:02.192 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244269] ["commit ts"=408986240913244494]
[2019/06/10 17:25:05.192 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244275] ["commit ts"=408986240913244488]
[2019/06/10 17:25:08.193 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244292] ["commit ts"=408986240913244482]
[2019/06/10 17:25:11.193 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244298] ["commit ts"=408986240913244518]
[2019/06/10 17:25:14.195 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244344] ["commit ts"=408986240913244468]
[2019/06/10 17:25:17.194 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244362] ["commit ts"=408986240913244485]
[2019/06/10 17:25:20.194 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244336] ["commit ts"=408986240913244517]
[2019/06/10 17:25:23.199 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244363] ["commit ts"=408986240913244419]
[2019/06/10 17:25:26.197 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244364] ["commit ts"=408986240913244447]
[2019/06/10 17:25:29.197 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244342] ["commit ts"=408986240913244489]
[2019/06/10 17:25:32.197 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244314] ["commit ts"=408986240913244448]
[2019/06/10 17:25:35.201 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244379] ["commit ts"=408986240913244450]
[2019/06/10 17:25:38.200 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244391] ["commit ts"=408986240913244506]
[2019/06/10 17:25:41.200 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244384] ["commit ts"=408986240913244528]
[2019/06/10 17:25:44.200 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244397] ["commit ts"=408986240913244505]
[2019/06/10 17:26:16.494 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244401] ["commit ts"=0]
[2019/06/10 17:26:17.497 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244406] ["commit ts"=0]
[2019/06/10 17:30:21.015 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244404] ["commit ts"=0]
[2019/06/10 17:30:22.017 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244410] ["commit ts"=408986240913244542]
[2019/06/10 17:30:23.023 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244412] ["commit ts"=0]
[2019/06/10 17:30:24.026 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244418] ["commit ts"=408986240913244531]
[2019/06/10 17:30:25.028 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244428] ["commit ts"=0]
[2019/06/10 17:34:55.403 +08:00] [INFO] [storage.go:468] ["known txn is committed from tikv"] ["start ts"=408986240913244441] ["commit ts"=0]
[2019/06/10 17:34:56.406 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244455] ["commit ts"=0]
[2019/06/10 17:34:57.408 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244463] ["commit ts"=0]
[2019/06/10 17:34:58.411 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244460] ["commit ts"=0]
[2019/06/10 17:34:59.413 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244454] ["commit ts"=0]
[2019/06/10 17:35:00.415 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244497] ["commit ts"=0]
[2019/06/10 17:35:01.417 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244457] ["commit ts"=0]
[2019/06/10 17:35:02.423 +08:00] [INFO] [storage.go:468] ["known txn is committed from tikv"] ["start ts"=408986240913244474] ["commit ts"=0]
[2019/06/10 17:35:03.425 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244495] ["commit ts"=0]
[2019/06/10 17:35:04.437 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244479] ["commit ts"=0]
[2019/06/10 17:35:05.440 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244490] ["commit ts"=0]
[2019/06/10 17:35:06.442 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244453] ["commit ts"=0]
[2019/06/10 17:35:07.446 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244473] ["commit ts"=0]
[2019/06/10 17:35:08.448 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244512] ["commit ts"=0]
[2019/06/10 17:35:09.451 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244521] ["commit ts"=0]
[2019/06/10 17:35:10.531 +08:00] [INFO] [storage.go:433] ["known txn is committed or rollback from tikv"] ["start ts"=408986240913244523] ["commit ts"=0]

.74 is the version with this pr
Screen Shot 2019-06-10 at 5 56 59 PM

Screen Shot 2019-06-10 at 6 00 04 PM

Code changes

Side effects

Related changes

  • Need to cherry-pick to the release branch
  • Need to be included in the release note

pump/server.go Outdated

if len(binlog.PrewriteKey) > 0 {
tikvStorage := s.tiStore.(tikv.Storage)
healper := storage.Helper{
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not one Helper instance?

Copy link
Contributor Author

@july2993 july2993 Jun 11, 2019

Choose a reason for hiding this comment

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

no performance cost and only use here so I think better just construct here, don't make Server struct complicate

pump/server.go Outdated
RegionCache: tikvStorage.GetRegionCache(),
}

resp, err := healper.GetMvccByEncodedKey(binlog.PrewriteKey)
Copy link
Collaborator

Choose a reason for hiding this comment

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

we can extract one function queryTransactionStatus, then just call it. the implementation output too many unless and old mvcc records

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for debug just keep all info?

@IANTHEREAL
Copy link
Collaborator

Good Job!

@IANTHEREAL IANTHEREAL changed the title pump/: Query txn info by GetMvccByEncodeKey pump/: Accelerat transaction status queries throught GetMvccByEncodeKey Jun 10, 2019
pump/storage/storage.go Outdated Show resolved Hide resolved
@IANTHEREAL
Copy link
Collaborator

if item.tp == pb.BinlogType_Prewrite {
	getTime := time.Now()

	for {
		_, ok := s.waitStartTS[item.start]
		if !ok {
			break
		}

		// we may get the C binlog soon at start up time
		if time.Since(getTime) > time.Second {
		        if s.resolver != nil && s.resolver(item.start) {
				break
			}
		}

should we put getTime := time.Now() in the for loop?

pump/server.go Outdated Show resolved Hide resolved
pump/server.go Show resolved Hide resolved
}
kvResp, err := h.Store.SendReq(tikv.NewBackoffer(context.Background(), 500), tikvReq, keyLocation.Region, time.Minute)
if err != nil {
log.Info("get MVCC by encoded key failed",
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
log.Info("get MVCC by encoded key failed",
log.Error("get MVCC by encoded key failed",

}

// GetMvccByEncodedKey get the MVCC value by the specific encoded key.
func (h *Helper) GetMvccByEncodedKey(encodedKey kv.Key) (*kvrpcpb.MvccGetByKeyResponse, error) {
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 just define a function GetMVCCByEncodedKey(tikv.Storage, kv.Key) instead? It seems like we have no other use for the Helper struct here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

// Copy from https://github.com/pingcap/tidb/blob/71def9c7263432c0dfa6a5960f6db824775177c9/store/helper/helper.go#L47
// we can use it directly if we upgrade to the latest version of TiDB dependency.

add comment in helper.go
and we may add other myself if not use TiDB code directly.

pump/storage/storage.go Outdated Show resolved Hide resolved
pump/storage/storage.go Outdated Show resolved Hide resolved
@july2993
Copy link
Contributor Author

/run-all-tests

@july2993
Copy link
Contributor Author

/run-all-tests

1 similar comment
@july2993
Copy link
Contributor Author

/run-all-tests

@july2993 july2993 requested a review from suzaku June 13, 2019 02:23
@IANTHEREAL
Copy link
Collaborator

LGTM

@suzaku
Copy link
Contributor

suzaku commented Jun 17, 2019

/run-all-tests

@suzaku
Copy link
Contributor

suzaku commented Jun 18, 2019

/run-all-tests

@july2993
Copy link
Contributor Author

/run-unit-test

Copy link
Contributor

@suzaku suzaku left a comment

Choose a reason for hiding this comment

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

LGTM

@suzaku
Copy link
Contributor

suzaku commented Jun 18, 2019

/run-all-tests

@suzaku suzaku merged commit d54d6b9 into pingcap:master Jun 18, 2019
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.

3 participants