Skip to content

Commit 0988115

Browse files
committed
mma: make external caller mostly use an ExternalRangeChange
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
1 parent 1f1ee11 commit 0988115

File tree

12 files changed

+388
-235
lines changed

12 files changed

+388
-235
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
@@ -259,7 +259,7 @@ func (a *allocatorState) ProcessStoreLoadMsg(ctx context.Context, msg *StoreLoad
259259
}
260260

261261
// AdjustPendingChangeDisposition implements the Allocator interface.
262-
func (a *allocatorState) AdjustPendingChangeDisposition(change PendingRangeChange, success bool) {
262+
func (a *allocatorState) AdjustPendingChangeDisposition(change ExternalRangeChange, success bool) {
263263
a.mu.Lock()
264264
defer a.mu.Unlock()
265265
rs, ok := a.cs.ranges[change.RangeID]
@@ -279,7 +279,7 @@ func (a *allocatorState) AdjustPendingChangeDisposition(change PendingRangeChang
279279
// can be made about whether these changes will be found in the allocator's
280280
// state. We gather the found changes.
281281
var changes []*pendingReplicaChange
282-
for _, c := range change.pendingReplicaChanges {
282+
for _, c := range change.Changes {
283283
ch, ok := a.cs.pendingChanges[c.changeID]
284284
if !ok {
285285
continue
@@ -308,25 +308,27 @@ func (a *allocatorState) AdjustPendingChangeDisposition(change PendingRangeChang
308308
}
309309

310310
// RegisterExternalChange implements the Allocator interface.
311-
func (a *allocatorState) RegisterExternalChange(change PendingRangeChange) (ok bool) {
311+
func (a *allocatorState) RegisterExternalChange(
312+
change PendingRangeChange,
313+
) (_ ExternalRangeChange, ok bool) {
312314
a.mu.Lock()
313315
defer a.mu.Unlock()
314316
if err := a.cs.preCheckOnApplyReplicaChanges(change); err != nil {
315317
a.mmaMetrics.ExternalFailedToRegister.Inc(1)
316318
log.KvDistribution.Infof(context.Background(),
317319
"did not register external changes: due to %v", err)
318-
return false
320+
return ExternalRangeChange{}, false
319321
} else {
320322
a.mmaMetrics.ExternaRegisterSuccess.Inc(1)
321323
}
322324
a.cs.addPendingRangeChange(change)
323-
return true
325+
return MakeExternalRangeChange(change), true
324326
}
325327

326328
// ComputeChanges implements the Allocator interface.
327329
func (a *allocatorState) ComputeChanges(
328330
ctx context.Context, msg *StoreLeaseholderMsg, opts ChangeOptions,
329-
) []PendingRangeChange {
331+
) []ExternalRangeChange {
330332
a.mu.Lock()
331333
defer a.mu.Unlock()
332334
if msg.StoreID != opts.LocalStoreID {

0 commit comments

Comments
 (0)