From daf4e5932a4b74a9854b2adf219c537c19a73e45 Mon Sep 17 00:00:00 2001 From: lyang24 Date: Thu, 23 May 2024 15:13:09 -0700 Subject: [PATCH] kv: shallow copy BatchRequest on mutate in tryBumpBatchTimestamp This avoids a data race on tryBumpBatchTimestamp, which was fallout from the new logging introduced in ba13697. Fixes: #124553 Release note: None --- pkg/kv/kvserver/replica_batch_updates.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/kv/kvserver/replica_batch_updates.go b/pkg/kv/kvserver/replica_batch_updates.go index 63705f695205..2dbf01df4243 100644 --- a/pkg/kv/kvserver/replica_batch_updates.go +++ b/pkg/kv/kvserver/replica_batch_updates.go @@ -239,8 +239,11 @@ func tryBumpBatchTimestamp( } log.VEventf(ctx, 2, "bumping batch timestamp to: %s from read: %s, write: %s", ts, ba.Txn.ReadTimestamp, ba.Txn.WriteTimestamp) - ba.Txn = ba.Txn.Clone() - ba.Txn.BumpReadTimestamp(ts) - ba.Timestamp = ba.Txn.ReadTimestamp // Refresh just updated ReadTimestamp + txn := ba.Txn.Clone() + txn.BumpReadTimestamp(ts) + readTs := ba.Txn.ReadTimestamp + ba = ba.ShallowCopy() + ba.Txn = txn + ba.Timestamp = readTs // Refresh just updated ReadTimestamp return true }