Add UseDetectedLocalDC balancing policy#564
Add UseDetectedLocalDC balancing policy#564Ilya-Repin wants to merge 9 commits intoydb-platform:mainfrom
Conversation
| std::vector<std::uint64_t> timings; | ||
| timings.reserve(PING_COUNT); | ||
| for (size_t i = 0; i < PING_COUNT; ++i) { | ||
| const auto& ep = endpoints[i % endpoints.size()].get(); |
There was a problem hiding this comment.
Тут кажется проще каждый эндпоинт по PING_COUNT раз пинговать, читаемее будет
|
|
||
| static constexpr std::uint32_t PING_TIMEOUT_SECONDS = 5; | ||
|
|
||
| TDuration PingEndpoint(const Ydb::Discovery::EndpointInfo& endpoint); |
There was a problem hiding this comment.
Лучше тут std::chrono::duration сделать, мы от TDuration и TInstant потихоньку избавляемся в SDK
|
|
||
| namespace NYdb::inline V3 { | ||
|
|
||
| static constexpr std::uint32_t PING_TIMEOUT_SECONDS = 5; |
There was a problem hiding this comment.
Тут лучше временной тип использовать, а не в сырую хранить
| std::vector<std::string> removed; | ||
| if (result.DiscoveryStatus.Status == EStatus::SUCCESS) { | ||
| if (BalancingPolicy_.PolicyType == TBalancingPolicy::TImpl::EPolicyType::UseDetectedLocalDC) { | ||
| LocalDCDetector_.DetectLocalDC(result.Result); |
There was a problem hiding this comment.
А это ведь прям тяжелая операция. А мы ее синхронно делаем. Это может discovery сильно замедлить, тут замеры не помешали бы. Лучше пинги в фоне делать, как по мне, но такое писать сложнее будет
| std::string FindNearestLocation(const TEndpointsByLocation& endpointsByLocation); | ||
|
|
||
| private: | ||
| static constexpr std::size_t MAX_ENDPOINTS_PER_LOCATION = 3; |
There was a problem hiding this comment.
С одной стороны, маловато нод, но тогда сильно тяжелее будет операция. Может действительно надо асинхронно
| timings.reserve(PING_COUNT); | ||
| for (size_t i = 0; i < PING_COUNT; ++i) { | ||
| const auto& ep = endpoints[i % endpoints.size()].get(); | ||
| timings.push_back(PingEndpoint_(ep).MicroSeconds()); |
There was a problem hiding this comment.
А это же синхронные пинги из одного потока? На первый взгляд так нельзя делать:
Во-первых, 2*3 - это 6 пингов один за другим.
Во-вторых, 3 ендпоинта в ДЦ может быть слишком мало.
Мы можем параллельно пинги рассылать? Странно, если нет. А если да, то видимо надо пинговать асинхронно и бОльшее количество нод (может и по 1 разу) для точности
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new UseDetectedLocalDC balancing policy that automatically detects the nearest datacenter by measuring endpoint latencies through network pings. The implementation includes:
- A local DC detector that pings endpoints across different locations and identifies the nearest one based on median RTT measurements
- Integration with the existing balancing policy framework
- Unit tests covering basic detection, single location scenarios, unavailable DC handling, and offline DC scenarios
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
include/ydb-cpp-sdk/client/types/ydb.h |
Added public API declaration for UseDetectedLocalDC() |
src/client/types/ydb.cpp |
Implemented the UseDetectedLocalDC() factory method |
src/client/impl/internal/common/balancing_policies.h |
Added UseDetectedLocalDC enum value to policy types |
src/client/impl/internal/common/balancing_policies.cpp |
Implemented internal policy initialization for detected local DC |
src/client/impl/internal/local_dc_detector/local_dc_detector.h |
Defined detector class interface with configurable pinger |
src/client/impl/internal/local_dc_detector/local_dc_detector.cpp |
Implemented DC detection logic using sampling and RTT measurement |
src/client/impl/internal/local_dc_detector/pinger.h |
Declared endpoint ping function |
src/client/impl/internal/local_dc_detector/pinger.cpp |
Implemented TCP connection-based ping with timeout handling |
src/client/impl/internal/db_driver_state/endpoint_pool.h |
Added LocalDCDetector_ member to endpoint pool |
src/client/impl/internal/db_driver_state/endpoint_pool.cpp |
Integrated detector into endpoint preference evaluation |
src/client/table/impl/table_client.cpp |
Extended foreign location scanning to include detected local DC policy |
tests/unit/client/local_dc_detector/local_dc_detector_ut.cpp |
Added comprehensive unit tests with mocked ping functionality |
| CMake files | Added build configuration for the new local_dc_detector component |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
No description provided.