Skip to content

Commit df12f8a

Browse files
Reserve WRR service ring size using real count
Balancer service ring size use only <Ñservice real count> * <max real weight> items in size so we definitely should not use one common constant for all the services. Also fix some boundary violations.
1 parent 6baee41 commit df12f8a

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

common/actions.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ struct DumpAction final
161161
tCounterId counter_id;
162162

163163
DumpAction(const acl::dump_t& dump_action) :
164-
dump_id(dump_action.dump_id), counter_id(dump_action.counter_id){};
164+
dump_id(dump_action.dump_id), counter_id(dump_action.counter_id) {};
165165

166166
DumpAction() :
167-
dump_id(0), counter_id(0){};
167+
dump_id(0), counter_id(0) {};
168168

169169
[[nodiscard]] bool terminating() const { return false; }
170170

@@ -193,7 +193,7 @@ struct FlowAction final
193193
std::optional<uint32_t> timeout;
194194

195195
FlowAction(const globalBase::tFlow& flow) :
196-
flow(flow){};
196+
flow(flow) {};
197197

198198
FlowAction(globalBase::tFlow&& flow) :
199199
flow(std::move(flow)) {}
@@ -228,7 +228,7 @@ struct CheckStateAction final
228228
tCounterId counter_id{0};
229229

230230
CheckStateAction(const acl::check_state_t& check_state_action) :
231-
counter_id(check_state_action.counter_id){};
231+
counter_id(check_state_action.counter_id) {};
232232
CheckStateAction() = default;
233233

234234
[[nodiscard]] bool terminating() const { return false; }
@@ -255,10 +255,10 @@ struct StateTimeoutAction final
255255
uint32_t timeout;
256256

257257
StateTimeoutAction(const acl::state_timeout_t& timeout_action) :
258-
timeout(timeout_action.timeout){};
258+
timeout(timeout_action.timeout) {};
259259

260260
StateTimeoutAction() :
261-
timeout(0){};
261+
timeout(0) {};
262262

263263
[[nodiscard]] bool terminating() const { return false; }
264264

@@ -287,11 +287,11 @@ struct HitCountAction final
287287

288288
HitCountAction(const acl::hit_count_t& hitcount_action) :
289289
id(std::move(hitcount_action.id)),
290-
counter_id(hitcount_action.counter_id){};
290+
counter_id(hitcount_action.counter_id) {};
291291

292292
HitCountAction() :
293293
id(""),
294-
counter_id(0){};
294+
counter_id(0) {};
295295

296296
[[nodiscard]] bool terminating() const { return false; }
297297

dataplane/globalbase.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1854,7 +1854,11 @@ generation::ServiceSize generation::rebuild_service_ring_one_wrr(
18541854
const balancer_service_t& service)
18551855
{
18561856
balancer_real_id_t* end = start;
1857-
balancer_real_id_t* reserve = start + YANET_BALANCER_WRR_SERVICE_SIZE;
1857+
balancer_real_id_t* reserve = start + YANET_CONFIG_BALANCER_REAL_WEIGHT_MAX * service.real_size;
1858+
if (reserve > do_not_exceed)
1859+
{
1860+
reserve = (balancer_real_id_t*)do_not_exceed;
1861+
}
18581862
for (uint32_t real_idx = service.real_start;
18591863
real_idx < service.real_start + service.real_size;
18601864
++real_idx)
@@ -1867,6 +1871,8 @@ generation::ServiceSize generation::rebuild_service_ring_one_wrr(
18671871
if (end + weight > reserve)
18681872
{
18691873
YANET_LOG_ERROR("Balancer service exceeded ring chunk bounds. Some reals skipped.\n");
1874+
std::fill_n(end, reserve - end, real_id);
1875+
end = reserve;
18701876
break;
18711877
}
18721878

0 commit comments

Comments
 (0)