@@ -10,10 +10,12 @@ import (
10
10
"fmt"
11
11
12
12
"github.com/cockroachdb/cockroach/pkg/kv/kvpb"
13
+ "github.com/cockroachdb/cockroach/pkg/kv/kvserver"
13
14
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/allocator"
14
15
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/allocator/mmaprototype"
15
16
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/allocator/storepool"
16
17
"github.com/cockroachdb/cockroach/pkg/roachpb"
18
+ "github.com/cockroachdb/cockroach/pkg/settings/cluster"
17
19
"github.com/cockroachdb/cockroach/pkg/util/log"
18
20
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
19
21
)
@@ -62,17 +64,21 @@ func (s Author) External() bool {
62
64
type AllocatorSync struct {
63
65
sp * storepool.StorePool
64
66
mmAllocator mmaprototype.Allocator
67
+ st * cluster.Settings
65
68
mu struct {
66
69
syncutil.Mutex
67
70
changeSeqGen SyncChangeID
68
71
trackedChanges map [SyncChangeID ]trackedAllocatorChange
69
72
}
70
73
}
71
74
72
- func NewAllocatorSync (sp * storepool.StorePool , mmAllocator mmaprototype.Allocator ) * AllocatorSync {
75
+ func NewAllocatorSync (
76
+ sp * storepool.StorePool , mmAllocator mmaprototype.Allocator , st * cluster.Settings ,
77
+ ) * AllocatorSync {
73
78
as := & AllocatorSync {
74
79
sp : sp ,
75
80
mmAllocator : mmAllocator ,
81
+ st : st ,
76
82
}
77
83
as .mu .trackedChanges = make (map [SyncChangeID ]trackedAllocatorChange )
78
84
return as
@@ -122,9 +128,12 @@ func (as *AllocatorSync) NonMMAPreTransferLease(
122
128
)
123
129
log .Infof (ctx , "registering external lease transfer change: usage=%v changes=%v" ,
124
130
usage , replicaChanges )
125
- changeIDs := as .mmAllocator .RegisterExternalChanges (replicaChanges [:])
126
- if changeIDs == nil {
127
- log .Info (ctx , "mma did not track lease transfer, skipping" )
131
+ var changeIDs []mmaprototype.ChangeID
132
+ if kvserver .LoadBasedRebalancingMode .Get (& as .st .SV ) == kvserver .LBRebalancingMultiMetric {
133
+ changeIDs = as .mmAllocator .RegisterExternalChanges (replicaChanges [:])
134
+ if changeIDs == nil {
135
+ log .Info (ctx , "mma did not track lease transfer, skipping" )
136
+ }
128
137
}
129
138
trackedChange := trackedAllocatorChange {
130
139
typ : AllocatorChangeTypeLeaseTransfer ,
@@ -210,9 +219,12 @@ func (as *AllocatorSync) NonMMAPreChangeReplicas(
210
219
211
220
log .Infof (ctx , "registering external replica change: chgs=%v usage=%v changes=%v" ,
212
221
changes , usage , replicaChanges )
213
- changeIDs := as .mmAllocator .RegisterExternalChanges (replicaChanges )
214
- if changeIDs == nil {
215
- log .Info (ctx , "cluster does not have a range for the external replica change, skipping" )
222
+ var changeIDs []mmaprototype.ChangeID
223
+ if kvserver .LoadBasedRebalancingMode .Get (& as .st .SV ) == kvserver .LBRebalancingMultiMetric {
224
+ changeIDs = as .mmAllocator .RegisterExternalChanges (replicaChanges )
225
+ if changeIDs == nil {
226
+ log .Info (ctx , "cluster does not have a range for the external replica change, skipping" )
227
+ }
216
228
}
217
229
trackedChange := trackedAllocatorChange {
218
230
typ : AllocatorChangeTypeChangeReplicas ,
@@ -335,12 +347,14 @@ func (as *AllocatorSync) PostApply(ctx context.Context, syncChangeID SyncChangeI
335
347
}
336
348
delete (as .mu .trackedChanges , syncChangeID )
337
349
}()
338
- if changeIDs := tracked .changeIDs ; changeIDs != nil {
339
- log .Infof (ctx , "PostApply: tracked=%v change_ids=%v success: %v" , tracked , changeIDs , success )
340
- as .updateMetrics (success , tracked .typ , tracked .author )
341
- as .mmAllocator .AdjustPendingChangesDisposition (changeIDs , success )
342
- } else {
343
- log .Infof (ctx , "PostApply: tracked=%v no change_ids success: %v" , tracked , success )
350
+ if kvserver .LoadBasedRebalancingMode .Get (& as .st .SV ) == kvserver .LBRebalancingMultiMetric {
351
+ if changeIDs := tracked .changeIDs ; changeIDs != nil {
352
+ log .Infof (ctx , "PostApply: tracked=%v change_ids=%v success: %v" , tracked , changeIDs , success )
353
+ as .updateMetrics (success , tracked .typ , tracked .author )
354
+ as .mmAllocator .AdjustPendingChangesDisposition (changeIDs , success )
355
+ } else {
356
+ log .Infof (ctx , "PostApply: tracked=%v no change_ids success: %v" , tracked , success )
357
+ }
344
358
}
345
359
as .updateMetrics (success , tracked .typ , tracked .author )
346
360
if ! success {
0 commit comments