@@ -171,12 +171,12 @@ class TKqpResourceManager : public IKqpResourceManager {
171
171
SetConfigValues (config);
172
172
}
173
173
174
- void Bootstrap (NKikimrConfig::TTableServiceConfig::TResourceManager& config, TActorSystem* actorSystem, TActorId selfId) {
175
- if (!Counters) {
176
- Counters = MakeIntrusive<TKqpCounters>(AppData ()->Counters );
177
- }
174
+ void Registered (NKikimrConfig::TTableServiceConfig::TResourceManager& config, TActorSystem* actorSystem, TActorId selfId) {
178
175
ActorSystem = actorSystem;
179
176
SelfId = selfId;
177
+ if (!Counters) {
178
+ Counters = MakeIntrusive<TKqpCounters>(AppData (ActorSystem)->Counters );
179
+ }
180
180
UpdatePatternCache (config.GetKqpPatternCacheCapacityBytes (),
181
181
config.GetKqpPatternCacheCompiledCapacityBytes (),
182
182
config.GetKqpPatternCachePatternAccessTimesBeforeTryToCompile ());
@@ -582,20 +582,30 @@ class TKqpResourceManagerActor : public TActorBootstrapped<TKqpResourceManagerAc
582
582
TKqpResourceManagerActor (const NKikimrConfig::TTableServiceConfig::TResourceManager& config,
583
583
TIntrusivePtr<TKqpCounters> counters, const TActorId& resourceBrokerId,
584
584
std::shared_ptr<TKqpProxySharedResources>&& kqpProxySharedResources, ui32 nodeId)
585
- : Config(config)
585
+ : NodeId(nodeId)
586
+ , Config(config)
586
587
, ResourceBrokerId(resourceBrokerId ? resourceBrokerId : MakeResourceBrokerID())
587
588
, KqpProxySharedResources(std::move(kqpProxySharedResources))
588
589
{
589
590
ResourceManager = std::make_shared<TKqpResourceManager>(config, counters);
591
+ }
592
+
593
+ // Is called right after service registration
594
+ // and before any usual actor can try to get ResourceManager
595
+ void Registered (TActorSystem* sys, const TActorId& owner) override {
596
+ TActorBootstrapped::Registered (sys, owner);
597
+
598
+ ResourceManager->Registered (Config, sys, SelfId ());
599
+
590
600
with_lock (ResourceManagers.Lock ) {
591
- ResourceManagers.ByNodeId [nodeId] = ResourceManager;
592
- ResourceManagers.Default = ResourceManager;
601
+ if (ResourceManagers.Default .expired ()) { // There can be several managers in tests
602
+ ResourceManagers.Default = ResourceManager;
603
+ }
604
+ ResourceManagers.ByNodeId [NodeId] = ResourceManager;
593
605
}
594
606
}
595
607
596
608
void Bootstrap () {
597
- ResourceManager->Bootstrap (Config, TlsActivationContext->ActorSystem (), SelfId ());
598
-
599
609
LOG_D (" Start KqpResourceManagerActor at " << SelfId () << " with ResourceBroker at " << ResourceBrokerId);
600
610
601
611
// Subscribe for tenant changes
@@ -935,6 +945,7 @@ class TKqpResourceManagerActor : public TActorBootstrapped<TKqpResourceManagerAc
935
945
}
936
946
937
947
private:
948
+ const ui32 NodeId;
938
949
NKikimrConfig::TTableServiceConfig::TResourceManager Config;
939
950
940
951
const TActorId ResourceBrokerId;
@@ -984,7 +995,7 @@ std::shared_ptr<NRm::IKqpResourceManager> GetKqpResourceManager(TMaybe<ui32> _no
984
995
985
996
std::shared_ptr<NRm::IKqpResourceManager> TryGetKqpResourceManager (TMaybe<ui32> _nodeId) {
986
997
ui32 nodeId = _nodeId ? *_nodeId : TActivationContext::ActorSystem ()->NodeId ;
987
- auto rm = NRm::ResourceManagers.Default .lock ();
998
+ std::shared_ptr<NRm::TKqpResourceManager> rm = NRm::ResourceManagers.Default .lock ();
988
999
if (Y_LIKELY (rm && rm->GetNodeId () == nodeId)) {
989
1000
return rm;
990
1001
}
0 commit comments