|
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; |
@@ -1352,6 +1350,7 @@ class TKqpProxyService : public TActorBootstrapped<TKqpProxyService> { |
1352 | 1350 | hFunc(TEvInterconnect::TEvNodeDisconnected, Handle); |
1353 | 1351 | hFunc(TEvKqp::TEvListSessionsRequest, Handle); |
1354 | 1352 | hFunc(TEvKqp::TEvListProxyNodesRequest, Handle); |
| 1353 | + hFunc(NWorkload::TEvUpdatePoolInfo, Handle); |
1355 | 1354 | default: |
1356 | 1355 | Y_ABORT("TKqpProxyService: unexpected event type: %" PRIx32 " event: %s", |
1357 | 1356 | ev->GetTypeRewrite(), ev->ToString().data()); |
@@ -1559,6 +1558,43 @@ class TKqpProxyService : public TActorBootstrapped<TKqpProxyService> { |
1559 | 1558 | } |
1560 | 1559 | } |
1561 | 1560 |
|
| 1561 | + bool TryGetPoolInfoFromCache(TEvKqp::TEvQueryRequest::TPtr& ev, ui64 requestId) { |
| 1562 | + if (!FeatureFlags.GetEnableResourcePools()) { |
| 1563 | + ev->Get()->SetPoolId(""); |
| 1564 | + return true; |
| 1565 | + } |
| 1566 | + |
| 1567 | + if (!ev->Get()->GetPoolId()) { |
| 1568 | + ev->Get()->SetPoolId(NResourcePool::DEFAULT_POOL_ID); |
| 1569 | + } |
| 1570 | + |
| 1571 | + const auto& poolId = ev->Get()->GetPoolId(); |
| 1572 | + const auto& poolInfo = ResourcePoolsCache.GetPoolInfo(ev->Get()->GetDatabase(), poolId); |
| 1573 | + if (!poolInfo) { |
| 1574 | + return true; |
| 1575 | + } |
| 1576 | + |
| 1577 | + const auto& securityObject = poolInfo->SecurityObject; |
| 1578 | + const auto& userToken = ev->Get()->GetUserToken(); |
| 1579 | + if (securityObject && userToken && !userToken->GetSerializedToken().empty()) { |
| 1580 | + if (!securityObject->CheckAccess(NACLib::EAccessRights::DescribeSchema, *userToken)) { |
| 1581 | + ReplyProcessError(Ydb::StatusIds::NOT_FOUND, TStringBuilder() << "Resource pool " << poolId << " not found or you don't have access permissions", requestId); |
| 1582 | + return false; |
| 1583 | + } |
| 1584 | + if (!securityObject->CheckAccess(NACLib::EAccessRights::SelectRow, *userToken)) { |
| 1585 | + ReplyProcessError(Ydb::StatusIds::UNAUTHORIZED, TStringBuilder() << "You don't have access permissions for resource pool " << poolId, requestId); |
| 1586 | + return false; |
| 1587 | + } |
| 1588 | + } |
| 1589 | + |
| 1590 | + const auto& poolConfig = poolInfo->Config; |
| 1591 | + if (poolConfig.ConcurrentQueryLimit == -1 && poolConfig.DatabaseLoadCpuThreshold < 0.0 && !poolConfig.QueryCancelAfter) { |
| 1592 | + ev->Get()->SetPoolConfig(poolConfig); |
| 1593 | + } |
| 1594 | + |
| 1595 | + return true; |
| 1596 | + } |
| 1597 | + |
1562 | 1598 | void UpdateYqlLogLevels() { |
1563 | 1599 | const auto& kqpYqlName = NKikimrServices::EServiceKikimr_Name(NKikimrServices::KQP_YQL); |
1564 | 1600 | for (auto &entry : LogConfig.GetEntry()) { |
@@ -1744,6 +1780,10 @@ class TKqpProxyService : public TActorBootstrapped<TKqpProxyService> { |
1744 | 1780 | Send(ev->Sender, result.release(), 0, ev->Cookie); |
1745 | 1781 | } |
1746 | 1782 |
|
| 1783 | + void Handle(NWorkload::TEvUpdatePoolInfo::TPtr& ev) { |
| 1784 | + ResourcePoolsCache.UpdatePoolInfo(ev->Get()->Database, ev->Get()->PoolId, ev->Get()->Config, ev->Get()->SecurityObject); |
| 1785 | + } |
| 1786 | + |
1747 | 1787 | private: |
1748 | 1788 | NKikimrConfig::TLogConfig LogConfig; |
1749 | 1789 | NKikimrConfig::TTableServiceConfig TableServiceConfig; |
@@ -1805,6 +1845,8 @@ class TKqpProxyService : public TActorBootstrapped<TKqpProxyService> { |
1805 | 1845 | std::deque<TDelayedEvent> DelayedEventsQueue; |
1806 | 1846 | bool IsLookupByRmScheduled = false; |
1807 | 1847 | TActorId KqpTempTablesAgentActor; |
| 1848 | + |
| 1849 | + TResourcePoolsCache ResourcePoolsCache; |
1808 | 1850 | }; |
1809 | 1851 |
|
1810 | 1852 | } // namespace |
|
0 commit comments