Skip to content

Commit

Permalink
executor: fix point get in pessimistic txn (pingcap#5)
Browse files Browse the repository at this point in the history
In pessimistic txn, statement retry should use 'for update ts' to read
but point get use the snapshot with start ts
  • Loading branch information
tiancaiamao authored Apr 17, 2019
1 parent 8abd975 commit 203532c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ func (a *ExecStmt) handleNoDelayExecutor(ctx context.Context, sctx sessionctx.Co
return nil, errors.Trace(err)
}

// Rollback the statement change before retry it.
sctx.StmtRollback()

if err = e.Open(ctx); err != nil {
return nil, errors.Trace(err)
}
Expand Down
10 changes: 9 additions & 1 deletion executor/point_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,17 @@ func (e *PointGetExecutor) get(key kv.Key) (val []byte, err error) {
if err != nil {
return nil, errors.Trace(err)
}

if txn != nil && txn.Valid() && !txn.IsReadOnly() {
return txn.Get(key)
val, err = txn.GetMemBuffer().Get(key)
if err == nil {
return val, err
}
if !kv.IsErrNotFound(err) {
return nil, err
}
}
// In pessimistic txn, this snapshot may be using the 'for update ts' instead of start ts.
return e.snapshot.Get(key)
}

Expand Down

0 comments on commit 203532c

Please sign in to comment.