Skip to content

Commit

Permalink
roachpb: improve RangeDescriptor.Validate
Browse files Browse the repository at this point in the history
Make sure there isn't more than one replica per store.

Release note: None
  • Loading branch information
tbg committed Aug 23, 2019
1 parent 7a07ce0 commit eb7d146
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/roachpb/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ func (r *RangeDescriptor) Validate() error {
return errors.Errorf("NextReplicaID must be non-zero")
}
seen := map[ReplicaID]struct{}{}
stores := map[StoreID]struct{}{}
for i, rep := range r.Replicas().All() {
if err := rep.Validate(); err != nil {
return errors.Errorf("replica %d is invalid: %s", i, err)
Expand All @@ -232,6 +233,10 @@ func (r *RangeDescriptor) Validate() error {
return errors.Errorf("ReplicaID %d must be less than NextReplicaID %d",
rep.ReplicaID, r.NextReplicaID)
}
if _, ok := stores[rep.StoreID]; ok {
return errors.Errorf("StoreID %d was reused", rep.StoreID)
}
stores[rep.StoreID] = struct{}{}
}
return nil
}
Expand Down

0 comments on commit eb7d146

Please sign in to comment.