|
11 | 11 | #include <ydb/core/cms/console/console.h> |
12 | 12 | #include <ydb/core/kqp/counters/kqp_counters.h> |
13 | 13 | #include <ydb/core/kqp/common/events/script_executions.h> |
| 14 | +#include <ydb/core/kqp/common/events/workload_service.h> |
14 | 15 | #include <ydb/core/kqp/common/kqp_lwtrace_probes.h> |
15 | 16 | #include <ydb/core/kqp/common/kqp_timeouts.h> |
16 | 17 | #include <ydb/core/kqp/compile_service/kqp_compile_service.h> |
@@ -696,11 +697,8 @@ class TKqpProxyService : public TActorBootstrapped<TKqpProxyService> { |
696 | 697 | LocalSessions->AttachQueryText(sessionInfo, ev->Get()->GetQuery()); |
697 | 698 | } |
698 | 699 |
|
699 | | - if (!FeatureFlags.GetEnableResourcePools()) { |
700 | | - ev->Get()->SetPoolId(""); |
701 | | - } else if (!ev->Get()->GetPoolId()) { |
702 | | - // TODO: do not use default pool if there is no limits |
703 | | - ev->Get()->SetPoolId(NResourcePool::DEFAULT_POOL_ID); |
| 700 | + if (!TryGetPoolInfoFromCache(ev, requestId)) { |
| 701 | + return; |
704 | 702 | } |
705 | 703 |
|
706 | 704 | TActorId targetId; |
@@ -1353,6 +1351,7 @@ class TKqpProxyService : public TActorBootstrapped<TKqpProxyService> { |
1353 | 1351 | hFunc(TEvInterconnect::TEvNodeDisconnected, Handle); |
1354 | 1352 | hFunc(TEvKqp::TEvListSessionsRequest, Handle); |
1355 | 1353 | hFunc(TEvKqp::TEvListProxyNodesRequest, Handle); |
| 1354 | + hFunc(NWorkload::TEvUpdatePoolInfo, Handle); |
1356 | 1355 | default: |
1357 | 1356 | Y_ABORT("TKqpProxyService: unexpected event type: %" PRIx32 " event: %s", |
1358 | 1357 | ev->GetTypeRewrite(), ev->ToString().data()); |
@@ -1575,6 +1574,42 @@ class TKqpProxyService : public TActorBootstrapped<TKqpProxyService> { |
1575 | 1574 | } |
1576 | 1575 | } |
1577 | 1576 |
|
| 1577 | + bool TryGetPoolInfoFromCache(TEvKqp::TEvQueryRequest::TPtr& ev, ui64 requestId) { |
| 1578 | + if (!FeatureFlags.GetEnableResourcePools()) { |
| 1579 | + ev->Get()->SetPoolId(""); |
| 1580 | + return true; |
| 1581 | + } |
| 1582 | + |
| 1583 | + if (!ev->Get()->GetPoolId()) { |
| 1584 | + ev->Get()->SetPoolId(NResourcePool::DEFAULT_POOL_ID); |
| 1585 | + } |
| 1586 | + |
| 1587 | + const auto& poolId = ev->Get()->GetPoolId(); |
| 1588 | + const auto& poolInfo = ResourcePoolsCache.GetPoolInfo(ev->Get()->GetDatabase(), poolId); |
| 1589 | + if (!poolInfo) { |
| 1590 | + return true; |
| 1591 | + } |
| 1592 | + |
| 1593 | + if (const auto& securityObject = poolInfo->SecurityObject) { |
| 1594 | + const auto& userToken = ev->Get()->GetUserToken(); |
| 1595 | + if (!userToken || !securityObject->CheckAccess(NACLib::EAccessRights::DescribeSchema, *userToken)) { |
| 1596 | + ReplyProcessError(Ydb::StatusIds::NOT_FOUND, TStringBuilder() << "Resource pool " << poolId << " not found or you don't have access permissions", requestId); |
| 1597 | + return false; |
| 1598 | + } |
| 1599 | + if (!securityObject->CheckAccess(NACLib::EAccessRights::SelectRow, *userToken)) { |
| 1600 | + ReplyProcessError(Ydb::StatusIds::UNAUTHORIZED, TStringBuilder() << "You don't have access permissions for resource pool " << poolId, requestId); |
| 1601 | + return false; |
| 1602 | + } |
| 1603 | + } |
| 1604 | + |
| 1605 | + const auto& poolConfig = poolInfo->Config; |
| 1606 | + if (poolConfig.ConcurrentQueryLimit == -1 && poolConfig.DatabaseLoadCpuThreshold < 0.0 && !poolConfig.QueryCancelAfter) { |
| 1607 | + ev->Get()->SetPoolConfig(poolConfig); |
| 1608 | + } |
| 1609 | + |
| 1610 | + return true; |
| 1611 | + } |
| 1612 | + |
1578 | 1613 | void UpdateYqlLogLevels() { |
1579 | 1614 | const auto& kqpYqlName = NKikimrServices::EServiceKikimr_Name(NKikimrServices::KQP_YQL); |
1580 | 1615 | for (auto &entry : LogConfig.GetEntry()) { |
@@ -1760,6 +1795,10 @@ class TKqpProxyService : public TActorBootstrapped<TKqpProxyService> { |
1760 | 1795 | Send(ev->Sender, result.release(), 0, ev->Cookie); |
1761 | 1796 | } |
1762 | 1797 |
|
| 1798 | + void Handle(NWorkload::TEvUpdatePoolInfo::TPtr& ev) { |
| 1799 | + ResourcePoolsCache.UpdatePoolInfo(ev->Get()->Database, ev->Get()->PoolId, ev->Get()->Config, ev->Get()->SecurityObject); |
| 1800 | + } |
| 1801 | + |
1763 | 1802 | private: |
1764 | 1803 | NKikimrConfig::TLogConfig LogConfig; |
1765 | 1804 | NKikimrConfig::TTableServiceConfig TableServiceConfig; |
@@ -1821,6 +1860,8 @@ class TKqpProxyService : public TActorBootstrapped<TKqpProxyService> { |
1821 | 1860 | std::deque<TDelayedEvent> DelayedEventsQueue; |
1822 | 1861 | bool IsLookupByRmScheduled = false; |
1823 | 1862 | TActorId KqpTempTablesAgentActor; |
| 1863 | + |
| 1864 | + TResourcePoolsCache ResourcePoolsCache; |
1824 | 1865 | }; |
1825 | 1866 |
|
1826 | 1867 | } // namespace |
|
0 commit comments