diff --git a/.github/import_generation.txt b/.github/import_generation.txt index f64f5d8d85..9902f17848 100644 --- a/.github/import_generation.txt +++ b/.github/import_generation.txt @@ -1 +1 @@ -27 +28 diff --git a/.github/last_commit.txt b/.github/last_commit.txt index bd4d1291fd..74c170ce52 100644 --- a/.github/last_commit.txt +++ b/.github/last_commit.txt @@ -1 +1 @@ -78aa6fa75eba124b91b200bfe76c67e94ee968a4 +42606baa568dd1f0408b0651dce31577f28bcfe1 diff --git a/include/ydb-cpp-sdk/client/types/ydb.h b/include/ydb-cpp-sdk/client/types/ydb.h index cb89fa0a5e..c62652c609 100644 --- a/include/ydb-cpp-sdk/client/types/ydb.h +++ b/include/ydb-cpp-sdk/client/types/ydb.h @@ -4,6 +4,7 @@ #include "status_codes.h" #include +#include #include @@ -50,8 +51,8 @@ class TBalancingPolicy { friend class TDriver; public: //! Use preferable location, - //! location is a name of datacenter (VLA, MAN), if location is empty local datacenter is used - static TBalancingPolicy UsePreferableLocation(const std::string& location = {}); + //! location is a name of datacenter (VLA, MAN), if location is nullopt local datacenter is used + static TBalancingPolicy UsePreferableLocation(const std::optional& location = {}); //! Use all available cluster nodes regardless datacenter locality static TBalancingPolicy UseAllNodes(); @@ -71,6 +72,7 @@ class TBalancingPolicy { private: TBalancingPolicy(std::unique_ptr&& impl); + // For deprecated EBalancingPolicy TBalancingPolicy(EBalancingPolicy policy, const std::string& params); std::unique_ptr Impl_; diff --git a/src/client/driver/driver.cpp b/src/client/driver/driver.cpp index ba6a6559ab..e1e88dea22 100644 --- a/src/client/driver/driver.cpp +++ b/src/client/driver/driver.cpp @@ -70,7 +70,7 @@ class TDriverConfig::TImpl : public IConnectionsParams { TCP_KEEPALIVE_INTERVAL }; bool DrainOnDtors = true; - TBalancingPolicy::TImpl BalancingSettings = TBalancingPolicy::TImpl::UsePreferableLocation(""); + TBalancingPolicy::TImpl BalancingSettings = TBalancingPolicy::TImpl::UsePreferableLocation(std::nullopt); TDuration GRpcKeepAliveTimeout = TDuration::Seconds(10); bool GRpcKeepAlivePermitWithoutCalls = true; TDuration SocketIdleTimeout = TDuration::Minutes(6); diff --git a/src/client/export/export.cpp b/src/client/export/export.cpp index 342329018c..4549605260 100644 --- a/src/client/export/export.cpp +++ b/src/client/export/export.cpp @@ -29,7 +29,8 @@ const std::string TExportToS3Settings::TEncryptionAlgorithm::CHACHA_20_POLY_1305 namespace { std::vector ItemsProgressFromProto(const google::protobuf::RepeatedPtrField& proto) { - std::vector result(proto.size()); + std::vector result; + result.reserve(proto.size()); for (const auto& protoItem : proto) { auto& item = result.emplace_back(); diff --git a/src/client/impl/internal/common/balancing_policies.cpp b/src/client/impl/internal/common/balancing_policies.cpp index b3b943c63b..22ec50a622 100644 --- a/src/client/impl/internal/common/balancing_policies.cpp +++ b/src/client/impl/internal/common/balancing_policies.cpp @@ -9,7 +9,7 @@ TBalancingPolicy::TImpl TBalancingPolicy::TImpl::UseAllNodes() { return impl; } -TBalancingPolicy::TImpl TBalancingPolicy::TImpl::UsePreferableLocation(const std::string& location) { +TBalancingPolicy::TImpl TBalancingPolicy::TImpl::UsePreferableLocation(const std::optional& location) { TBalancingPolicy::TImpl impl; impl.PolicyType = EPolicyType::UsePreferableLocation; impl.Location = location; diff --git a/src/client/impl/internal/common/balancing_policies.h b/src/client/impl/internal/common/balancing_policies.h index 6c7e1c0905..f1180f37ed 100644 --- a/src/client/impl/internal/common/balancing_policies.h +++ b/src/client/impl/internal/common/balancing_policies.h @@ -19,14 +19,14 @@ class TBalancingPolicy::TImpl { static TImpl UseAllNodes(); - static TImpl UsePreferableLocation(const std::string& location); + static TImpl UsePreferableLocation(const std::optional& location); static TImpl UsePreferablePileState(EPileState pileState); EPolicyType PolicyType; // UsePreferableLocation - std::string Location; + std::optional Location; // UsePreferablePileState EPileState PileState; diff --git a/src/client/impl/internal/db_driver_state/endpoint_pool.cpp b/src/client/impl/internal/db_driver_state/endpoint_pool.cpp index 1895f39069..8bdbd19262 100644 --- a/src/client/impl/internal/db_driver_state/endpoint_pool.cpp +++ b/src/client/impl/internal/db_driver_state/endpoint_pool.cpp @@ -45,6 +45,7 @@ std::pair, bool> TEndpointPool::Updat // Is used to convert float to integer load factor // same integer values will be selected randomly. const float multiplicator = 10.0; + std::string selfLocation = result.Result.self_location(); std::unordered_map pileStates; for (const auto& pile : result.Result.pile_states()) { pileStates[pile.pile_name()] = pile; @@ -53,7 +54,7 @@ std::pair, bool> TEndpointPool::Updat for (const auto& endpoint : result.Result.endpoints()) { std::int32_t loadFactor = static_cast(multiplicator * std::min(LoadMax, std::max(LoadMin, endpoint.load_factor()))); std::uint64_t nodeId = endpoint.node_id(); - if (!IsLocalEndpoint(endpoint, pileStates)) { + if (!IsPreferredEndpoint(endpoint, selfLocation, pileStates)) { // Location mismatch, shift this endpoint loadFactor += GetLocalityShift(); } @@ -173,13 +174,14 @@ constexpr std::int32_t TEndpointPool::GetLocalityShift() { return LoadMax * Multiplicator; } -bool TEndpointPool::IsLocalEndpoint(const Ydb::Discovery::EndpointInfo& endpoint, - const std::unordered_map& pileStates) const { +bool TEndpointPool::IsPreferredEndpoint(const Ydb::Discovery::EndpointInfo& endpoint, + const std::string& selfLocation, + const std::unordered_map& pileStates) const { switch (BalancingPolicy_.PolicyType) { case TBalancingPolicy::TImpl::EPolicyType::UseAllNodes: return true; case TBalancingPolicy::TImpl::EPolicyType::UsePreferableLocation: - return endpoint.location() == BalancingPolicy_.Location; + return endpoint.location() == BalancingPolicy_.Location.value_or(selfLocation); case TBalancingPolicy::TImpl::EPolicyType::UsePreferablePileState: if (auto it = pileStates.find(endpoint.bridge_pile_name()); it != pileStates.end()) { return GetPileState(it->second.state()) == BalancingPolicy_.PileState; diff --git a/src/client/impl/internal/db_driver_state/endpoint_pool.h b/src/client/impl/internal/db_driver_state/endpoint_pool.h index c7d54ce510..b534593337 100644 --- a/src/client/impl/internal/db_driver_state/endpoint_pool.h +++ b/src/client/impl/internal/db_driver_state/endpoint_pool.h @@ -46,8 +46,9 @@ class TEndpointPool { static constexpr std::int32_t GetLocalityShift(); private: - bool IsLocalEndpoint(const Ydb::Discovery::EndpointInfo& endpoint, - const std::unordered_map& pileStates) const; + bool IsPreferredEndpoint(const Ydb::Discovery::EndpointInfo& endpoint, + const std::string& selfLocation, + const std::unordered_map& pileStates) const; EPileState GetPileState(const Ydb::Bridge::PileState::State& state) const; private: diff --git a/src/client/impl/session/kqp_session_common.cpp b/src/client/impl/session/kqp_session_common.cpp index e2a59de959..fc0fe64ef3 100644 --- a/src/client/impl/session/kqp_session_common.cpp +++ b/src/client/impl/session/kqp_session_common.cpp @@ -171,9 +171,10 @@ std::function TKqpSessionCommon::GetSmartDeleter(std:: switch (sessionImpl->GetState()) { case TKqpSessionCommon::S_STANDALONE: case TKqpSessionCommon::S_BROKEN: - case TKqpSessionCommon::S_CLOSING: + case TKqpSessionCommon::S_CLOSING: { client->DeleteSession(sessionImpl); break; + } case TKqpSessionCommon::S_IDLE: case TKqpSessionCommon::S_ACTIVE: { if (!client->ReturnSession(sessionImpl)) { diff --git a/src/client/types/ydb.cpp b/src/client/types/ydb.cpp index 332c03b626..f6083ec25e 100644 --- a/src/client/types/ydb.cpp +++ b/src/client/types/ydb.cpp @@ -10,7 +10,7 @@ namespace NYdb::inline V3 { TBalancingPolicy::TBalancingPolicy(EBalancingPolicy policy, const std::string& params) { switch (policy) { case EBalancingPolicy::UsePreferableLocation: - Impl_ = std::make_unique(TImpl::UsePreferableLocation(params)); + Impl_ = std::make_unique(TImpl::UsePreferableLocation(params.empty() ? std::nullopt : std::make_optional(params))); break; case EBalancingPolicy::UseAllNodes: Impl_ = std::make_unique(TImpl::UseAllNodes()); @@ -18,7 +18,7 @@ TBalancingPolicy::TBalancingPolicy(EBalancingPolicy policy, const std::string& p } } -TBalancingPolicy TBalancingPolicy::UsePreferableLocation(const std::string& location) { +TBalancingPolicy TBalancingPolicy::UsePreferableLocation(const std::optional& location) { return TBalancingPolicy(std::make_unique(TImpl::UsePreferableLocation(location))); }