diff options
author | maxkovalev <[email protected]> | 2023-02-03 13:13:02 +0300 |
---|---|---|
committer | maxkovalev <[email protected]> | 2023-02-03 13:13:02 +0300 |
commit | 75fc1cce176cb44cd825fe8f85928a2c80187e0a (patch) | |
tree | f174aaa8e407d656d6cb353b07d92695d290e295 | |
parent | f6f5837c9d0278853229cd10e24c140979ddca2e (diff) |
Move DbPool library to ydb/library
Move DbPool library to ydb/library
39 files changed, 419 insertions, 143 deletions
diff --git a/ydb/core/protos/services.proto b/ydb/core/protos/services.proto index a5b9d59c624..837a9d4e6d6 100644 --- a/ydb/core/protos/services.proto +++ b/ydb/core/protos/services.proto @@ -324,6 +324,8 @@ enum EServiceKikimr { VIEWER = 1166; + DB_POOL = 1167; + // 1024 - 1099 is reserved for nbs // Change exchange (async indexes & CDC) diff --git a/ydb/core/yq/libs/actors/proxy.h b/ydb/core/yq/libs/actors/proxy.h index da481f1b87a..09ff70aa6e3 100644 --- a/ydb/core/yq/libs/actors/proxy.h +++ b/ydb/core/yq/libs/actors/proxy.h @@ -6,7 +6,6 @@ #include <ydb/core/yq/libs/config/protos/pinger.pb.h> #include <ydb/core/yq/libs/events/events.h> #include <ydb/core/yq/libs/private_client/private_client.h> -#include <ydb/core/yq/libs/shared_resources/db_pool.h> #include <ydb/core/yq/libs/shared_resources/shared_resources.h> #include <ydb/core/yq/libs/signer/signer.h> diff --git a/ydb/core/yq/libs/actors/proxy_private.cpp b/ydb/core/yq/libs/actors/proxy_private.cpp index 7fdf4924ff4..861c60f1122 100644 --- a/ydb/core/yq/libs/actors/proxy_private.cpp +++ b/ydb/core/yq/libs/actors/proxy_private.cpp @@ -2,7 +2,6 @@ #include <ydb/core/yq/libs/config/protos/fq_config.pb.h> #include <ydb/core/yq/libs/events/events.h> -#include <ydb/core/yq/libs/shared_resources/db_pool.h> #include <library/cpp/actors/core/events.h> #include <library/cpp/actors/core/hfunc.h> diff --git a/ydb/core/yq/libs/actors/proxy_private.h b/ydb/core/yq/libs/actors/proxy_private.h index a1e6db1eae2..8f87a7ceb17 100644 --- a/ydb/core/yq/libs/actors/proxy_private.h +++ b/ydb/core/yq/libs/actors/proxy_private.h @@ -1,5 +1,6 @@ #pragma once -#include <ydb/core/yq/libs/shared_resources/db_pool.h> + +#include <ydb/core/yq/libs/config/protos/fq_config.pb.h> #include <ydb/core/yq/libs/events/events.h> #include <ydb/library/yql/minikql/computation/mkql_computation_node.h> diff --git a/ydb/core/yq/libs/control_plane_config/CMakeLists.darwin.txt b/ydb/core/yq/libs/control_plane_config/CMakeLists.darwin.txt index 7e5ec2771dc..94f7c1ddcc8 100644 --- a/ydb/core/yq/libs/control_plane_config/CMakeLists.darwin.txt +++ b/ydb/core/yq/libs/control_plane_config/CMakeLists.darwin.txt @@ -27,6 +27,7 @@ target_link_libraries(yq-libs-control_plane_config PUBLIC libs-quota_manager-events libs-rate_limiter-events yq-libs-ydb + ydb-library-db_pool ydb-library-security cpp-client-ydb_scheme cpp-client-ydb_value diff --git a/ydb/core/yq/libs/control_plane_config/CMakeLists.linux-aarch64.txt b/ydb/core/yq/libs/control_plane_config/CMakeLists.linux-aarch64.txt index 1567299bf49..e2a6f310477 100644 --- a/ydb/core/yq/libs/control_plane_config/CMakeLists.linux-aarch64.txt +++ b/ydb/core/yq/libs/control_plane_config/CMakeLists.linux-aarch64.txt @@ -28,6 +28,7 @@ target_link_libraries(yq-libs-control_plane_config PUBLIC libs-quota_manager-events libs-rate_limiter-events yq-libs-ydb + ydb-library-db_pool ydb-library-security cpp-client-ydb_scheme cpp-client-ydb_value diff --git a/ydb/core/yq/libs/control_plane_config/CMakeLists.linux.txt b/ydb/core/yq/libs/control_plane_config/CMakeLists.linux.txt index 1567299bf49..e2a6f310477 100644 --- a/ydb/core/yq/libs/control_plane_config/CMakeLists.linux.txt +++ b/ydb/core/yq/libs/control_plane_config/CMakeLists.linux.txt @@ -28,6 +28,7 @@ target_link_libraries(yq-libs-control_plane_config PUBLIC libs-quota_manager-events libs-rate_limiter-events yq-libs-ydb + ydb-library-db_pool ydb-library-security cpp-client-ydb_scheme cpp-client-ydb_value diff --git a/ydb/core/yq/libs/control_plane_config/control_plane_config.cpp b/ydb/core/yq/libs/control_plane_config/control_plane_config.cpp index 3e83245a05d..170c3a56aa6 100644 --- a/ydb/core/yq/libs/control_plane_config/control_plane_config.cpp +++ b/ydb/core/yq/libs/control_plane_config/control_plane_config.cpp @@ -21,6 +21,7 @@ #include <library/cpp/actors/core/actor.h> #include <ydb/core/base/kikimr_issue.h> +#include <ydb/library/db_pool/db_pool.h> #include <ydb/library/yql/public/issue/yql_issue_message.h> #include <ydb/library/security/util.h> #include <ydb/public/sdk/cpp/client/ydb_scheme/scheme.h> @@ -43,12 +44,13 @@ class TControlPlaneConfigActor : public NActors::TActorBootstrapped<TControlPlan ::NYq::TYqSharedResources::TPtr YqSharedResources; NKikimr::TYdbCredentialsProviderFactory CredProviderFactory; TYdbConnectionPtr YdbConnection; - TDbPool::TPtr DbPool; + NDbPool::TDbPool::TPtr DbPool; ::NMonitoring::TDynamicCounterPtr Counters; NConfig::TControlPlaneStorageConfig Config; TTenantInfo::TPtr TenantInfo; bool LoadInProgress = false; TDuration DbReloadPeriod; + TString TablePathPrefix; public: TControlPlaneConfigActor(const ::NYq::TYqSharedResources::TPtr& yqSharedResources, const NKikimr::TYdbCredentialsProviderFactory& credProviderFactory, const NConfig::TControlPlaneStorageConfig& config, const ::NMonitoring::TDynamicCounterPtr& counters) @@ -67,7 +69,8 @@ public: Become(&TControlPlaneConfigActor::StateFunc); if (Config.GetUseDbMapping()) { YdbConnection = NewYdbConnection(Config.GetStorage(), CredProviderFactory, YqSharedResources->CoreYdbDriver); - DbPool = YqSharedResources->DbPoolHolder->GetOrCreate(EDbPoolId::MAIN, 10, YdbConnection->TablePathPrefix); + DbPool = YqSharedResources->DbPoolHolder->GetOrCreate(static_cast<ui32>(EDbPoolId::MAIN), 10); + TablePathPrefix = YdbConnection->TablePathPrefix; Schedule(TDuration::Zero(), new NActors::TEvents::TEvWakeup()); } else { TenantInfo.reset(new TTenantInfo()); @@ -211,14 +214,14 @@ private: ); } - Exec(DbPool, executable); + Exec(DbPool, executable, TablePathPrefix); } LoadInProgress = false; } ); - Exec(DbPool, executable); + Exec(DbPool, executable, TablePathPrefix); } void ReflectTenantChanges(TTenantInfo::TPtr oldInfo) { diff --git a/ydb/core/yq/libs/control_plane_storage/CMakeLists.darwin.txt b/ydb/core/yq/libs/control_plane_storage/CMakeLists.darwin.txt index a0a3f4a27c6..933946e04b1 100644 --- a/ydb/core/yq/libs/control_plane_storage/CMakeLists.darwin.txt +++ b/ydb/core/yq/libs/control_plane_storage/CMakeLists.darwin.txt @@ -37,6 +37,7 @@ target_link_libraries(yq-libs-control_plane_storage PUBLIC api-protos cpp-client-ydb_scheme cpp-client-ydb_table + ydb-library-db_pool providers-s3-path_generator yql-public-issue ) diff --git a/ydb/core/yq/libs/control_plane_storage/CMakeLists.linux-aarch64.txt b/ydb/core/yq/libs/control_plane_storage/CMakeLists.linux-aarch64.txt index d62369ae178..6e4bcea5019 100644 --- a/ydb/core/yq/libs/control_plane_storage/CMakeLists.linux-aarch64.txt +++ b/ydb/core/yq/libs/control_plane_storage/CMakeLists.linux-aarch64.txt @@ -38,6 +38,7 @@ target_link_libraries(yq-libs-control_plane_storage PUBLIC api-protos cpp-client-ydb_scheme cpp-client-ydb_table + ydb-library-db_pool providers-s3-path_generator yql-public-issue ) diff --git a/ydb/core/yq/libs/control_plane_storage/CMakeLists.linux.txt b/ydb/core/yq/libs/control_plane_storage/CMakeLists.linux.txt index d62369ae178..6e4bcea5019 100644 --- a/ydb/core/yq/libs/control_plane_storage/CMakeLists.linux.txt +++ b/ydb/core/yq/libs/control_plane_storage/CMakeLists.linux.txt @@ -38,6 +38,7 @@ target_link_libraries(yq-libs-control_plane_storage PUBLIC api-protos cpp-client-ydb_scheme cpp-client-ydb_table + ydb-library-db_pool providers-s3-path_generator yql-public-issue ) diff --git a/ydb/core/yq/libs/control_plane_storage/ydb_control_plane_storage.cpp b/ydb/core/yq/libs/control_plane_storage/ydb_control_plane_storage.cpp index 6bc04c7a939..6cc1856deb4 100644 --- a/ydb/core/yq/libs/control_plane_storage/ydb_control_plane_storage.cpp +++ b/ydb/core/yq/libs/control_plane_storage/ydb_control_plane_storage.cpp @@ -3,7 +3,7 @@ #include "ydb_control_plane_storage_impl.h" #include <ydb/core/yq/libs/ydb/schema.h> -#include <ydb/core/yq/libs/shared_resources/db_pool.h> +#include <ydb/library/db_pool/db_pool.h> #include <ydb/library/security/ydb_credentials_provider_factory.h> @@ -37,7 +37,8 @@ void TYdbControlPlaneStorageActor::Bootstrap() { NLwTraceMonPage::ProbeRegistry().AddProbesList(LWTRACE_GET_PROBES(YQ_CONTROL_PLANE_STORAGE_PROVIDER)); YdbConnection = NewYdbConnection(Config->Proto.GetStorage(), CredProviderFactory, YqSharedResources->CoreYdbDriver); - DbPool = YqSharedResources->DbPoolHolder->GetOrCreate(EDbPoolId::MAIN, 10, YdbConnection->TablePathPrefix); + DbPool = YqSharedResources->DbPoolHolder->GetOrCreate(static_cast<ui32>(EDbPoolId::MAIN), 10); + TablePathPrefix = YdbConnection->TablePathPrefix; CreateDirectory(); CreateQueriesTable(); diff --git a/ydb/core/yq/libs/control_plane_storage/ydb_control_plane_storage_impl.h b/ydb/core/yq/libs/control_plane_storage/ydb_control_plane_storage_impl.h index 72a3c97a295..0953b56f2c1 100644 --- a/ydb/core/yq/libs/control_plane_storage/ydb_control_plane_storage_impl.h +++ b/ydb/core/yq/libs/control_plane_storage/ydb_control_plane_storage_impl.h @@ -21,6 +21,7 @@ #include <ydb/public/api/protos/yq.pb.h> #include <ydb/public/sdk/cpp/client/ydb_scheme/scheme.h> +#include <ydb/library/db_pool/db_pool.h> #include <ydb/library/security/util.h> #include <ydb/core/base/appdata.h> @@ -45,6 +46,7 @@ namespace NYq { using namespace NActors; using namespace NConfig; +using namespace NDbPool; using namespace NKikimr; using namespace NThreading; using namespace NYdb; @@ -563,6 +565,8 @@ class TYdbControlPlaneStorageActor : public NActors::TActorBootstrapped<TYdbCont TInstant QuotasUpdatedAt = TInstant::Zero(); bool QuotasUpdating = false; + TString TablePathPrefix; + public: TYdbControlPlaneStorageActor( const NConfig::TControlPlaneStorageConfig& config, diff --git a/ydb/core/yq/libs/control_plane_storage/ydb_control_plane_storage_quotas.cpp b/ydb/core/yq/libs/control_plane_storage/ydb_control_plane_storage_quotas.cpp index dac6db39fef..6206a97d67a 100644 --- a/ydb/core/yq/libs/control_plane_storage/ydb_control_plane_storage_quotas.cpp +++ b/ydb/core/yq/libs/control_plane_storage/ydb_control_plane_storage_quotas.cpp @@ -95,7 +95,7 @@ void TYdbControlPlaneStorageActor::Handle(TEvQuotaService::TQuotaUsageRequest::T } ); - Exec(DbPool, executable); + Exec(DbPool, executable, TablePathPrefix); } void TYdbControlPlaneStorageActor::Handle(TEvQuotaService::TQuotaLimitChangeRequest::TPtr& ev) { diff --git a/ydb/core/yq/libs/events/event_ids.h b/ydb/core/yq/libs/events/event_ids.h index 7a6755db25c..3a9ca8db602 100644 --- a/ydb/core/yq/libs/events/event_ids.h +++ b/ydb/core/yq/libs/events/event_ids.h @@ -30,10 +30,6 @@ struct TEventIds { // Internal events EvAsyncContinue, - EvDbRequest, - EvDbResponse, - EvDbFunctionRequest, - EvDbFunctionResponse, EvEndpointRequest, EvEndpointResponse, EvDataStreamsReadRulesCreationResult, diff --git a/ydb/core/yq/libs/events/events.h b/ydb/core/yq/libs/events/events.h index 10ace97f109..dfe21235d55 100644 --- a/ydb/core/yq/libs/events/events.h +++ b/ydb/core/yq/libs/events/events.h @@ -104,45 +104,6 @@ struct TEvents { {} }; - struct TEvDbRequest : NActors::TEventLocal<TEvDbRequest, TEventIds::EvDbRequest> { - TString Sql; - NYdb::TParams Params; - bool Idempotent; - - TEvDbRequest(const TString& sql, NYdb::TParams&& params, bool idempotent = true) - : Sql(sql) - , Params(std::move(params)) - , Idempotent(idempotent) - {} - }; - - struct TEvDbResponse : NActors::TEventLocal<TEvDbResponse, TEventIds::EvDbResponse> { - NYdb::TStatus Status; - TVector<NYdb::TResultSet> ResultSets; - - TEvDbResponse(NYdb::TStatus status, const TVector<NYdb::TResultSet>& resultSets) - : Status(status) - , ResultSets(resultSets) - {} - }; - - struct TEvDbFunctionRequest : NActors::TEventLocal<TEvDbFunctionRequest, TEventIds::EvDbFunctionRequest> { - using TFunction = std::function<NYdb::TAsyncStatus(NYdb::NTable::TSession&)>; - TFunction Handler; - - explicit TEvDbFunctionRequest(const TFunction& handler) - : Handler(handler) - {} - }; - - struct TEvDbFunctionResponse : NActors::TEventLocal<TEvDbFunctionResponse, TEventIds::EvDbFunctionResponse> { - NYdb::TStatus Status; - - explicit TEvDbFunctionResponse(NYdb::TStatus status) - : Status(status) - {} - }; - struct TEvEndpointResponse : NActors::TEventLocal<TEvEndpointResponse, TEventIds::EvEndpointResponse> { NYql::TDbResolverResponse DbResolverResponse; explicit TEvEndpointResponse(NYql::TDbResolverResponse&& response) noexcept : DbResolverResponse(std::move(response)) {} diff --git a/ydb/core/yq/libs/quota_manager/quota_manager.cpp b/ydb/core/yq/libs/quota_manager/quota_manager.cpp index 7f6f5898634..5c3b3d665c1 100644 --- a/ydb/core/yq/libs/quota_manager/quota_manager.cpp +++ b/ydb/core/yq/libs/quota_manager/quota_manager.cpp @@ -188,7 +188,8 @@ public: } YdbConnection = NewYdbConnection(StorageConfig, CredProviderFactory, YqSharedResources->CoreYdbDriver); - DbPool = YqSharedResources->DbPoolHolder->GetOrCreate(EDbPoolId::MAIN, 10, YdbConnection->TablePathPrefix); + TablePathPrefix = YdbConnection->TablePathPrefix; + DbPool = YqSharedResources->DbPoolHolder->GetOrCreate(static_cast<ui32>(EDbPoolId::MAIN), 10); Send(NActors::GetNameserviceActorId(), new NActors::TEvInterconnect::TEvListNodes()); Become(&TQuotaManagementService::StateFunc); LOG_I("STARTED"); @@ -471,7 +472,7 @@ private: } ); - Exec(DbPool, executable); + Exec(DbPool, executable, TablePathPrefix); } void SendQuota(NActors::TActorId receivedId, ui64 cookie, const TString& subjectType, const TString& subjectId, TQuotaCache& cache) { @@ -632,7 +633,7 @@ private: } ); - Exec(DbPool, executable); + Exec(DbPool, executable, TablePathPrefix); } void UpdateQuota(const TString& subjectType, const TString& subjectId, const TString& metricName, TQuotaUsage& usage) { @@ -836,7 +837,7 @@ private: ::NYq::TYqSharedResources::TPtr YqSharedResources; NKikimr::TYdbCredentialsProviderFactory CredProviderFactory; TYdbConnectionPtr YdbConnection; - TDbPool::TPtr DbPool; + NDbPool::TDbPool::TPtr DbPool; const ::NMonitoring::TDynamicCounterPtr ServiceCounters; THashMap<TString /* SubjectType */, THashMap<TString /* MetricName */, TQuotaInfo>> QuotaInfoMap; THashMap<TString /* SubjectType */, THashMap<TString /* SubjectId */, TQuotaCache>> QuotaCacheMap; @@ -845,6 +846,7 @@ private: std::vector<ui32> NodeIds; NActors::TMon* Monitoring; NActors::TActorId HttpMonId; + TString TablePathPrefix; }; NActors::IActor* CreateQuotaServiceActor( diff --git a/ydb/core/yq/libs/shared_resources/CMakeLists.darwin.txt b/ydb/core/yq/libs/shared_resources/CMakeLists.darwin.txt index b2fbbe52e44..a4e86e30e0e 100644 --- a/ydb/core/yq/libs/shared_resources/CMakeLists.darwin.txt +++ b/ydb/core/yq/libs/shared_resources/CMakeLists.darwin.txt @@ -26,6 +26,7 @@ target_link_libraries(yq-libs-shared_resources PUBLIC yq-libs-exceptions libs-quota_manager-events libs-shared_resources-interface + ydb-library-db_pool ydb-library-logger ydb-library-security cpp-client-ydb_driver @@ -33,6 +34,5 @@ target_link_libraries(yq-libs-shared_resources PUBLIC ) target_sources(yq-libs-shared_resources PRIVATE ${CMAKE_SOURCE_DIR}/ydb/core/yq/libs/shared_resources/db_exec.cpp - ${CMAKE_SOURCE_DIR}/ydb/core/yq/libs/shared_resources/db_pool.cpp ${CMAKE_SOURCE_DIR}/ydb/core/yq/libs/shared_resources/shared_resources.cpp ) diff --git a/ydb/core/yq/libs/shared_resources/CMakeLists.linux-aarch64.txt b/ydb/core/yq/libs/shared_resources/CMakeLists.linux-aarch64.txt index 191d8418b29..005c55de979 100644 --- a/ydb/core/yq/libs/shared_resources/CMakeLists.linux-aarch64.txt +++ b/ydb/core/yq/libs/shared_resources/CMakeLists.linux-aarch64.txt @@ -27,6 +27,7 @@ target_link_libraries(yq-libs-shared_resources PUBLIC yq-libs-exceptions libs-quota_manager-events libs-shared_resources-interface + ydb-library-db_pool ydb-library-logger ydb-library-security cpp-client-ydb_driver @@ -34,6 +35,5 @@ target_link_libraries(yq-libs-shared_resources PUBLIC ) target_sources(yq-libs-shared_resources PRIVATE ${CMAKE_SOURCE_DIR}/ydb/core/yq/libs/shared_resources/db_exec.cpp - ${CMAKE_SOURCE_DIR}/ydb/core/yq/libs/shared_resources/db_pool.cpp ${CMAKE_SOURCE_DIR}/ydb/core/yq/libs/shared_resources/shared_resources.cpp ) diff --git a/ydb/core/yq/libs/shared_resources/CMakeLists.linux.txt b/ydb/core/yq/libs/shared_resources/CMakeLists.linux.txt index 191d8418b29..005c55de979 100644 --- a/ydb/core/yq/libs/shared_resources/CMakeLists.linux.txt +++ b/ydb/core/yq/libs/shared_resources/CMakeLists.linux.txt @@ -27,6 +27,7 @@ target_link_libraries(yq-libs-shared_resources PUBLIC yq-libs-exceptions libs-quota_manager-events libs-shared_resources-interface + ydb-library-db_pool ydb-library-logger ydb-library-security cpp-client-ydb_driver @@ -34,6 +35,5 @@ target_link_libraries(yq-libs-shared_resources PUBLIC ) target_sources(yq-libs-shared_resources PRIVATE ${CMAKE_SOURCE_DIR}/ydb/core/yq/libs/shared_resources/db_exec.cpp - ${CMAKE_SOURCE_DIR}/ydb/core/yq/libs/shared_resources/db_pool.cpp ${CMAKE_SOURCE_DIR}/ydb/core/yq/libs/shared_resources/shared_resources.cpp ) diff --git a/ydb/core/yq/libs/shared_resources/db_exec.h b/ydb/core/yq/libs/shared_resources/db_exec.h index 53caecc4531..19600ecd46c 100644 --- a/ydb/core/yq/libs/shared_resources/db_exec.h +++ b/ydb/core/yq/libs/shared_resources/db_exec.h @@ -1,9 +1,10 @@ #pragma once -#include "db_pool.h" +#include <ydb/library/db_pool/db_pool.h> #include <ydb/core/yq/libs/common/debug_info.h> #include <ydb/core/yq/libs/config/yq_issue.h> +#include <ydb/core/yq/libs/events/events.h> #include <ydb/core/yq/libs/exceptions/exceptions.h> #include <ydb/core/yq/libs/db_schema/db_schema.h> @@ -26,11 +27,12 @@ public: virtual TAsyncStatus Execute(NYdb::NTable::TSession& session) = 0; void Throw(const TString& message); - TDbPool::TPtr DbPool; + NDbPool::TDbPool::TPtr DbPool; std::weak_ptr<TDbExecutable> SelfHolder; NYql::TIssues Issues; NYql::TIssues InternalIssues; TDebugInfoPtr DebugInfo; + TString TablePathPrefix; }; template <typename TProto> @@ -41,9 +43,11 @@ void ParseProto(TDbExecutable& executable, TProto& proto, TResultSetParser& pars } } -inline TAsyncStatus Exec(TDbPool::TPtr dbPool, TDbExecutable::TPtr executable) { +inline TAsyncStatus Exec(NDbPool::TDbPool::TPtr dbPool, TDbExecutable::TPtr executable, + const TString& tablePathPrefix) { executable->DbPool = dbPool; executable->SelfHolder = executable; + executable->TablePathPrefix = tablePathPrefix; return ExecDbRequest(dbPool, [=](NYdb::NTable::TSession& session) { return executable->Execute(session); }); @@ -159,7 +163,7 @@ public: } return MakeFuture(TStatus{EStatus::SUCCESS, NYql::TIssues{}}); } else { - TSqlQueryBuilder builder(DbPool->TablePathPrefix, Steps[CurrentStepIndex].Name); + TSqlQueryBuilder builder(TablePathPrefix, Steps[CurrentStepIndex].Name); SkipStep_ = false; Steps[CurrentStepIndex].BuildCallback(*this, builder); diff --git a/ydb/core/yq/libs/shared_resources/interface/shared_resources.h b/ydb/core/yq/libs/shared_resources/interface/shared_resources.h index 485c0d89562..b7b56d68860 100644 --- a/ydb/core/yq/libs/shared_resources/interface/shared_resources.h +++ b/ydb/core/yq/libs/shared_resources/interface/shared_resources.h @@ -14,4 +14,8 @@ struct IYqSharedResources : public TThrRefBase { virtual void Stop() = 0; }; +enum class EDbPoolId { + MAIN = 0 +}; + } // NYq diff --git a/ydb/core/yq/libs/shared_resources/shared_resources.cpp b/ydb/core/yq/libs/shared_resources/shared_resources.cpp index fe96bb3aba3..4ab3cbd379d 100644 --- a/ydb/core/yq/libs/shared_resources/shared_resources.cpp +++ b/ydb/core/yq/libs/shared_resources/shared_resources.cpp @@ -32,7 +32,20 @@ struct TYqSharedResourcesImpl : public TActorSystemPtrMixin, public TYqSharedRes const ::NMonitoring::TDynamicCounterPtr& counters) : TYqSharedResources(NYdb::TDriver(GetYdbDriverConfig(config.GetCommon().GetYdbDriverConfig()))) { - CreateDbPoolHolder(config.GetDbPool(), credentialsProviderFactory, counters); + CreateDbPoolHolder(PrepareDbPoolConfig(config), credentialsProviderFactory, counters); + } + + NDbPool::TConfig PrepareDbPoolConfig(const NYq::NConfig::TConfig& config) { + NDbPool::TConfig dbPoolConfig; + const auto& storageConfig = config.GetDbPool().GetStorage(); + dbPoolConfig.SetMaxSessionCount(config.GetDbPool().GetMaxSessionCount()); + dbPoolConfig.SetEndpoint(storageConfig.GetEndpoint()); + dbPoolConfig.SetDatabase(storageConfig.GetDatabase()); + dbPoolConfig.SetOAuthFile(storageConfig.GetOAuthFile()); + dbPoolConfig.SetUseLocalMetadataService(storageConfig.GetUseLocalMetadataService()); + dbPoolConfig.SetUseSsl(storageConfig.GetUseSsl()); + dbPoolConfig.SetToken(storageConfig.GetToken()); + return dbPoolConfig; } void Init(NActors::TActorSystem* actorSystem) override { @@ -62,10 +75,10 @@ struct TYqSharedResourcesImpl : public TActorSystemPtrMixin, public TYqSharedRes } void CreateDbPoolHolder( - const NYq::NConfig::TDbPoolConfig& config, + const NDbPool::TConfig& config, const NKikimr::TYdbCredentialsProviderFactory& credentialsProviderFactory, const ::NMonitoring::TDynamicCounterPtr& counters) { - DbPoolHolder = MakeIntrusive<NYq::TDbPoolHolder>(config, CoreYdbDriver, credentialsProviderFactory, counters); + DbPoolHolder = MakeIntrusive<NDbPool::TDbPoolHolder>(config, CoreYdbDriver, credentialsProviderFactory, counters); } }; diff --git a/ydb/core/yq/libs/shared_resources/shared_resources.h b/ydb/core/yq/libs/shared_resources/shared_resources.h index f1c2b5efb6f..5fccbf2afaf 100644 --- a/ydb/core/yq/libs/shared_resources/shared_resources.h +++ b/ydb/core/yq/libs/shared_resources/shared_resources.h @@ -1,5 +1,5 @@ #pragma once -#include "db_pool.h" +#include <ydb/library/db_pool/db_pool.h> #include <ydb/public/sdk/cpp/client/ydb_driver/driver.h> #include <ydb/core/yq/libs/config/protos/fq_config.pb.h> @@ -21,7 +21,7 @@ struct TYqSharedResources : public IYqSharedResources { // For now they are actually point to the same driver, but it can be changed in the future. NYdb::TDriver CoreYdbDriver; NYdb::TDriver UserSpaceYdbDriver; - TDbPoolHolder::TPtr DbPoolHolder; + NDbPool::TDbPoolHolder::TPtr DbPoolHolder; protected: explicit TYqSharedResources(NYdb::TDriver driver); diff --git a/ydb/core/yq/libs/test_connection/test_connection.h b/ydb/core/yq/libs/test_connection/test_connection.h index c11e9ccdd49..e611489f289 100644 --- a/ydb/core/yq/libs/test_connection/test_connection.h +++ b/ydb/core/yq/libs/test_connection/test_connection.h @@ -4,6 +4,7 @@ #include <ydb/core/yq/libs/actors/logging/log.h> #include <ydb/core/yq/libs/config/protos/test_connection.pb.h> +#include <ydb/core/yq/libs/db_id_async_resolver_impl/db_async_resolver_impl.h> #include <ydb/core/yq/libs/shared_resources/shared_resources.h> #include <ydb/core/yq/libs/signer/signer.h> #include <ydb/library/yql/providers/common/token_accessor/client/factory.h> diff --git a/ydb/library/CMakeLists.txt b/ydb/library/CMakeLists.txt index 90ce1c49cd1..da36a78e0b0 100644 --- a/ydb/library/CMakeLists.txt +++ b/ydb/library/CMakeLists.txt @@ -12,6 +12,7 @@ add_subdirectory(arrow_clickhouse) add_subdirectory(arrow_kernels) add_subdirectory(backup) add_subdirectory(binary_json) +add_subdirectory(db_pool) add_subdirectory(dynumber) add_subdirectory(folder_service) add_subdirectory(http_proxy) diff --git a/ydb/library/db_pool/CMakeLists.darwin.txt b/ydb/library/db_pool/CMakeLists.darwin.txt new file mode 100644 index 00000000000..6de7fc97e73 --- /dev/null +++ b/ydb/library/db_pool/CMakeLists.darwin.txt @@ -0,0 +1,25 @@ + +# This file was generated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + +add_subdirectory(protos) + +add_library(ydb-library-db_pool) +target_link_libraries(ydb-library-db_pool PUBLIC + contrib-libs-cxxsupp + yutil + cpp-actors-core + cpp-monlib-dynamic_counters + ydb-core-protos + library-db_pool-protos + ydb-library-security + cpp-client-ydb_driver + cpp-client-ydb_table +) +target_sources(ydb-library-db_pool PRIVATE + ${CMAKE_SOURCE_DIR}/ydb/library/db_pool/db_pool.cpp +) diff --git a/ydb/library/db_pool/CMakeLists.linux-aarch64.txt b/ydb/library/db_pool/CMakeLists.linux-aarch64.txt new file mode 100644 index 00000000000..596c5913b10 --- /dev/null +++ b/ydb/library/db_pool/CMakeLists.linux-aarch64.txt @@ -0,0 +1,26 @@ + +# This file was generated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + +add_subdirectory(protos) + +add_library(ydb-library-db_pool) +target_link_libraries(ydb-library-db_pool PUBLIC + contrib-libs-linux-headers + contrib-libs-cxxsupp + yutil + cpp-actors-core + cpp-monlib-dynamic_counters + ydb-core-protos + library-db_pool-protos + ydb-library-security + cpp-client-ydb_driver + cpp-client-ydb_table +) +target_sources(ydb-library-db_pool PRIVATE + ${CMAKE_SOURCE_DIR}/ydb/library/db_pool/db_pool.cpp +) diff --git a/ydb/library/db_pool/CMakeLists.linux.txt b/ydb/library/db_pool/CMakeLists.linux.txt new file mode 100644 index 00000000000..596c5913b10 --- /dev/null +++ b/ydb/library/db_pool/CMakeLists.linux.txt @@ -0,0 +1,26 @@ + +# This file was generated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + +add_subdirectory(protos) + +add_library(ydb-library-db_pool) +target_link_libraries(ydb-library-db_pool PUBLIC + contrib-libs-linux-headers + contrib-libs-cxxsupp + yutil + cpp-actors-core + cpp-monlib-dynamic_counters + ydb-core-protos + library-db_pool-protos + ydb-library-security + cpp-client-ydb_driver + cpp-client-ydb_table +) +target_sources(ydb-library-db_pool PRIVATE + ${CMAKE_SOURCE_DIR}/ydb/library/db_pool/db_pool.cpp +) diff --git a/ydb/library/db_pool/CMakeLists.txt b/ydb/library/db_pool/CMakeLists.txt new file mode 100644 index 00000000000..5bb4faffb40 --- /dev/null +++ b/ydb/library/db_pool/CMakeLists.txt @@ -0,0 +1,15 @@ + +# This file was generated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + +if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" AND UNIX AND NOT APPLE AND NOT ANDROID) + include(CMakeLists.linux-aarch64.txt) +elseif (APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") + include(CMakeLists.darwin.txt) +elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND UNIX AND NOT APPLE AND NOT ANDROID) + include(CMakeLists.linux.txt) +endif() diff --git a/ydb/core/yq/libs/shared_resources/db_pool.cpp b/ydb/library/db_pool/db_pool.cpp index 2d6ded1a285..8e1c7e22cd4 100644 --- a/ydb/core/yq/libs/shared_resources/db_pool.cpp +++ b/ydb/library/db_pool/db_pool.cpp @@ -1,37 +1,15 @@ #include "db_pool.h" - -#include <ydb/core/protos/services.pb.h> +#include "log.h" #include <library/cpp/actors/core/events.h> #include <library/cpp/actors/core/hfunc.h> #include <library/cpp/actors/core/actor_bootstrapped.h> -#include <ydb/core/yq/libs/actors/logging/log.h> - #include <util/stream/file.h> #include <util/string/strip.h> -#define LOG_F_AS(actorSystem, logRecordStream) LOG_STREAMS_IMPL_AS(*actorSystem, EMERG, STREAMS, logRecordStream) -#define LOG_A_AS(actorSystem, logRecordStream) LOG_STREAMS_IMPL_AS(*actorSystem, ALERT, STREAMS, logRecordStream) -#define LOG_C_AS(actorSystem, logRecordStream) LOG_STREAMS_IMPL_AS(*actorSystem, CRIT, STREAMS, logRecordStream) -#define LOG_E_AS(actorSystem, logRecordStream) LOG_STREAMS_IMPL_AS(*actorSystem, ERROR, STREAMS, logRecordStream) -#define LOG_W_AS(actorSystem, logRecordStream) LOG_STREAMS_IMPL_AS(*actorSystem, WARN, STREAMS, logRecordStream) -#define LOG_N_AS(actorSystem, logRecordStream) LOG_STREAMS_IMPL_AS(*actorSystem, NOTICE, STREAMS, logRecordStream) -#define LOG_I_AS(actorSystem, logRecordStream) LOG_STREAMS_IMPL_AS(*actorSystem, INFO, STREAMS, logRecordStream) -#define LOG_D_AS(actorSystem, logRecordStream) LOG_STREAMS_IMPL_AS(*actorSystem, DEBUG, STREAMS, logRecordStream) -#define LOG_T_AS(actorSystem, logRecordStream) LOG_STREAMS_IMPL_AS(*actorSystem, TRACE, STREAMS, logRecordStream) - -#define LOG_F(logRecordStream) LOG_F_AS(::NActors::TActivationContext::ActorSystem(), logRecordStream) -#define LOG_A(logRecordStream) LOG_A_AS(::NActors::TActivationContext::ActorSystem(), logRecordStream) -#define LOG_C(logRecordStream) LOG_C_AS(::NActors::TActivationContext::ActorSystem(), logRecordStream) -#define LOG_E(logRecordStream) LOG_E_AS(::NActors::TActivationContext::ActorSystem(), logRecordStream) -#define LOG_W(logRecordStream) LOG_W_AS(::NActors::TActivationContext::ActorSystem(), logRecordStream) -#define LOG_N(logRecordStream) LOG_N_AS(::NActors::TActivationContext::ActorSystem(), logRecordStream) -#define LOG_I(logRecordStream) LOG_I_AS(::NActors::TActivationContext::ActorSystem(), logRecordStream) -#define LOG_D(logRecordStream) LOG_D_AS(::NActors::TActivationContext::ActorSystem(), logRecordStream) -#define LOG_T(logRecordStream) LOG_T_AS(::NActors::TActivationContext::ActorSystem(), logRecordStream) - -namespace NYq { + +namespace NDbPool { using namespace NActors; using namespace NYql; @@ -206,10 +184,8 @@ private: TDbPool::TDbPool( ui32 sessionsCount, const NYdb::NTable::TTableClient& tableClient, - const ::NMonitoring::TDynamicCounterPtr& counters, - const TString& tablePathPrefix) + const ::NMonitoring::TDynamicCounterPtr& counters) { - TablePathPrefix = tablePathPrefix; const auto& ctx = NActors::TActivationContext::AsActorContext(); auto parentId = ctx.SelfID; Actors.reserve(sessionsCount); @@ -238,9 +214,9 @@ TActorId TDbPool::GetNextActor() { return Actors[Index++]; } -static void PrepareConfig(NYq::NConfig::TDbPoolConfig& config) { - if (!config.GetStorage().GetToken() && config.GetStorage().GetOAuthFile()) { - config.MutableStorage()->SetToken(StripString(TFileInput(config.GetStorage().GetOAuthFile()).ReadAll())); +static void PrepareConfig(NDbPool::TConfig& config) { + if (!config.GetToken() && config.GetOAuthFile()) { + config.SetToken(StripString(TFileInput(config.GetOAuthFile()).ReadAll())); } if (!config.GetMaxSessionCount()) { @@ -249,7 +225,7 @@ static void PrepareConfig(NYq::NConfig::TDbPoolConfig& config) { } TDbPoolMap::TDbPoolMap( - const NYq::NConfig::TDbPoolConfig& config, + const NDbPool::TConfig& config, NYdb::TDriver driver, const NKikimr::TYdbCredentialsProviderFactory& credentialsProviderFactory, const ::NMonitoring::TDynamicCounterPtr& counters) @@ -262,7 +238,7 @@ TDbPoolMap::TDbPoolMap( } TDbPoolHolder::TDbPoolHolder( - const NYq::NConfig::TDbPoolConfig& config, + const NDbPool::TConfig& config, const NYdb::TDriver& driver, const NKikimr::TYdbCredentialsProviderFactory& credentialsProviderFactory, const ::NMonitoring::TDynamicCounterPtr& counters) @@ -275,7 +251,7 @@ TDbPoolHolder::~TDbPoolHolder() Driver.Stop(true); } -void TDbPoolHolder::Reset(const NYq::NConfig::TDbPoolConfig& config) { +void TDbPoolHolder::Reset(const NDbPool::TConfig& config) { Pools->Reset(config); } @@ -283,7 +259,7 @@ TDbPoolMap::TPtr TDbPoolHolder::Get() { return Pools; } -void TDbPoolMap::Reset(const NYq::NConfig::TDbPoolConfig& config) { +void TDbPoolMap::Reset(const NDbPool::TConfig& config) { TGuard<TMutex> lock(Mutex); Config = config; PrepareConfig(Config); @@ -291,18 +267,18 @@ void TDbPoolMap::Reset(const NYq::NConfig::TDbPoolConfig& config) { TableClient = nullptr; } -TDbPool::TPtr TDbPoolHolder::GetOrCreate(EDbPoolId dbPoolId, ui32 sessionsCount, const TString& tablePathPrefix) { - return Pools->GetOrCreate(dbPoolId, sessionsCount, tablePathPrefix); +TDbPool::TPtr TDbPoolHolder::GetOrCreate(ui32 dbPoolId, ui32 sessionsCount) { + return Pools->GetOrCreate(dbPoolId, sessionsCount); } -TDbPool::TPtr TDbPoolMap::GetOrCreate(EDbPoolId dbPoolId, ui32 sessionsCount, const TString& tablePathPrefix) { +TDbPool::TPtr TDbPoolMap::GetOrCreate(ui32 dbPoolId, ui32 sessionsCount) { TGuard<TMutex> lock(Mutex); auto it = Pools.find(dbPoolId); if (it != Pools.end()) { return it->second; } - if (!Config.GetStorage().GetEndpoint()) { + if (!Config.GetEndpoint()) { return nullptr; } @@ -310,21 +286,21 @@ TDbPool::TPtr TDbPoolMap::GetOrCreate(EDbPoolId dbPoolId, ui32 sessionsCount, co auto clientSettings = NYdb::NTable::TClientSettings() .UseQueryCache(false) .SessionPoolSettings(NYdb::NTable::TSessionPoolSettings().MaxActiveSessions(1 + Config.GetMaxSessionCount())) - .Database(Config.GetStorage().GetDatabase()) - .DiscoveryEndpoint(Config.GetStorage().GetEndpoint()) + .Database(Config.GetDatabase()) + .DiscoveryEndpoint(Config.GetEndpoint()) .DiscoveryMode(NYdb::EDiscoveryMode::Async); NKikimr::TYdbCredentialsSettings credSettings; - credSettings.UseLocalMetadata = Config.GetStorage().GetUseLocalMetadataService(); - credSettings.OAuthToken = Config.GetStorage().GetToken(); + credSettings.UseLocalMetadata = Config.GetUseLocalMetadataService(); + credSettings.OAuthToken = Config.GetToken(); clientSettings.CredentialsProviderFactory(CredentialsProviderFactory(credSettings)); - clientSettings.SslCredentials(NYdb::TSslCredentials(Config.GetStorage().GetUseSsl())); + clientSettings.SslCredentials(NYdb::TSslCredentials(Config.GetUseSsl())); TableClient = MakeHolder<NYdb::NTable::TTableClient>(Driver, clientSettings); } - TDbPool::TPtr dbPool = new TDbPool(sessionsCount, *TableClient, Counters, tablePathPrefix); + TDbPool::TPtr dbPool = new TDbPool(sessionsCount, *TableClient, Counters); Pools.emplace(dbPoolId, dbPool); return dbPool; } @@ -333,6 +309,12 @@ NYdb::TDriver& TDbPoolHolder::GetDriver() { return Driver; } +NYdb::TAsyncStatus ExecDbRequest(TDbPool::TPtr dbPool, std::function<NYdb::TAsyncStatus(NYdb::NTable::TSession&)> handler) { + NThreading::TPromise<NYdb::TStatus> promise = NThreading::NewPromise<NYdb::TStatus>(); + TActivationContext::Register(new TDbRequest(dbPool, promise, handler)); + return promise.GetFuture(); +} + TDbRequest::TDbRequest(const TDbPool::TPtr& dbPool, const NThreading::TPromise<NYdb::TStatus>& promise, const TFunction& handler) : DbPool(dbPool) , Promise(promise) @@ -356,10 +338,4 @@ void TDbRequest::OnUndelivered(NActors::TEvents::TEvUndelivered::TPtr&) { Send(DbPool->GetNextActor(), new TEvents::TEvDbFunctionRequest(Handler), IEventHandle::FlagTrackDelivery); } -NYdb::TAsyncStatus ExecDbRequest(TDbPool::TPtr dbPool, std::function<NYdb::TAsyncStatus(NYdb::NTable::TSession&)> handler) { - NThreading::TPromise<NYdb::TStatus> promise = NThreading::NewPromise<NYdb::TStatus>(); - TActivationContext::Register(new TDbRequest(dbPool, promise, handler)); - return promise.GetFuture(); -} - -} /* namespace NYq */ +} // namespace NDbPool
\ No newline at end of file diff --git a/ydb/core/yq/libs/shared_resources/db_pool.h b/ydb/library/db_pool/db_pool.h index 51bde518e28..c321f5a400c 100644 --- a/ydb/core/yq/libs/shared_resources/db_pool.h +++ b/ydb/library/db_pool/db_pool.h @@ -1,9 +1,10 @@ #pragma once -#include <ydb/core/yq/libs/config/protos/fq_config.pb.h> +#include "events.h" + #include <ydb/public/sdk/cpp/client/ydb_table/table.h> -#include <ydb/core/yq/libs/events/events.h> +#include <ydb/library/db_pool/protos/config.pb.h> #include <ydb/library/security/ydb_credentials_provider_factory.h> #include <library/cpp/actors/core/actor.h> @@ -13,7 +14,7 @@ #include <util/system/mutex.h> -namespace NYq { +namespace NDbPool { class TDbPool: public TThrRefBase { public: @@ -23,12 +24,10 @@ public: NActors::TActorId GetNextActor(); - TString TablePathPrefix; - private: friend class TDbPoolMap; - TDbPool(ui32 sessionsCount, const NYdb::NTable::TTableClient& tableClient, const ::NMonitoring::TDynamicCounterPtr& counters, const TString& tablePathPrefix); + TDbPool(ui32 sessionsCount, const NYdb::NTable::TTableClient& tableClient, const ::NMonitoring::TDynamicCounterPtr& counters); TMutex Mutex; TVector<NActors::TActorId> Actors; @@ -36,48 +35,47 @@ private: const ::NMonitoring::TDynamicCounterPtr Counters; }; -enum class EDbPoolId { - MAIN = 0, - REFRESH = 1 -}; - class TDbPoolMap: public TThrRefBase { public: using TPtr = TIntrusivePtr<TDbPoolMap>; - TDbPool::TPtr GetOrCreate(EDbPoolId poolId, ui32 sessionsCount, const TString& tablePathPrefix); + TDbPool::TPtr GetOrCreate(ui32 poolId, ui32 sessionsCount); private: friend class TDbPoolHolder; - TDbPoolMap(const NYq::NConfig::TDbPoolConfig& config, + TDbPoolMap(const NDbPool::TConfig& config, NYdb::TDriver driver, const NKikimr::TYdbCredentialsProviderFactory& credentialsProviderFactory, const ::NMonitoring::TDynamicCounterPtr& counters); - void Reset(const NYq::NConfig::TDbPoolConfig& config); + void Reset(const NDbPool::TConfig& config); TMutex Mutex; - NYq::NConfig::TDbPoolConfig Config; + NDbPool::TConfig Config; NYdb::TDriver Driver; - THashMap<EDbPoolId, TDbPool::TPtr> Pools; + THashMap<ui32, TDbPool::TPtr> Pools; +public: THolder<NYdb::NTable::TTableClient> TableClient; +private: NKikimr::TYdbCredentialsProviderFactory CredentialsProviderFactory; const ::NMonitoring::TDynamicCounterPtr Counters; }; +NYdb::TAsyncStatus ExecDbRequest(TDbPool::TPtr dbPool, std::function<NYdb::TAsyncStatus(NYdb::NTable::TSession&)> handler); + class TDbPoolHolder: public TThrRefBase { public: using TPtr = TIntrusivePtr<TDbPoolHolder>; TDbPoolHolder( - const NYq::NConfig::TDbPoolConfig& config, + const NDbPool::TConfig& config, const NYdb::TDriver& driver, const NKikimr::TYdbCredentialsProviderFactory& credentialsProviderFactory, const ::NMonitoring::TDynamicCounterPtr& counters); ~TDbPoolHolder(); - void Reset(const NYq::NConfig::TDbPoolConfig& config); - TDbPool::TPtr GetOrCreate(EDbPoolId poolId, ui32 sessionsCount, const TString& tablePathPrefix); + void Reset(const NDbPool::TConfig& config); + TDbPool::TPtr GetOrCreate(ui32 poolId, ui32 sessionsCount); NYdb::TDriver& GetDriver(); TDbPoolMap::TPtr Get(); @@ -86,8 +84,6 @@ public: TDbPoolMap::TPtr Pools; }; -NYdb::TAsyncStatus ExecDbRequest(TDbPool::TPtr dbPool, std::function<NYdb::TAsyncStatus(NYdb::NTable::TSession&)> handler); - class TDbRequest: public NActors::TActorBootstrapped<TDbRequest> { using TFunction = std::function<NYdb::TAsyncStatus(NYdb::NTable::TSession&)>; TDbPool::TPtr DbPool; @@ -108,4 +104,4 @@ public: void OnUndelivered(NActors::TEvents::TEvUndelivered::TPtr&); }; -} /* NYq */ +} // namespace NDbPool
\ No newline at end of file diff --git a/ydb/library/db_pool/events.h b/ydb/library/db_pool/events.h new file mode 100644 index 00000000000..d2673838e7d --- /dev/null +++ b/ydb/library/db_pool/events.h @@ -0,0 +1,63 @@ +#pragma once + +#include <library/cpp/actors/core/events.h> +#include <library/cpp/actors/core/event_local.h> + +#include <ydb/public/sdk/cpp/client/ydb_table/table.h> + +namespace NDbPool { + +struct TEvents { + + enum EEv { + EvDbRequest = EventSpaceBegin(NActors::TEvents::ES_PRIVATE), + EvDbResponse, + EvDbFunctionRequest, + EvDbFunctionResponse, + EvEnd, + }; + + static_assert(EvEnd < EventSpaceEnd(NActors::TEvents::ES_PRIVATE), "expect EvEnd < EventSpaceEnd(NActors::TEvents::ES_PRIVATE)"); + + struct TEvDbRequest : NActors::TEventLocal<TEvDbRequest, EvDbRequest> { + TString Sql; + NYdb::TParams Params; + bool Idempotent; + + TEvDbRequest(const TString& sql, NYdb::TParams&& params, bool idempotent = true) + : Sql(sql) + , Params(std::move(params)) + , Idempotent(idempotent) + {} + }; + + struct TEvDbResponse : NActors::TEventLocal<TEvDbResponse, EvDbResponse> { + NYdb::TStatus Status; + TVector<NYdb::TResultSet> ResultSets; + + TEvDbResponse(NYdb::TStatus status, const TVector<NYdb::TResultSet>& resultSets) + : Status(status) + , ResultSets(resultSets) + {} + }; + + struct TEvDbFunctionRequest : NActors::TEventLocal<TEvDbFunctionRequest, EvDbFunctionRequest> { + using TFunction = std::function<NYdb::TAsyncStatus(NYdb::NTable::TSession&)>; + TFunction Handler; + + explicit TEvDbFunctionRequest(const TFunction& handler) + : Handler(handler) + {} + }; + + struct TEvDbFunctionResponse : NActors::TEventLocal<TEvDbFunctionResponse, EvDbFunctionResponse> { + NYdb::TStatus Status; + + explicit TEvDbFunctionResponse(NYdb::TStatus status) + : Status(status) + {} + }; + +}; + +} // namespace NDbPool diff --git a/ydb/library/db_pool/log.h b/ydb/library/db_pool/log.h new file mode 100644 index 00000000000..ce60d7df51a --- /dev/null +++ b/ydb/library/db_pool/log.h @@ -0,0 +1,28 @@ +#pragma once + +#include <ydb/core/protos/services.pb.h> + +#include <library/cpp/actors/core/log.h> + +#define LOG_IMPL_AS(actorSystem, level, component, logRecordStream) \ + LOG_LOG_S(actorSystem, ::NActors::NLog:: Y_CAT(PRI_, level), ::NKikimrServices::component, logRecordStream); + +#define LOG_F_AS(actorSystem, logRecordStream) LOG_IMPL_AS(*actorSystem, EMERG, DB_POOL, logRecordStream) +#define LOG_A_AS(actorSystem, logRecordStream) LOG_IMPL_AS(*actorSystem, ALERT, DB_POOL, logRecordStream) +#define LOG_C_AS(actorSystem, logRecordStream) LOG_IMPL_AS(*actorSystem, CRIT, DB_POOL, logRecordStream) +#define LOG_E_AS(actorSystem, logRecordStream) LOG_IMPL_AS(*actorSystem, ERROR, DB_POOL, logRecordStream) +#define LOG_W_AS(actorSystem, logRecordStream) LOG_IMPL_AS(*actorSystem, WARN, DB_POOL, logRecordStream) +#define LOG_N_AS(actorSystem, logRecordStream) LOG_IMPL_AS(*actorSystem, NOTICE, DB_POOL, logRecordStream) +#define LOG_I_AS(actorSystem, logRecordStream) LOG_IMPL_AS(*actorSystem, INFO, DB_POOL, logRecordStream) +#define LOG_D_AS(actorSystem, logRecordStream) LOG_IMPL_AS(*actorSystem, DEBUG, DB_POOL, logRecordStream) +#define LOG_T_AS(actorSystem, logRecordStream) LOG_IMPL_AS(*actorSystem, TRACE, DB_POOL, logRecordStream) + +#define LOG_F(logRecordStream) LOG_F_AS(::NActors::TActivationContext::ActorSystem(), logRecordStream) +#define LOG_A(logRecordStream) LOG_A_AS(::NActors::TActivationContext::ActorSystem(), logRecordStream) +#define LOG_C(logRecordStream) LOG_C_AS(::NActors::TActivationContext::ActorSystem(), logRecordStream) +#define LOG_E(logRecordStream) LOG_E_AS(::NActors::TActivationContext::ActorSystem(), logRecordStream) +#define LOG_W(logRecordStream) LOG_W_AS(::NActors::TActivationContext::ActorSystem(), logRecordStream) +#define LOG_N(logRecordStream) LOG_N_AS(::NActors::TActivationContext::ActorSystem(), logRecordStream) +#define LOG_I(logRecordStream) LOG_I_AS(::NActors::TActivationContext::ActorSystem(), logRecordStream) +#define LOG_D(logRecordStream) LOG_D_AS(::NActors::TActivationContext::ActorSystem(), logRecordStream) +#define LOG_T(logRecordStream) LOG_T_AS(::NActors::TActivationContext::ActorSystem(), logRecordStream) diff --git a/ydb/library/db_pool/protos/CMakeLists.darwin.txt b/ydb/library/db_pool/protos/CMakeLists.darwin.txt new file mode 100644 index 00000000000..514410b8b5e --- /dev/null +++ b/ydb/library/db_pool/protos/CMakeLists.darwin.txt @@ -0,0 +1,31 @@ + +# This file was generated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_library(library-db_pool-protos) +target_link_libraries(library-db_pool-protos PUBLIC + contrib-libs-cxxsupp + yutil + contrib-libs-protobuf +) +target_proto_messages(library-db_pool-protos PRIVATE + ${CMAKE_SOURCE_DIR}/ydb/library/db_pool/protos/config.proto +) +target_proto_addincls(library-db_pool-protos + ./ + ${CMAKE_SOURCE_DIR}/ + ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/contrib/libs/protobuf/src + ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/contrib/libs/protobuf/src +) +target_proto_outs(library-db_pool-protos + --cpp_out=${CMAKE_BINARY_DIR}/ + --cpp_styleguide_out=${CMAKE_BINARY_DIR}/ +) diff --git a/ydb/library/db_pool/protos/CMakeLists.linux-aarch64.txt b/ydb/library/db_pool/protos/CMakeLists.linux-aarch64.txt new file mode 100644 index 00000000000..2e62e2bc4b2 --- /dev/null +++ b/ydb/library/db_pool/protos/CMakeLists.linux-aarch64.txt @@ -0,0 +1,32 @@ + +# This file was generated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_library(library-db_pool-protos) +target_link_libraries(library-db_pool-protos PUBLIC + contrib-libs-linux-headers + contrib-libs-cxxsupp + yutil + contrib-libs-protobuf +) +target_proto_messages(library-db_pool-protos PRIVATE + ${CMAKE_SOURCE_DIR}/ydb/library/db_pool/protos/config.proto +) +target_proto_addincls(library-db_pool-protos + ./ + ${CMAKE_SOURCE_DIR}/ + ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/contrib/libs/protobuf/src + ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/contrib/libs/protobuf/src +) +target_proto_outs(library-db_pool-protos + --cpp_out=${CMAKE_BINARY_DIR}/ + --cpp_styleguide_out=${CMAKE_BINARY_DIR}/ +) diff --git a/ydb/library/db_pool/protos/CMakeLists.linux.txt b/ydb/library/db_pool/protos/CMakeLists.linux.txt new file mode 100644 index 00000000000..2e62e2bc4b2 --- /dev/null +++ b/ydb/library/db_pool/protos/CMakeLists.linux.txt @@ -0,0 +1,32 @@ + +# This file was generated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_library(library-db_pool-protos) +target_link_libraries(library-db_pool-protos PUBLIC + contrib-libs-linux-headers + contrib-libs-cxxsupp + yutil + contrib-libs-protobuf +) +target_proto_messages(library-db_pool-protos PRIVATE + ${CMAKE_SOURCE_DIR}/ydb/library/db_pool/protos/config.proto +) +target_proto_addincls(library-db_pool-protos + ./ + ${CMAKE_SOURCE_DIR}/ + ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/contrib/libs/protobuf/src + ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/contrib/libs/protobuf/src +) +target_proto_outs(library-db_pool-protos + --cpp_out=${CMAKE_BINARY_DIR}/ + --cpp_styleguide_out=${CMAKE_BINARY_DIR}/ +) diff --git a/ydb/library/db_pool/protos/CMakeLists.txt b/ydb/library/db_pool/protos/CMakeLists.txt new file mode 100644 index 00000000000..5bb4faffb40 --- /dev/null +++ b/ydb/library/db_pool/protos/CMakeLists.txt @@ -0,0 +1,15 @@ + +# This file was generated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + +if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" AND UNIX AND NOT APPLE AND NOT ANDROID) + include(CMakeLists.linux-aarch64.txt) +elseif (APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") + include(CMakeLists.darwin.txt) +elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND UNIX AND NOT APPLE AND NOT ANDROID) + include(CMakeLists.linux.txt) +endif() diff --git a/ydb/library/db_pool/protos/config.proto b/ydb/library/db_pool/protos/config.proto new file mode 100644 index 00000000000..f8c0825d971 --- /dev/null +++ b/ydb/library/db_pool/protos/config.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; +option cc_enable_arenas = true; + +package NDbPool; + +message TConfig { + uint32 MaxSessionCount = 1; + string Endpoint = 2; + string Database = 3; + string OAuthFile = 4; + bool UseLocalMetadataService = 5; + bool UseSsl = 6; + string Token = 7; +}
\ No newline at end of file |