Skip to content

Commit

Permalink
storage: break some dependencies on inconsistent reads with intent in…
Browse files Browse the repository at this point in the history
…terleaving

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
  • Loading branch information
nvanbenschoten committed Aug 31, 2023
1 parent b713686 commit 2e2f413
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 @@ -1772,11 +1772,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 @@ -2038,11 +2037,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 2e2f413

Please sign in to comment.