Skip to content

Commit

Permalink
kvserver: plumb ctx to txn record creation helper
Browse files Browse the repository at this point in the history
Release note: None
  • Loading branch information
andreimatei committed May 26, 2021
1 parent 3e82795 commit 70b13ab
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/batcheval/cmd_push_txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/batcheval/cmd_query_txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/batcheval/cmd_recover_txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/kv/kvserver/batcheval/eval_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
}
Expand Down
8 changes: 5 additions & 3 deletions pkg/kv/kvserver/batcheval/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions pkg/kv/kvserver/replica_eval_context_span.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/replica_tscache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/replica_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 70b13ab

Please sign in to comment.