@@ -45,6 +45,7 @@ std::pair<NThreading::TFuture<TEndpointUpdateResult>, bool> TEndpointPool::Updat
4545 // Is used to convert float to integer load factor
4646 // same integer values will be selected randomly.
4747 const float multiplicator = 10.0 ;
48+ std::string selfLocation = result.Result .self_location ();
4849 std::unordered_map<std::string, Ydb::Bridge::PileState> pileStates;
4950 for (const auto & pile : result.Result .pile_states ()) {
5051 pileStates[pile.pile_name ()] = pile;
@@ -53,7 +54,7 @@ std::pair<NThreading::TFuture<TEndpointUpdateResult>, bool> TEndpointPool::Updat
5354 for (const auto & endpoint : result.Result .endpoints ()) {
5455 std::int32_t loadFactor = static_cast <std::int32_t >(multiplicator * std::min (LoadMax, std::max (LoadMin, endpoint.load_factor ())));
5556 std::uint64_t nodeId = endpoint.node_id ();
56- if (!IsLocalEndpoint (endpoint, pileStates)) {
57+ if (!IsPreferredEndpoint (endpoint, selfLocation , pileStates)) {
5758 // Location mismatch, shift this endpoint
5859 loadFactor += GetLocalityShift ();
5960 }
@@ -173,13 +174,14 @@ constexpr std::int32_t TEndpointPool::GetLocalityShift() {
173174 return LoadMax * Multiplicator;
174175}
175176
176- bool TEndpointPool::IsLocalEndpoint (const Ydb::Discovery::EndpointInfo& endpoint,
177- const std::unordered_map<std::string, Ydb::Bridge::PileState>& pileStates) const {
177+ bool TEndpointPool::IsPreferredEndpoint (const Ydb::Discovery::EndpointInfo& endpoint,
178+ const std::string& selfLocation,
179+ const std::unordered_map<std::string, Ydb::Bridge::PileState>& pileStates) const {
178180 switch (BalancingPolicy_.PolicyType ) {
179181 case TBalancingPolicy::TImpl::EPolicyType::UseAllNodes:
180182 return true ;
181183 case TBalancingPolicy::TImpl::EPolicyType::UsePreferableLocation:
182- return endpoint.location () == BalancingPolicy_.Location ;
184+ return endpoint.location () == BalancingPolicy_.Location . value_or (selfLocation) ;
183185 case TBalancingPolicy::TImpl::EPolicyType::UsePreferablePileState:
184186 if (auto it = pileStates.find (endpoint.bridge_pile_name ()); it != pileStates.end ()) {
185187 return GetPileState (it->second .state ()) == BalancingPolicy_.PileState ;
0 commit comments