Skip to content

Commit d2cfdda

Browse files
committed
server: make mma Allocator calls more visible
They were kind of hidden before, and it has been tripping me up every now and then for a while. The problem was that NewAllocatorState returns a private struct directly, so a bunch of the calls later in the method do not show up when you look at the call hierarchy for the Allocator interface. This is now fixed. Epic: CRDB-55052.
1 parent 05c6218 commit d2cfdda

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

pkg/server/server.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -903,9 +903,16 @@ func NewServer(cfg Config, stopper *stop.Stopper) (serverctl.ServerStartupInterf
903903
uint64(kvserver.EagerLeaseAcquisitionConcurrency.Get(&cfg.Settings.SV)))
904904
})
905905

906-
mmaAllocator := mmaprototype.NewAllocatorState(timeutil.DefaultTimeSource{},
907-
rand.New(rand.NewSource(timeutil.Now().UnixNano())))
908-
allocatorSync := mmaintegration.NewAllocatorSync(storePool, mmaAllocator, st, nil)
906+
mmaAlloc, mmaAllocSync := func() (mmaprototype.Allocator, *mmaintegration.AllocatorSync) {
907+
mmaAllocState := mmaprototype.NewAllocatorState(timeutil.DefaultTimeSource{},
908+
rand.New(rand.NewSource(timeutil.Now().UnixNano())))
909+
allocatorSync := mmaintegration.NewAllocatorSync(storePool, mmaAllocState, st, nil)
910+
// We make sure that mmaAllocState is returned through the `Allocator`
911+
// interface so that when looking up callers to the interface, we see this
912+
// call site.
913+
return mmaAllocState, allocatorSync
914+
}()
915+
909916
g.RegisterCallback(
910917
gossip.MakePrefixPattern(gossip.KeyStoreDescPrefix),
911918
func(_ string, content roachpb.Value, origTimestampNanos int64) {
@@ -915,8 +922,8 @@ func NewServer(cfg Config, stopper *stop.Stopper) (serverctl.ServerStartupInterf
915922
return
916923
}
917924
storeLoadMsg := mmaintegration.MakeStoreLoadMsg(storeDesc, origTimestampNanos)
918-
mmaAllocator.SetStore(state.StoreAttrAndLocFromDesc(storeDesc))
919-
mmaAllocator.ProcessStoreLoadMsg(context.TODO(), &storeLoadMsg)
925+
mmaAlloc.SetStore(state.StoreAttrAndLocFromDesc(storeDesc))
926+
mmaAlloc.ProcessStoreLoadMsg(context.TODO(), &storeLoadMsg)
920927
},
921928
)
922929

@@ -931,8 +938,8 @@ func NewServer(cfg Config, stopper *stop.Stopper) (serverctl.ServerStartupInterf
931938
NodeLiveness: nodeLiveness,
932939
StoreLiveness: storeLiveness,
933940
StorePool: storePool,
934-
MMAllocator: mmaAllocator,
935-
AllocatorSync: allocatorSync,
941+
MMAllocator: mmaAlloc,
942+
AllocatorSync: mmaAllocSync,
936943
Transport: raftTransport,
937944
NodeDialer: kvNodeDialer,
938945
RPCContext: rpcContext,

0 commit comments

Comments
 (0)