Skip to content

Commit 4253489

Browse files
craig[bot]sumeerbhola
andcommitted
Merge #158153
158153: mma: make external caller mostly use an ExternalRangeChange r=sumeerbhola a=sumeerbhola An ExternalRangeChange does not have the currently mutable fields of PendingRangeChange (and the set of mutable fields is going to expand in the near future). Todos related to limitation of viewing a change as a "change replicas" or "lease transfer" etc., are moved to ExternalRangeChange, so compartmentalized to methods that are called by integration code outside the mma package. There is still some potential future cleanup involving unexporting PendingRangeChange, which is not in scope for this PR. The PendingRangeChange becomes a temporary container for a slice of []*pendingReplicaChanges. Printing this struct no longer involves viewing it as a "change replicas" or "lease transfer". Furthermore, the ReplicaChange.replicaChangeType field is removed and the change type is now a function of prev and next. This sets us up for making prev mutable in a future PR. Informs #157049 Epic: CRDB-55052 Release note: None Co-authored-by: sumeerbhola <sumeer@cockroachlabs.com>
2 parents 6e3c4b9 + d2b2bb3 commit 4253489

File tree

12 files changed

+402
-247
lines changed

12 files changed

+402
-247
lines changed

pkg/kv/kvserver/allocator/mmaprototype/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ go_library(
1313
"load.go",
1414
"memo_helper.go",
1515
"messages.go",
16+
"range_change.go",
1617
"rebalance_advisor.go",
1718
"store_load_summary.go",
1819
"store_set.go",

pkg/kv/kvserver/allocator/mmaprototype/allocator.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ type Allocator interface {
5656
// Calls to AdjustPendingChangeDisposition must be correctly sequenced with
5757
// full state updates from the local node provided in
5858
// ProcessNodeLoadResponse.
59-
AdjustPendingChangeDisposition(change PendingRangeChange, success bool)
59+
AdjustPendingChangeDisposition(change ExternalRangeChange, success bool)
6060

6161
// RegisterExternalChange informs this allocator about yet to complete
6262
// changes to the cluster which were not initiated by this allocator. The
6363
// ownership of all state inside change is handed off to the callee. If ok
64-
// is true, the change was registered, and the caller should subsequently
65-
// use the same change in a subsequent call to
64+
// is true, the change was registered, and the caller is returned an
65+
// ExternalRangeChange that it should subsequently use in a call to
6666
// AdjustPendingChangeDisposition when the changes are completed, either
6767
// successfully or not. If ok is false, the change was not registered.
68-
RegisterExternalChange(change PendingRangeChange) (ok bool)
68+
RegisterExternalChange(change PendingRangeChange) (_ ExternalRangeChange, ok bool)
6969

7070
// ComputeChanges is called periodically and frequently, say every 10s.
7171
//
@@ -82,7 +82,7 @@ type Allocator interface {
8282
// the allocator, to avoid re-proposing the same change and to make
8383
// adjustments to the load.
8484
ComputeChanges(
85-
ctx context.Context, msg *StoreLeaseholderMsg, opts ChangeOptions) []PendingRangeChange
85+
ctx context.Context, msg *StoreLeaseholderMsg, opts ChangeOptions) []ExternalRangeChange
8686

8787
// AdminRelocateOne is a helper for AdminRelocateRange.
8888
//

pkg/kv/kvserver/allocator/mmaprototype/allocator_state.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func (a *allocatorState) ProcessStoreLoadMsg(ctx context.Context, msg *StoreLoad
254254
}
255255

256256
// AdjustPendingChangeDisposition implements the Allocator interface.
257-
func (a *allocatorState) AdjustPendingChangeDisposition(change PendingRangeChange, success bool) {
257+
func (a *allocatorState) AdjustPendingChangeDisposition(change ExternalRangeChange, success bool) {
258258
a.mu.Lock()
259259
defer a.mu.Unlock()
260260
rs, ok := a.cs.ranges[change.RangeID]
@@ -274,7 +274,7 @@ func (a *allocatorState) AdjustPendingChangeDisposition(change PendingRangeChang
274274
// can be made about whether these changes will be found in the allocator's
275275
// state. We gather the found changes.
276276
var changes []*pendingReplicaChange
277-
for _, c := range change.pendingReplicaChanges {
277+
for _, c := range change.Changes {
278278
ch, ok := a.cs.pendingChanges[c.changeID]
279279
if !ok {
280280
continue
@@ -303,25 +303,27 @@ func (a *allocatorState) AdjustPendingChangeDisposition(change PendingRangeChang
303303
}
304304

305305
// RegisterExternalChange implements the Allocator interface.
306-
func (a *allocatorState) RegisterExternalChange(change PendingRangeChange) (ok bool) {
306+
func (a *allocatorState) RegisterExternalChange(
307+
change PendingRangeChange,
308+
) (_ ExternalRangeChange, ok bool) {
307309
a.mu.Lock()
308310
defer a.mu.Unlock()
309311
if err := a.cs.preCheckOnApplyReplicaChanges(change); err != nil {
310312
a.mmaMetrics.ExternalFailedToRegister.Inc(1)
311313
log.KvDistribution.Infof(context.Background(),
312314
"did not register external changes: due to %v", err)
313-
return false
315+
return ExternalRangeChange{}, false
314316
} else {
315317
a.mmaMetrics.ExternaRegisterSuccess.Inc(1)
316318
}
317319
a.cs.addPendingRangeChange(change)
318-
return true
320+
return MakeExternalRangeChange(change), true
319321
}
320322

321323
// ComputeChanges implements the Allocator interface.
322324
func (a *allocatorState) ComputeChanges(
323325
ctx context.Context, msg *StoreLeaseholderMsg, opts ChangeOptions,
324-
) []PendingRangeChange {
326+
) []ExternalRangeChange {
325327
a.mu.Lock()
326328
defer a.mu.Unlock()
327329
if msg.StoreID != opts.LocalStoreID {

0 commit comments

Comments
 (0)