Skip to content

Commit

Permalink
kvserver,asim: move storepool ownership out of allocator
Browse files Browse the repository at this point in the history
This fully decouples the StorePool from the allocator by moving
ownership of the configured view of peer stores to the store
configuration (the original source), the store rebalancer, and various
structures in the allocator simulator.

Part of #91570.

Release note: None
  • Loading branch information
AlexTalks committed Dec 21, 2022
1 parent ef6db0c commit 79e7b0a
Show file tree
Hide file tree
Showing 23 changed files with 291 additions and 224 deletions.
21 changes: 10 additions & 11 deletions pkg/kv/kvserver/allocator/allocatorimpl/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@ type AllocatorMetrics struct {
type Allocator struct {
st *cluster.Settings
deterministic bool
StorePool storepool.AllocatorStorePool
nodeLatencyFn func(addr string) (time.Duration, bool)
// TODO(aayush): Let's replace this with a *rand.Rand that has a rand.Source
// wrapped inside a mutex, to avoid misuse.
Expand Down Expand Up @@ -509,28 +508,26 @@ func makeAllocatorMetrics() AllocatorMetrics {
}
}

// MakeAllocator creates a new allocator using the specified StorePool.
// MakeAllocator creates a new allocator.
// The deterministic flag indicates that this allocator is intended to be used
// with a deterministic store pool.
//
// In test cases where the store pool is nil, deterministic should be false.
func MakeAllocator(
st *cluster.Settings,
storePool storepool.AllocatorStorePool,
deterministic bool,
nodeLatencyFn func(addr string) (time.Duration, bool),
knobs *allocator.TestingKnobs,
) Allocator {
var randSource rand.Source
var deterministic bool
// There are number of test cases that make a test store but don't add
// gossip or a store pool. So we can't rely on the existence of the
// store pool in those cases.
if storePool != nil && storePool.IsDeterministic() {
if deterministic {
randSource = rand.NewSource(777)
deterministic = true
} else {
randSource = rand.NewSource(rand.Int63())
}
allocator := Allocator{
st: st,
deterministic: deterministic,
StorePool: storePool,
nodeLatencyFn: nodeLatencyFn,
randGen: makeAllocatorRand(randSource),
Metrics: makeAllocatorMetrics(),
Expand Down Expand Up @@ -2349,7 +2346,9 @@ func (a Allocator) shouldTransferLeaseForLeaseCountConvergence(
// PreferredLeaseholders returns a slice of replica descriptors corresponding to
// replicas that meet lease preferences (among the `existing` replicas).
func (a Allocator) PreferredLeaseholders(
storePool storepool.AllocatorStorePool, conf roachpb.SpanConfig, existing []roachpb.ReplicaDescriptor,
storePool storepool.AllocatorStorePool,
conf roachpb.SpanConfig,
existing []roachpb.ReplicaDescriptor,
) []roachpb.ReplicaDescriptor {
// Go one preference at a time. As soon as we've found replicas that match a
// preference, we don't need to look at the later preferences, because
Expand Down
Loading

0 comments on commit 79e7b0a

Please sign in to comment.