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 cockroachdb#91570.

Release note: None
  • Loading branch information
AlexTalks authored and adityamaru committed Dec 22, 2022
1 parent 70897c6 commit 37e91a6
Show file tree
Hide file tree
Showing 23 changed files with 313 additions and 235 deletions.
23 changes: 12 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,28 @@ 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.
// TODO(sarkesian): Eliminate the need for this flag, which is a remnant of
// close coupling with the StorePool.
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 +2348,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 37e91a6

Please sign in to comment.