-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
store: update kvproto.CheckTxnStatus response #13432
Changes from 11 commits
7bc8c6f
3014ef9
28144de
7003818
f08f59e
eb9cc30
5a47660
fe11fb9
2ff5e70
90371ad
260d155
c8b5932
69d7fb6
df186b8
e4e7403
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -387,11 +387,11 @@ func (h *rpcHandler) handleKvCheckTxnStatus(req *kvrpcpb.CheckTxnStatusRequest) | |
panic("KvCheckTxnStatus: key not in region") | ||
} | ||
var resp kvrpcpb.CheckTxnStatusResponse | ||
ttl, commitTS, err := h.mvccStore.CheckTxnStatus(req.GetPrimaryKey(), req.GetLockTs(), req.GetCallerStartTs(), req.GetCurrentTs(), req.GetRollbackIfNotExist()) | ||
ttl, commitTS, rollbackReason, err := h.mvccStore.CheckTxnStatus(req.GetPrimaryKey(), req.GetLockTs(), req.GetCallerStartTs(), req.GetCurrentTs(), req.GetRollbackIfNotExist()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. variable name should update There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
if err != nil { | ||
resp.Error = convertToKeyError(err) | ||
} else { | ||
resp.LockTtl, resp.CommitVersion = ttl, commitTS | ||
resp.LockTtl, resp.CommitVersion, resp.Action = ttl, commitTS, rollbackReason | ||
} | ||
return &resp | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,7 @@ func NewLockResolver(etcdAddrs []string, security config.Security) (*LockResolve | |
type TxnStatus struct { | ||
ttl uint64 | ||
commitTS uint64 | ||
action kvrpcpb.Action | ||
} | ||
Comment on lines
109
to
113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this definition be moved to a better place in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would involve too many irrelevant changes in this PR |
||
|
||
// IsCommitted returns true if the txn's final status is Commit. | ||
|
@@ -397,7 +398,7 @@ func (lr *LockResolver) getTxnStatusFromLock(bo *Backoffer, l *Lock, callerStart | |
} | ||
|
||
if l.LockType == kvrpcpb.Op_PessimisticLock { | ||
return TxnStatus{l.TTL, 0}, nil | ||
return TxnStatus{ttl: l.TTL}, nil | ||
} | ||
|
||
// Handle txnNotFound error. | ||
|
@@ -482,6 +483,7 @@ func (lr *LockResolver) getTxnStatus(bo *Backoffer, txnID uint64, primary []byte | |
logutil.BgLogger().Error("getTxnStatus error", zap.Error(err)) | ||
return status, err | ||
} | ||
status.action = cmdResp.Action | ||
if cmdResp.LockTtl != 0 { | ||
status.ttl = cmdResp.LockTtl | ||
youjiali1995 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,7 +201,7 @@ func (s *testLockSuite) TestGetTxnStatus(c *C) { | |
status, err = s.store.lockResolver.GetTxnStatus(startTS, startTS, []byte("a")) | ||
c.Assert(err, IsNil) | ||
c.Assert(status.IsCommitted(), IsFalse) | ||
c.Assert(status.ttl, Greater, uint64(0)) | ||
c.Assert(status.ttl, Greater, uint64(0), Commentf("rollback reason:%s", status.action)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. log message need update There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
} | ||
|
||
func (s *testLockSuite) TestCheckTxnStatusTTL(c *C) { | ||
|
@@ -234,6 +234,7 @@ func (s *testLockSuite) TestCheckTxnStatusTTL(c *C) { | |
c.Assert(err, IsNil) | ||
c.Assert(status.ttl, Equals, uint64(0)) | ||
c.Assert(status.commitTS, Equals, uint64(0)) | ||
c.Assert(status.action, Equals, kvrpcpb.Action_NoAction) | ||
|
||
// Check a committed txn. | ||
startTS, commitTS := s.putKV(c, []byte("a"), []byte("a")) | ||
|
@@ -287,6 +288,7 @@ func (s *testLockSuite) TestCheckTxnStatus(c *C) { | |
c.Assert(status.IsCommitted(), IsFalse) | ||
c.Assert(status.ttl, Greater, uint64(0)) | ||
c.Assert(status.CommitTS(), Equals, uint64(0)) | ||
c.Assert(status.action, kvrpcpb.Action_MinCommitTSPushed) | ||
|
||
// Test the ResolveLocks API | ||
lock := s.mustGetLock(c, []byte("second")) | ||
|
@@ -303,10 +305,11 @@ func (s *testLockSuite) TestCheckTxnStatus(c *C) { | |
// Then call getTxnStatus again and check the lock status. | ||
currentTS, err = oracle.GetTimestamp(context.Background()) | ||
c.Assert(err, IsNil) | ||
status, err = resolver.getTxnStatus(bo, txn.StartTS(), []byte("key"), currentTS, currentTS, true) | ||
status, err = newLockResolver(s.store).getTxnStatus(bo, txn.StartTS(), []byte("key"), currentTS, 0, true) | ||
c.Assert(err, IsNil) | ||
c.Assert(status.ttl, Equals, uint64(0)) | ||
c.Assert(status.commitTS, Equals, uint64(0)) | ||
c.Assert(status.action, Equals, kvrpcpb.Action_NoAction) | ||
|
||
// Call getTxnStatus on a committed transaction. | ||
startTS, commitTS := s.putKV(c, []byte("a"), []byte("a")) | ||
|
@@ -366,14 +369,15 @@ func (s *testLockSuite) TestCheckTxnStatusNoWait(c *C) { | |
c.Assert(err, IsNil) | ||
lock = &Lock{ | ||
Key: []byte("second"), | ||
Primary: []byte("key"), | ||
Primary: []byte("key_not_exist"), | ||
TxnID: startTS, | ||
TTL: 1000, | ||
} | ||
status, err = resolver.getTxnStatusFromLock(bo, lock, currentTS) | ||
c.Assert(err, IsNil) | ||
c.Assert(status.ttl, Equals, uint64(0)) | ||
c.Assert(status.commitTS, Equals, uint64(0)) | ||
c.Assert(status.action, Equals, kvrpcpb.Action_LockNotExistRollback) | ||
} | ||
|
||
func (s *testLockSuite) prewriteTxn(c *C, txn *tikvTxn) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to set this action even if minCommitTS is already greater than callerStartTS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, get it!
That information is actually 'could the caller read ignore the lock', rather than 'minCommitTS pushed'