22#include " kqp_compute_actor.h"
33
44#include < ydb/core/kqp/common/kqp_resolve.h>
5+ #include < ydb/core/kqp/node_service/kqp_node_state.h>
56#include < ydb/core/kqp/rm_service/kqp_resource_estimation.h>
67
78namespace NKikimr ::NKqp::NComputeActor {
@@ -11,24 +12,17 @@ struct TMemoryQuotaManager : public NYql::NDq::TGuaranteeQuotaManager {
1112
1213 TMemoryQuotaManager (std::shared_ptr<NRm::IKqpResourceManager> resourceManager
1314 , NRm::EKqpMemoryPool memoryPool
14- , std::shared_ptr<IKqpNodeState> state
1515 , TIntrusivePtr<NRm::TTxState> tx
1616 , TIntrusivePtr<NRm::TTaskState> task
1717 , ui64 limit)
1818 : NYql::NDq::TGuaranteeQuotaManager(limit, limit)
1919 , ResourceManager(std::move(resourceManager))
2020 , MemoryPool(memoryPool)
21- , State(std::move(state))
2221 , Tx(std::move(tx))
2322 , Task(std::move(task))
24- {
25- }
23+ {}
2624
2725 ~TMemoryQuotaManager () override {
28- if (State) {
29- State->OnTaskTerminate (Tx->TxId , Task->TaskId , Success);
30- }
31-
3226 ResourceManager->FreeResources (Tx, Task);
3327 }
3428
@@ -71,7 +65,6 @@ struct TMemoryQuotaManager : public NYql::NDq::TGuaranteeQuotaManager {
7165
7266 std::shared_ptr<NRm::IKqpResourceManager> ResourceManager;
7367 NRm::EKqpMemoryPool MemoryPool;
74- std::shared_ptr<IKqpNodeState> State;
7568 TIntrusivePtr<NRm::TTxState> Tx;
7669 TIntrusivePtr<NRm::TTaskState> Task;
7770 bool Success = true ;
@@ -169,7 +162,6 @@ class TKqpCaFactory : public IKqpNodeComputeActorFactory {
169162 memoryLimits.MemoryQuotaManager = std::make_shared<TMemoryQuotaManager>(
170163 ResourceManager_,
171164 args.MemoryPool ,
172- std::move (args.State ),
173165 std::move (args.TxInfo ),
174166 std::move (task),
175167 limit);
@@ -193,12 +185,14 @@ class TKqpCaFactory : public IKqpNodeComputeActorFactory {
193185 }
194186
195187 NYql::NDq::IMemoryQuotaManager::TWeakPtr memoryQuotaManager = memoryLimits.MemoryQuotaManager ;
196- runtimeSettings.TerminateHandler = [memoryQuotaManager]
188+ runtimeSettings.TerminateHandler = [memoryQuotaManager, state=args. State , txId=args. TxId , taskId=args. Task -> GetId () ]
197189 (bool success, const NYql::TIssues& issues) {
198- auto manager = memoryQuotaManager.lock ();
199- if (manager) {
190+ if (auto manager = memoryQuotaManager.lock ()) {
200191 static_cast <TMemoryQuotaManager*>(manager.get ())->TerminateHandler (success, issues);
201192 }
193+ if (state) {
194+ state->OnTaskFinished (txId, taskId, success);
195+ }
202196 };
203197
204198 NKikimrTxDataShard::TKqpTransaction::TScanTaskMeta meta;
@@ -224,8 +218,7 @@ class TKqpCaFactory : public IKqpNodeComputeActorFactory {
224218 YQL_ENSURE (args.ComputesByStages );
225219 auto & info = args.ComputesByStages ->UpsertTaskWithScan (*args.Task , meta);
226220 IActor* computeActor = CreateKqpScanComputeActor (
227- args.ExecuterId , args.TxId ,
228- args.Task , AsyncIoFactory, runtimeSettings, memoryLimits,
221+ args.ExecuterId , args.TxId , args.Task , AsyncIoFactory, runtimeSettings, memoryLimits,
229222 std::move (args.TraceId ), std::move (args.Arena ),
230223 std::move (schedulableOptions), args.BlockTrackingMode );
231224 TActorId result = TlsActivationContext->Register (computeActor);
@@ -236,8 +229,10 @@ class TKqpCaFactory : public IKqpNodeComputeActorFactory {
236229 if (!args.SerializedGUCSettings .empty ()) {
237230 GUCSettings = std::make_shared<TGUCSettings>(args.SerializedGUCSettings );
238231 }
239- IActor* computeActor = ::NKikimr::NKqp::CreateKqpComputeActor (args.ExecuterId , args.TxId , args.Task , AsyncIoFactory,
240- runtimeSettings, memoryLimits, std::move (args.TraceId ), std::move (args.Arena ), FederatedQuerySetup, GUCSettings,
232+ IActor* computeActor = NKqp::CreateKqpComputeActor (
233+ args.ExecuterId , args.TxId , args.Task , AsyncIoFactory, runtimeSettings, memoryLimits,
234+ std::move (args.TraceId ), std::move (args.Arena ),
235+ FederatedQuerySetup, GUCSettings,
241236 std::move (schedulableOptions), args.BlockTrackingMode , std::move (args.UserToken ), args.Database );
242237 return args.ShareMailbox ? TlsActivationContext->AsActorContext ().RegisterWithSameMailbox (computeActor) :
243238 TlsActivationContext->AsActorContext ().Register (computeActor);
0 commit comments