Skip to content

Commit

Permalink
kvstorage: assert against range desc overlap
Browse files Browse the repository at this point in the history
Epic: none
Release note: None
  • Loading branch information
tbg committed Feb 3, 2023
1 parent 45f538d commit 20685eb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
44 changes: 26 additions & 18 deletions pkg/kv/kvserver/kvstorage/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,24 +385,32 @@ func LoadAndReconcileReplicas(ctx context.Context, eng storage.Engine) (LoadedRe
// the state of the Replica.
// INVARIANT: the descriptor for range [a,z) is located at RangeDescriptorKey(a).
// This is checked in IterateRangeDescriptorsFromDisk.
if err := IterateRangeDescriptorsFromDisk(
ctx, eng, func(desc roachpb.RangeDescriptor) error {
// INVARIANT: a Replica's RangeDescriptor always contains the local Store,
// i.e. a Store is a member of all of its local Replicas.
repDesc, found := desc.GetReplicaDescriptor(ident.StoreID)
if !found {
return errors.AssertionFailedf(
"RangeDescriptor does not contain local s%d: %s",
ident.StoreID, desc)
}

if err := s.setDesc(desc.RangeID, desc); err != nil {
return err
}
s.setDescReplicaID(desc.RangeID, repDesc.ReplicaID)
return nil
}); err != nil {
return LoadedReplicas{}, err
{
var lastDesc roachpb.RangeDescriptor
if err := IterateRangeDescriptorsFromDisk(
ctx, eng, func(desc roachpb.RangeDescriptor) error {
if lastDesc.RangeID != 0 && desc.StartKey.Less(lastDesc.EndKey) {
return errors.AssertionFailedf("overlapping descriptors %s and %s", lastDesc, desc)
}
lastDesc = desc

// INVARIANT: a Replica's RangeDescriptor always contains the local Store,
// i.e. a Store is a member of all of its local Replicas.
repDesc, found := desc.GetReplicaDescriptor(ident.StoreID)
if !found {
return errors.AssertionFailedf(
"RangeDescriptor does not contain local s%d: %s",
ident.StoreID, desc)
}

if err := s.setDesc(desc.RangeID, desc); err != nil {
return err
}
s.setDescReplicaID(desc.RangeID, repDesc.ReplicaID)
return nil
}); err != nil {
return LoadedReplicas{}, err
}
}

// INVARIANT: all replicas have a persisted full ReplicaID (i.e. a "ReplicaID from disk").
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ r2:{b-d} [(n1,s1):20, next=21, gen=0]

load-and-reconcile
----
r1/10: r1:{a-c} [(n1,s1):10, next=11, gen=0]
r2/20: r2:{b-d} [(n1,s1):20, next=21, gen=0]
overlapping descriptors r1:{a-c} [(n1,s1):10, next=11, gen=0] and r2:{b-d} [(n1,s1):20, next=21, gen=0]

0 comments on commit 20685eb

Please sign in to comment.