Skip to content

Commit

Permalink
plumb ctx
Browse files Browse the repository at this point in the history
  • Loading branch information
andreimatei committed Sep 9, 2020
1 parent cc8f5e1 commit 3b99b1f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions pkg/kv/kvserver/replica_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func splitTxnAttempt(
{
b := txn.NewBatch()
leftDescKey := keys.RangeDescriptorKey(leftDesc.StartKey)
if err := updateRangeDescriptor(b, leftDescKey, dbDescValue, leftDesc); err != nil {
if err := updateRangeDescriptor(ctx, b, leftDescKey, dbDescValue, leftDesc); err != nil {
return err
}
// Commit this batch first to ensure that the transaction record
Expand All @@ -215,7 +215,7 @@ func splitTxnAttempt(
// Write range descriptor for right hand side of the split.
rightDescKey := keys.RangeDescriptorKey(rightDesc.StartKey)
log.Infof(ctx, "!!! will write RHS desc: %s", rightDesc)
if err := updateRangeDescriptor(b, rightDescKey, nil, rightDesc); err != nil {
if err := updateRangeDescriptor(ctx, b, rightDescKey, nil, rightDesc); err != nil {
return err
}

Expand Down Expand Up @@ -253,7 +253,7 @@ func splitTxnStickyUpdateAttempt(

b := txn.NewBatch()
descKey := keys.RangeDescriptorKey(desc.StartKey)
if err := updateRangeDescriptor(b, descKey, dbDescValue, &newDesc); err != nil {
if err := updateRangeDescriptor(ctx, b, descKey, dbDescValue, &newDesc); err != nil {
return err
}
if err := updateRangeAddressing(b, &newDesc); err != nil {
Expand Down Expand Up @@ -465,7 +465,7 @@ func (r *Replica) adminUnsplitWithDescriptor(
descKey := keys.RangeDescriptorKey(newDesc.StartKey)

b := txn.NewBatch()
if err := updateRangeDescriptor(b, descKey, dbDescValue, &newDesc); err != nil {
if err := updateRangeDescriptor(ctx, b, descKey, dbDescValue, &newDesc); err != nil {
return err
}
if err := updateRangeAddressing(b, &newDesc); err != nil {
Expand Down Expand Up @@ -672,7 +672,7 @@ func (r *Replica) AdminMerge(
b := txn.NewBatch()
leftDescKey := keys.RangeDescriptorKey(updatedLeftDesc.StartKey)
if err := updateRangeDescriptor(
b, leftDescKey, dbOrigLeftDescValue, &updatedLeftDesc,
ctx, b, leftDescKey, dbOrigLeftDescValue, &updatedLeftDesc,
); err != nil {
return err
}
Expand Down Expand Up @@ -701,7 +701,7 @@ func (r *Replica) AdminMerge(
}

// Remove the range descriptor for the deleted range.
if err := updateRangeDescriptor(b, rightDescKey, dbRightDescKV.Value, nil); err != nil {
if err := updateRangeDescriptor(ctx, b, rightDescKey, dbRightDescKV.Value, nil); err != nil {
return err
}

Expand Down Expand Up @@ -1608,7 +1608,7 @@ func execChangeReplicasTxn(

// Important: the range descriptor must be the first thing touched in the transaction
// so the transaction record is co-located with the range being modified.
if err := updateRangeDescriptor(b, descKey, dbDescValue, crt.Desc); err != nil {
if err := updateRangeDescriptor(ctx, b, descKey, dbDescValue, crt.Desc); err != nil {
return err
}

Expand Down Expand Up @@ -2007,7 +2007,11 @@ func conditionalGetDescValueFromDB(
// descriptor, a CommitTrigger must be used to update the in-memory
// descriptor; it will not automatically be copied from newDesc.
func updateRangeDescriptor(
b *kv.Batch, descKey roachpb.Key, oldValue *roachpb.Value, newDesc *roachpb.RangeDescriptor,
ctx context.Context,
b *kv.Batch,
descKey roachpb.Key,
oldValue *roachpb.Value,
newDesc *roachpb.RangeDescriptor,
) error {
// This is subtle: []byte(nil) != interface{}(nil). A []byte(nil) refers to
// an empty value. An interface{}(nil) refers to a non-existent value. So
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/replica_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func (tc *testContext) addBogusReplicaToRangeDesc(
Header: roachpb.Header{Timestamp: tc.Clock().Now()},
}
descKey := keys.RangeDescriptorKey(oldDesc.StartKey)
if err := updateRangeDescriptor(&ba, descKey, dbDescKV.Value, &newDesc); err != nil {
if err := updateRangeDescriptor(ctx, &ba, descKey, dbDescKV.Value, &newDesc); err != nil {
return roachpb.ReplicaDescriptor{}, err
}
if err := tc.store.DB().Run(ctx, &ba); err != nil {
Expand Down

0 comments on commit 3b99b1f

Please sign in to comment.