Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
109794: storage: break some dependencies on inconsistent reads with intent interleaving r=sumeerbhola a=nvanbenschoten

Informs cockroachdb#109647.

This commit eliminates a pair of dependencies in mvccPutInternal on inconsistent reads and intent interleaving when a transactional write wanted to read below its own intent. Instead, we can simply read at the timestamp preceding the intent, which is what the pebbleMVCCScanner was doing under the hood anyway.

Release note: None

Co-authored-by: Nathan VanBenschoten <[email protected]>
  • Loading branch information
craig[bot] and nvanbenschoten committed Sep 5, 2023
2 parents 75789fe + 2e2f413 commit 2af50c0
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions pkg/storage/mvcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1754,11 +1754,10 @@ func replayTransactionalWrite(
// If the previous value at the key wasn't written by this
// transaction, or it was hidden by a rolled back seqnum, we look at
// last committed value on the key. Since we want the last committed
// value on the key, we must make an inconsistent read so we ignore
// our previous intents here.
exVal, _, err = mvccGet(ctx, iter, key, timestamp, MVCCGetOptions{
Inconsistent: true,
Tombstones: true,
// value on the key, we read below our previous intents here.
metaTimestamp := meta.Timestamp.ToTimestamp()
exVal, _, err = mvccGet(ctx, iter, key, metaTimestamp.Prev(), MVCCGetOptions{
Tombstones: true,
})
if err != nil {
return err
Expand Down Expand Up @@ -2026,11 +2025,10 @@ func mvccPutInternal(
// "last write outside txn"
// => use inconsistent mvccGetInternal to retrieve the last committed value at key.
//
// Since we want the last committed value on the key, we must make
// an inconsistent read so we ignore our previous intents here.
exVal, _, err = mvccGet(ctx, iter, key, readTimestamp, MVCCGetOptions{
Inconsistent: true,
Tombstones: true,
// Since we want the last committed value on the key, we must
// read below our previous intents here.
exVal, _, err = mvccGet(ctx, iter, key, metaTimestamp.Prev(), MVCCGetOptions{
Tombstones: true,
})
if err != nil {
return false, err
Expand Down

0 comments on commit 2af50c0

Please sign in to comment.