Skip to content

Commit

Permalink
storage: sort InternalReplicas before comparing
Browse files Browse the repository at this point in the history
Fixes an issue where the in-memory copy of RangeDescriptor is
out-of-sync with the copy in kv.

Release note: None
  • Loading branch information
jeffrey-xiao authored and asubiotto committed Jul 2, 2019
1 parent cd0c005 commit 2c865ee
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/storage/replica_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,22 @@ func conditionalGetDescValueFromDB(
return nil, errors.Wrap(err, "decoding current range descriptor value")
}
}
// TODO(jeffreyxiao): This hacky fix ensures that we don't fail the
// conditional get because of the ordering of InternalReplicas. Calling
// Replicas() will sort the list of InternalReplicas as a side-effect. The
// invariant of having InternalReplicas sorted is not maintained in 19.1.
// Additionally, in 19.2, it's possible for the in-memory copy of
// RangeDescriptor to become sorted from a call to Replicas() without
// updating the copy in kv. These two factors makes it possible for the
// in-memory copy to be out of sync from the copy in kv. The sorted invariant
// of InternalReplicas is used by ReplicaDescriptors.Voters() and
// ReplicaDescriptors.Learners().
if existingDesc != nil {
existingDesc.Replicas() // for sorting side-effect
}
if expectation != nil {
expectation.Replicas() // for sorting side-effect
}
if !existingDesc.Equal(expectation) {
return nil, &roachpb.ConditionFailedError{ActualValue: existingDescKV.Value}
}
Expand Down

0 comments on commit 2c865ee

Please sign in to comment.