Skip to content

Commit

Permalink
kvserver: return destination from AdminScatter
Browse files Browse the repository at this point in the history
AdminScatter now returns the RangeInfos of each range that is scatter by
the request. The returned RangeInfos can be used to determine the
leaseholder of the range after the scattering of the range.

Release note: None
  • Loading branch information
pbardea committed Aug 2, 2020
1 parent 815725c commit 843dcc4
Show file tree
Hide file tree
Showing 7 changed files with 865 additions and 683 deletions.
66 changes: 52 additions & 14 deletions c-deps/libroach/protos/roachpb/api.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 66 additions & 28 deletions c-deps/libroach/protos/roachpb/api.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 15 additions & 6 deletions pkg/kv/kvserver/replica_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2395,14 +2395,23 @@ func (r *Replica) adminScatter(
}
}

desc := r.Desc()
desc, lease := r.GetDescAndLease(ctx)
return roachpb.AdminScatterResponse{
Ranges: []roachpb.AdminScatterResponse_Range{{
Span: roachpb.Span{
Key: desc.StartKey.AsRawKey(),
EndKey: desc.EndKey.AsRawKey(),
// TODO(pbardea): This is here for compatibility with 20.1, remove in 21.1.
DeprecatedRanges: []roachpb.AdminScatterResponse_Range{
{
Span: roachpb.Span{
Key: desc.StartKey.AsRawKey(),
EndKey: desc.EndKey.AsRawKey(),
},
},
},
RangeInfos: []roachpb.RangeInfo{
{
Desc: desc,
Lease: lease,
},
}},
},
}, nil
}

Expand Down
31 changes: 30 additions & 1 deletion pkg/roachpb/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,40 @@ func (r *AdminScatterResponse) combine(c combinable) error {
if err := r.ResponseHeader.combine(otherR.Header()); err != nil {
return err
}
r.Ranges = append(r.Ranges, otherR.Ranges...)

// Combined responses will always have only RangeInfo set, rather than
// DeprecatedRanges.
// TODO(pbardea): Remove in 21.1.
r.maybeUpgrade()
otherR.maybeUpgrade()
r.RangeInfos = append(r.RangeInfos, otherR.RangeInfos...)
}
return nil
}

// maybeUpgrade will upgrade responses from 20.1 clients to look like 20.2
// responses.
// It converts the DeprecatedRanges field of the response to the equivalent
// RangeInfos and nils out DeprecatedRanges. Note that the converted RangeInfos
// will have an empty lease and only have the start and end key of the range
// descriptor populated.
func (r *AdminScatterResponse) maybeUpgrade() {
if len(r.RangeInfos) == 0 {
r.RangeInfos = make([]RangeInfo, len(r.DeprecatedRanges))
for i, respRange := range r.DeprecatedRanges {
r.RangeInfos[i] = RangeInfo{
// respRange.Span's keys are not local keys. The keys were created with
// AsRawKey(), so converting back is safe.
Desc: RangeDescriptor{
StartKey: RKey(respRange.Span.Key),
EndKey: RKey(respRange.Span.EndKey),
},
}
}
}
r.DeprecatedRanges = nil
}

var _ combinable = &AdminScatterResponse{}

// Header implements the Request interface.
Expand Down
Loading

0 comments on commit 843dcc4

Please sign in to comment.