This is an automated email from the ASF dual-hosted git repository.

chenBright pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git


The following commit(s) were added to refs/heads/master by this push:
     new 96aa6942 fix: support more than eight DynPart candidates (#3692)
96aa6942 is described below

commit 96aa6942766acab6aff52b7c42829e583ff26184
Author: nkysg <[email protected]>
AuthorDate: Mon Nov 2 15:48:37 2026 +0800

    fix: support more than eight DynPart candidates (#3692)
    
    * fix: support more than eight DynPart candidates
    
    * fmt
---
 src/brpc/policy/dynpart_load_balancer.cpp |  9 +++++++--
 test/brpc_channel_unittest.cpp            | 21 +++++++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/src/brpc/policy/dynpart_load_balancer.cpp 
b/src/brpc/policy/dynpart_load_balancer.cpp
index 24a25704..c3b5f380 100644
--- a/src/brpc/policy/dynpart_load_balancer.cpp
+++ b/src/brpc/policy/dynpart_load_balancer.cpp
@@ -114,7 +114,13 @@ int DynPartLoadBalancer::SelectServer(const SelectIn& in, 
SelectOut* out) {
         return EHOSTDOWN;
     }
     int64_t total_weight = 0;
-    std::pair<SocketUniquePtr, int64_t> ptrs[8];
+    std::pair<SocketUniquePtr, int64_t> stack_ptrs[8];
+    std::vector<std::pair<SocketUniquePtr, int64_t>> heap_ptrs;
+    std::pair<SocketUniquePtr, int64_t>* ptrs = stack_ptrs;
+    if (n > ARRAY_SIZE(stack_ptrs)) {
+        heap_ptrs.resize(n);
+        ptrs = heap_ptrs.data();
+    }
     int nptr = 0;
     bool exclusion = true;
     do {
@@ -124,7 +130,6 @@ int DynPartLoadBalancer::SelectServer(const SelectIn& in, 
SelectOut* out) {
                 && Socket::Address(id, &ptrs[nptr].first) == 0) {
                 int w = schan::GetSubChannelWeight(ptrs[nptr].first->user());
                 total_weight += w;
-                RELEASE_ASSERT_VERBOSE(nptr < 8, "Not supported yet");
                 ptrs[nptr].second = total_weight;
                 ++nptr;
             }
diff --git a/test/brpc_channel_unittest.cpp b/test/brpc_channel_unittest.cpp
index 3366aa1f..4374e0c8 100644
--- a/test/brpc_channel_unittest.cpp
+++ b/test/brpc_channel_unittest.cpp
@@ -38,6 +38,7 @@
 #include "brpc/policy/most_common_message.h"
 #include "brpc/policy/public_pbrpc_protocol.h"
 #include "brpc/policy/streaming_rpc_protocol.h"
+#include "brpc/policy/dynpart_load_balancer.h"
 #include "brpc/channel.h"
 #include "brpc/details/load_balancer_with_naming.h"
 #include "brpc/parallel_channel.h"
@@ -2859,6 +2860,26 @@ TEST_F(ChannelTest, uninitialized_selective_channel) {
     EXPECT_EQ(EINVAL, async_cntl.ErrorCode()) << async_cntl.ErrorText();
 }
 
+TEST_F(ChannelTest, dynpart_load_balancer_supports_more_than_eight_candidates) 
{
+    std::vector<DeferredSelectiveChannel::SubCall> calls;
+    brpc::SelectiveChannel channel;
+    ASSERT_EQ(0, channel.Init("rr", nullptr));
+
+    brpc::policy::DynPartLoadBalancer lb;
+    for (int i = 0; i < 9; ++i) {
+        brpc::SelectiveChannel::ChannelHandle handle;
+        ASSERT_EQ(0, channel.AddChannel(
+                         new DeferredSelectiveChannel(&calls), &handle));
+        ASSERT_TRUE(lb.AddServer(brpc::ServerId(handle.id, handle.tag)));
+    }
+
+    brpc::SocketUniquePtr ptr;
+    brpc::LoadBalancer::SelectIn in = { 0, false, false, 0u, nullptr };
+    brpc::LoadBalancer::SelectOut out(&ptr);
+    ASSERT_EQ(0, lb.SelectServer(in, &out));
+    ASSERT_NE(nullptr, ptr.get());
+}
+
 TEST_F(ChannelTest, empty_selective_channel) {
     brpc::SelectiveChannel channel;
     ASSERT_EQ(0, channel.Init("rr", nullptr));


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to