Skip to content

Commit 203532c

Browse files
authored
executor: fix point get in pessimistic txn (pingcap#5)
In pessimistic txn, statement retry should use 'for update ts' to read but point get use the snapshot with start ts
1 parent 8abd975 commit 203532c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

executor/adapter.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,9 @@ func (a *ExecStmt) handleNoDelayExecutor(ctx context.Context, sctx sessionctx.Co
438438
return nil, errors.Trace(err)
439439
}
440440

441+
// Rollback the statement change before retry it.
442+
sctx.StmtRollback()
443+
441444
if err = e.Open(ctx); err != nil {
442445
return nil, errors.Trace(err)
443446
}

executor/point_get.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,17 @@ func (e *PointGetExecutor) get(key kv.Key) (val []byte, err error) {
137137
if err != nil {
138138
return nil, errors.Trace(err)
139139
}
140+
140141
if txn != nil && txn.Valid() && !txn.IsReadOnly() {
141-
return txn.Get(key)
142+
val, err = txn.GetMemBuffer().Get(key)
143+
if err == nil {
144+
return val, err
145+
}
146+
if !kv.IsErrNotFound(err) {
147+
return nil, err
148+
}
142149
}
150+
// In pessimistic txn, this snapshot may be using the 'for update ts' instead of start ts.
143151
return e.snapshot.Get(key)
144152
}
145153

0 commit comments

Comments
 (0)