Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kvserver: return destination from AdminScatter #51607

Merged
merged 1 commit into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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