From 2e2f413d3bf830be87c6a4151020f575a81725a3 Mon Sep 17 00:00:00 2001 From: Nathan VanBenschoten Date: Thu, 31 Aug 2023 01:23:49 -0400 Subject: [PATCH] storage: break some dependencies on inconsistent reads with intent interleaving Informs #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 --- pkg/storage/mvcc.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/pkg/storage/mvcc.go b/pkg/storage/mvcc.go index dd5012bf53f8..c046837af9b3 100644 --- a/pkg/storage/mvcc.go +++ b/pkg/storage/mvcc.go @@ -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 @@ -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