diff --git a/pkg/kv/kvserver/batcheval/cmd_push_txn.go b/pkg/kv/kvserver/batcheval/cmd_push_txn.go index 5d4ee4b811d7..698d60553e90 100644 --- a/pkg/kv/kvserver/batcheval/cmd_push_txn.go +++ b/pkg/kv/kvserver/batcheval/cmd_push_txn.go @@ -161,7 +161,7 @@ func PushTxn( // written. If a transaction record for the transaction could be written in // the future then we must be in the first case. If one could not be written // then we know we're in either the second or the third case. - reply.PusheeTxn = SynthesizeTxnFromMeta(cArgs.EvalCtx, args.PusheeTxn) + reply.PusheeTxn = SynthesizeTxnFromMeta(ctx, cArgs.EvalCtx, args.PusheeTxn) if reply.PusheeTxn.Status == roachpb.ABORTED { // If the transaction is uncommittable, we don't even need to // persist an ABORTED transaction record, we can just consider it diff --git a/pkg/kv/kvserver/batcheval/cmd_query_txn.go b/pkg/kv/kvserver/batcheval/cmd_query_txn.go index 0b60aa744392..e02324b9e721 100644 --- a/pkg/kv/kvserver/batcheval/cmd_query_txn.go +++ b/pkg/kv/kvserver/batcheval/cmd_query_txn.go @@ -74,7 +74,7 @@ func QueryTxn( } else { // The transaction hasn't written a transaction record yet. // Attempt to synthesize it from the provided TxnMeta. - reply.QueriedTxn = SynthesizeTxnFromMeta(cArgs.EvalCtx, args.Txn) + reply.QueriedTxn = SynthesizeTxnFromMeta(ctx, cArgs.EvalCtx, args.Txn) } // Get the list of txns waiting on this txn. diff --git a/pkg/kv/kvserver/batcheval/cmd_recover_txn.go b/pkg/kv/kvserver/batcheval/cmd_recover_txn.go index 3904c956d0d2..5a8d098266ba 100644 --- a/pkg/kv/kvserver/batcheval/cmd_recover_txn.go +++ b/pkg/kv/kvserver/batcheval/cmd_recover_txn.go @@ -85,7 +85,7 @@ func RecoverTxn( // returned even if it is possible that the transaction was actually // COMMITTED. This is safe because a COMMITTED transaction must have // resolved all of its intents before garbage collecting its intents. - synthTxn := SynthesizeTxnFromMeta(cArgs.EvalCtx, args.Txn) + synthTxn := SynthesizeTxnFromMeta(ctx, cArgs.EvalCtx, args.Txn) if synthTxn.Status != roachpb.ABORTED { err := errors.Errorf("txn record synthesized with non-ABORTED status: %v", synthTxn) return result.Result{}, err diff --git a/pkg/kv/kvserver/batcheval/eval_context.go b/pkg/kv/kvserver/batcheval/eval_context.go index 60e1c429e094..0dfcb5059f41 100644 --- a/pkg/kv/kvserver/batcheval/eval_context.go +++ b/pkg/kv/kvserver/batcheval/eval_context.go @@ -76,7 +76,7 @@ type EvalContext interface { // for the provided transaction information. See Replica.CanCreateTxnRecord // for details about its arguments, return values, and preconditions. CanCreateTxnRecord( - txnID uuid.UUID, txnKey []byte, txnMinTS hlc.Timestamp, + ctx context.Context, txnID uuid.UUID, txnKey []byte, txnMinTS hlc.Timestamp, ) (ok bool, minCommitTS hlc.Timestamp, reason roachpb.TransactionAbortedReason) // GetMVCCStats returns a snapshot of the MVCC stats for the range. @@ -234,7 +234,7 @@ func (m *mockEvalCtxImpl) GetLastSplitQPS() float64 { return m.QPS } func (m *mockEvalCtxImpl) CanCreateTxnRecord( - uuid.UUID, []byte, hlc.Timestamp, + context.Context, uuid.UUID, []byte, hlc.Timestamp, ) (bool, hlc.Timestamp, roachpb.TransactionAbortedReason) { return m.CanCreateTxn() } diff --git a/pkg/kv/kvserver/batcheval/transaction.go b/pkg/kv/kvserver/batcheval/transaction.go index 1b522eefd243..8ef18a9937c5 100644 --- a/pkg/kv/kvserver/batcheval/transaction.go +++ b/pkg/kv/kvserver/batcheval/transaction.go @@ -130,7 +130,7 @@ func CanPushWithPriority(pusher, pushee *roachpb.Transaction) bool { func CanCreateTxnRecord(ctx context.Context, rec EvalContext, txn *roachpb.Transaction) error { // The transaction could not have written a transaction record previously // with a timestamp below txn.MinTimestamp. - ok, minCommitTS, reason := rec.CanCreateTxnRecord(txn.ID, txn.Key, txn.MinTimestamp) + ok, minCommitTS, reason := rec.CanCreateTxnRecord(ctx, txn.ID, txn.Key, txn.MinTimestamp) if !ok { log.VEventf(ctx, 2, "txn tombstone present; transaction has been aborted") return roachpb.NewTransactionAbortedError(reason) @@ -159,7 +159,9 @@ func CanCreateTxnRecord(ctx context.Context, rec EvalContext, txn *roachpb.Trans // TxnMeta. Proceeding to KV reads or intent resolution without this // information would cause a partial rollback, if any, to be reverted // and yield inconsistent data. -func SynthesizeTxnFromMeta(rec EvalContext, txn enginepb.TxnMeta) roachpb.Transaction { +func SynthesizeTxnFromMeta( + ctx context.Context, rec EvalContext, txn enginepb.TxnMeta, +) roachpb.Transaction { synth := roachpb.TransactionRecord{ TxnMeta: txn, Status: roachpb.PENDING, @@ -182,7 +184,7 @@ func SynthesizeTxnFromMeta(rec EvalContext, txn enginepb.TxnMeta) roachpb.Transa // Determine whether the record could ever be allowed to be written in the // future. The transaction could not have written a transaction record // previously with a timestamp below txn.MinTimestamp. - ok, minCommitTS, _ := rec.CanCreateTxnRecord(txn.ID, txn.Key, txn.MinTimestamp) + ok, minCommitTS, _ := rec.CanCreateTxnRecord(ctx, txn.ID, txn.Key, txn.MinTimestamp) if ok { // Forward the provisional commit timestamp by the minimum timestamp that // the transaction would be able to create a transaction record at. diff --git a/pkg/kv/kvserver/replica_eval_context_span.go b/pkg/kv/kvserver/replica_eval_context_span.go index e6d6c53c40fc..acbda0219623 100644 --- a/pkg/kv/kvserver/replica_eval_context_span.go +++ b/pkg/kv/kvserver/replica_eval_context_span.go @@ -165,12 +165,12 @@ func (rec SpanSetReplicaEvalContext) GetLastSplitQPS() float64 { // for the provided transaction information. See Replica.CanCreateTxnRecord // for details about its arguments, return values, and preconditions. func (rec SpanSetReplicaEvalContext) CanCreateTxnRecord( - txnID uuid.UUID, txnKey []byte, txnMinTS hlc.Timestamp, + ctx context.Context, txnID uuid.UUID, txnKey []byte, txnMinTS hlc.Timestamp, ) (bool, hlc.Timestamp, roachpb.TransactionAbortedReason) { rec.ss.AssertAllowed(spanset.SpanReadOnly, roachpb.Span{Key: keys.TransactionKey(txnKey, txnID)}, ) - return rec.i.CanCreateTxnRecord(txnID, txnKey, txnMinTS) + return rec.i.CanCreateTxnRecord(ctx, txnID, txnKey, txnMinTS) } // GetGCThreshold returns the GC threshold of the Range, typically updated when diff --git a/pkg/kv/kvserver/replica_tscache.go b/pkg/kv/kvserver/replica_tscache.go index ce8427cfad83..fed8dd6c2b7a 100644 --- a/pkg/kv/kvserver/replica_tscache.go +++ b/pkg/kv/kvserver/replica_tscache.go @@ -478,7 +478,7 @@ func (r *Replica) applyTimestampCache( // system. // func (r *Replica) CanCreateTxnRecord( - txnID uuid.UUID, txnKey []byte, txnMinTS hlc.Timestamp, + ctx context.Context, txnID uuid.UUID, txnKey []byte, txnMinTS hlc.Timestamp, ) (ok bool, minCommitTS hlc.Timestamp, reason roachpb.TransactionAbortedReason) { // Consult the timestamp cache with the transaction's key. The timestamp // cache is used in two ways for transactions without transaction records. diff --git a/pkg/kv/kvserver/replica_write.go b/pkg/kv/kvserver/replica_write.go index 20bdf8256e1d..13a6c8820d00 100644 --- a/pkg/kv/kvserver/replica_write.go +++ b/pkg/kv/kvserver/replica_write.go @@ -422,7 +422,7 @@ func (r *Replica) canAttempt1PCEvaluation( // The EndTxn checks whether the txn record can be created, but we're // eliding the EndTxn. So, we'll do the check instead. - ok, minCommitTS, reason := r.CanCreateTxnRecord(ba.Txn.ID, ba.Txn.Key, ba.Txn.MinTimestamp) + ok, minCommitTS, reason := r.CanCreateTxnRecord(ctx, ba.Txn.ID, ba.Txn.Key, ba.Txn.MinTimestamp) if !ok { newTxn := ba.Txn.Clone() newTxn.Status = roachpb.ABORTED