Skip to content
Permalink
Browse files
Merge pull request #1567 from KaneVV1/master
Fix LA selection runs too long
  • Loading branch information
wwbmmm committed Mar 28, 2022
2 parents d4d98ff + dc45958 commit 8776fa886c89c5850c5df12720a0da69f2a259f2
Showing 2 changed files with 23 additions and 0 deletions.
@@ -341,6 +341,10 @@ int LocalityAwareLoadBalancer::SelectServer(const SelectIn& in, SelectOut* out)
if (++ntry >= n) {
break;
}
} else {
if (++ntry >= n) {
break;
}
}
total = _total.load(butil::memory_order_relaxed);
dice = butil::fast_rand_less_than(total);
@@ -30,6 +30,9 @@
#include "butil/containers/doubly_buffered_data.h"
#include "brpc/describable.h"
#include "brpc/socket.h"
#include "brpc/socket_map.h"
#include "brpc/global.h"
#include "brpc/details/load_balancer_with_naming.h"
#include "butil/strings/string_number_conversions.h"
#include "brpc/excluded_servers.h"
#include "brpc/policy/weighted_round_robin_load_balancer.h"
@@ -1084,4 +1087,20 @@ TEST_F(LoadBalancerTest, revived_from_all_failed_intergrated) {
ASSERT_EQ(0, num_failed.load(butil::memory_order_relaxed));
}

TEST_F(LoadBalancerTest, la_selection_too_long) {
brpc::GlobalInitializeOrDie();
brpc::LoadBalancerWithNaming lb;
CHECK_EQ(0, lb.Init("list://127.0.0.1:8888", "la", nullptr, nullptr));
char addr[] = "127.0.0.1:8888";
butil::EndPoint ep;
ASSERT_EQ(0, str2endpoint(addr, &ep));
brpc::SocketId id;
ASSERT_EQ(0, brpc::SocketMapFind(brpc::SocketMapKey(ep), &id));
ASSERT_EQ(0, brpc::Socket::SetFailed(id));
brpc::LoadBalancer::SelectIn in = { 0, false, false, 0u, nullptr };
brpc::SocketUniquePtr ptr;
brpc::LoadBalancer::SelectOut out(&ptr);
ASSERT_EQ(EHOSTDOWN, lb.SelectServer(in, &out));
}

} //namespace

0 comments on commit 8776fa8

Please sign in to comment.