Skip to content

Commit 6c78995

Browse files
committed
mmaintegration: add interface for store pool and mma
This commit integrates the store pool and MMA allocator into allocator sync via an interface to facilitate testing within this package.
1 parent 35f4f90 commit 6c78995

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

pkg/kv/kvserver/mmaintegration/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ go_library(
1414
"//pkg/kv/kvpb",
1515
"//pkg/kv/kvserver/allocator",
1616
"//pkg/kv/kvserver/allocator/mmaprototype",
17-
"//pkg/kv/kvserver/allocator/storepool",
1817
"//pkg/kv/kvserver/kvserverbase",
1918
"//pkg/roachpb",
2019
"//pkg/settings/cluster",

pkg/kv/kvserver/mmaintegration/allocator_sync.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/cockroachdb/cockroach/pkg/kv/kvpb"
1010
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/allocator"
1111
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/allocator/mmaprototype"
12-
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/allocator/storepool"
1312
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverbase"
1413
"github.com/cockroachdb/cockroach/pkg/roachpb"
1514
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
@@ -26,6 +25,28 @@ func (id SyncChangeID) IsValid() bool {
2625

2726
type SyncChangeID uint64
2827

28+
// storePool is an interface that defines the methods that the allocator sync
29+
// needs to call on the store pool. Using an interface to simplify testing.
30+
type storePool interface {
31+
// UpdateLocalStoresAfterLeaseTransfer is called by the allocator sync to
32+
// update the store pool after a lease transfer operation.
33+
UpdateLocalStoresAfterLeaseTransfer(transferFrom, transferTo roachpb.StoreID, usage allocator.RangeUsageInfo)
34+
// UpdateLocalStoreAfterRebalance is called by the allocator sync to update
35+
// the store pool after a rebalance operation.
36+
UpdateLocalStoreAfterRebalance(storeID roachpb.StoreID, rangeUsageInfo allocator.RangeUsageInfo, changeType roachpb.ReplicaChangeType)
37+
}
38+
39+
// mmaAllocator is an interface that defines the methods that the allocator sync
40+
// needs to call on the mma. Using an interface to simplify testing.
41+
type mmaAllocator interface {
42+
// RegisterExternalChanges is called by the allocator sync to register
43+
// external changes with the mma.
44+
RegisterExternalChanges(changes []mmaprototype.ReplicaChange) []mmaprototype.ChangeID
45+
// AdjustPendingChangesDisposition is called by the allocator sync to adjust
46+
// the disposition of pending changes.
47+
AdjustPendingChangesDisposition(changeIDs []mmaprototype.ChangeID, success bool)
48+
}
49+
2950
// TODO(wenyihu6): make sure allocator sync can tolerate cluster setting
3051
// changes not happening consistently or atomically across components. (For
3152
// example, replicate queue may call into allocator sync when mma is enabled but
@@ -37,9 +58,9 @@ type SyncChangeID uint64
3758
// disabled, its sole purpose is to track and apply changes to the store pool
3859
// upon success.
3960
type AllocatorSync struct {
40-
sp *storepool.StorePool
61+
sp storePool
4162
st *cluster.Settings
42-
mmaAllocator mmaprototype.Allocator
63+
mmaAllocator mmaAllocator
4364
mu struct {
4465
syncutil.Mutex
4566
// changeSeqGen is a monotonically increasing sequence number for
@@ -54,7 +75,7 @@ type AllocatorSync struct {
5475
}
5576

5677
func NewAllocatorSync(
57-
sp *storepool.StorePool, mmaAllocator mmaprototype.Allocator, st *cluster.Settings,
78+
sp storePool, mmaAllocator mmaAllocator, st *cluster.Settings,
5879
) *AllocatorSync {
5980
as := &AllocatorSync{
6081
sp: sp,

0 commit comments

Comments
 (0)