Skip to content

Commit

Permalink
Cleans up review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vimes committed Dec 13, 2024
1 parent cd20fd0 commit a490f75
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 49 deletions.
1 change: 0 additions & 1 deletion autotest/autotest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ static bool readPacket(int fd, pcap_pkthdr* header, u_char* data, Duration timel
struct packHeader hdr;
if (!readTimeLimited(fd, hdr, time_to_give_up))
{
YANET_LOG_ERROR("Failed to read packet header\n");
return false;
}

Expand Down
2 changes: 2 additions & 0 deletions common/define.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ extern LogPriority logPriority;
#define YANET_BALANCER_DEFAULT_MSS_SIZE 536
#define YANET_BALANCER_FIX_MSS_SIZE 1220
#define YANET_BALANCER_FIX_MSS_FLAG ((uint8_t)(1u << 0))
static constexpr auto YANET_DEFAULT_BALANCER_REAL_MAPPINGS_LIMIT = 20000;
static constexpr auto YANET_DEFAULT_BALANCER_CELLS_PER_WEIGHT_UNIT = 20;

#define YANET_BALANCER_OPS_FLAG ((uint8_t)(1u << 1))
#define YANET_BALANCER_PURE_L3 ((uint8_t)(1u << 2))
Expand Down
18 changes: 9 additions & 9 deletions controlplane/balancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -965,11 +965,11 @@ bool balancer_t::reconfigure_wlc()
ipv6_outer_source_network,
reals] : balancer.services)
{
(void)flags;
(void)version;
(void)forwarding_method;
(void)ipv4_outer_source_network;
(void)ipv6_outer_source_network;
YANET_GCC_BUG_UNUSED(flags);
YANET_GCC_BUG_UNUSED(version);
YANET_GCC_BUG_UNUSED(forwarding_method);
YANET_GCC_BUG_UNUSED(ipv4_outer_source_network);
YANET_GCC_BUG_UNUSED(ipv6_outer_source_network);

if (scheduler != ::balancer::scheduler::wlc)
{
Expand All @@ -982,6 +982,7 @@ bool balancer_t::reconfigure_wlc()
}

std::vector<std::tuple<balancer::real_key_global_t, uint32_t, uint32_t>> service_reals_usage_info;
service_reals_usage_info.reserve(reals.size());
uint32_t connection_sum = 0;
uint32_t weight_sum = 0;

Expand Down Expand Up @@ -1017,14 +1018,13 @@ bool balancer_t::reconfigure_wlc()
uint32_t connections = 0;
for (auto& [socket_id, real_connections] : balancer_real_connections)
{
(void)socket_id;
YANET_GCC_BUG_UNUSED(socket_id);

auto it = real_connections.find(real_connections_key);
if (it == real_connections.end())
if (auto it = real_connections.find(real_connections_key); it != real_connections.end())
{
continue;
connections += it->second;
}
connections += it->second;
}

connection_sum += connections;
Expand Down
67 changes: 34 additions & 33 deletions dataplane/globalbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1611,22 +1611,22 @@ inline uint64_t generation::count_real_connections(uint32_t counter_id)
balancer_real_id_t* generation::rebuild_service_ring_one_wrr(
balancer_real_id_t* start,
const balancer_real_id_t* const do_not_exceed,
const balancer_service_t* service)
const balancer_service_t& service)
{
utils::Deferer defer([]() { YADECAP_MEMORY_BARRIER_COMPILE; });
for (uint32_t real_idx = service->real_start;
real_idx < service->real_start + service->real_size;
for (uint32_t real_idx = service.real_start;
real_idx < service.real_start + service.real_size;
++real_idx)
{
uint32_t real_id = balancer_service_reals[real_idx];
balancer_real_state_t* state = balancer_real_states + real_id;
balancer_real_id_t real_id = balancer_service_reals[real_idx];
const balancer_real_state_t& state = balancer_real_states[real_id];

if (state->weight == 0)
if (state.weight == 0)
{
continue;
}

auto weight = state->weight;
auto weight = state.weight;

while (weight-- > 0)
{
Expand All @@ -1643,16 +1643,16 @@ balancer_real_id_t* generation::rebuild_service_ring_one_wrr(
return start;
}

std::vector<std::pair<balancer_real_id_t, decltype(balancer_real_state_t::weight)>>
generation::ServiceWeights(const balancer_service_t* service)
std::vector<generation::RealWeight> generation::ServiceWeights(const balancer_service_t& service)
{
std::vector<std::pair<balancer_real_id_t, decltype(balancer_real_state_t::weight)>> weights;
for (uint32_t real_idx = service->real_start;
real_idx < service->real_start + service->real_size;
std::vector<RealWeight> weights;
weights.reserve(service.real_size);
for (uint32_t real_idx = service.real_start;
real_idx < service.real_start + service.real_size;
++real_idx)
{
uint32_t real_id = balancer_service_reals[real_idx];
uint32_t weight = (balancer_real_states + real_id)->weight;
balancer_real_id_t real_id = balancer_service_reals[real_idx];
uint32_t weight = balancer_real_states[real_id].weight;

weights.emplace_back(real_id, weight);
}
Expand All @@ -1662,44 +1662,45 @@ generation::ServiceWeights(const balancer_service_t* service)
balancer_real_id_t* generation::rebuild_service_ring_one_chash(
balancer_real_id_t* start,
const balancer_real_id_t* const do_not_exceed,
const balancer_service_t* service)
const balancer_service_t& service)
{
std::vector<std::pair<ipv6_address_t, balancer_real_id_t>> reals;
for (uint32_t real_idx = service->real_start;
real_idx < service->real_start + service->real_size;
reals.reserve(service.real_size);
for (uint32_t real_idx = service.real_start;
real_idx < service.real_start + service.real_size;
++real_idx)
{
uint32_t real_id = balancer_service_reals[real_idx];
balancer_real_id_t real_id = balancer_service_reals[real_idx];
ipv6_address_t& ip = balancer_reals[real_id].destination;
reals.emplace_back(ip, real_id);
}
auto updater = chash::WeightUpdater::MakeWeightUpdater(
reals,
20000,
20);
YANET_DEFAULT_BALANCER_REAL_MAPPINGS_LIMIT,
YANET_DEFAULT_BALANCER_CELLS_PER_WEIGHT_UNIT);
if (!updater)
{
YANET_LOG_ERROR("Failed to intialize updater for balancer service reals: %ld\n",
reals.size());
YANET_THROW("Failed to intialize updater for balancer service reals");
std::abort();
}
updater.value().InitLookup(ServiceWeights(service), start);

chash_updaters.emplace(service, std::move(updater.value()));
chash_updaters.emplace(&service, std::move(updater.value()));
return start + updater.value().LookupSize();
}

balancer_real_id_t* generation::update_service_ring_one_chash(
balancer_real_id_t* start,
const balancer_real_id_t* const do_not_exceed,
const balancer_service_t* service)
const balancer_service_t& service)
{
if (chash_updaters.find(service) == chash_updaters.end())
auto up = chash_updaters.find(&service);
if (up == chash_updaters.end())
{
YANET_LOG_ERROR("No state information for updating requested service.\n");
return start;
}
auto& updater = chash_updaters.at(service);
auto& updater = up->second;
updater.UpdateLookup(ServiceWeights(service), start);
return start + updater.LookupSize();
}
Expand All @@ -1708,11 +1709,11 @@ balancer_real_id_t* generation::evaluate_service_ring_one(
ServiceRingOp op,
balancer_real_id_t* start,
const balancer_real_id_t* const do_not_exceed,
const balancer_service_t* service)
const balancer_service_t& service)
{
balancer_real_id_t* end{start};
using scheduler = ::balancer::scheduler;
switch (service->scheduler)
switch (service.scheduler)
{
case scheduler::rr:
case scheduler::wrr:
Expand All @@ -1739,7 +1740,7 @@ balancer_real_id_t* generation::evaluate_service_ring_one(
}
break;
default:
YANET_LOG_ERROR("Unknown balancer service scheduler type\n");
YANET_THROW("Unknown balancer service scheduler type");
}
return end;
}
Expand All @@ -1752,17 +1753,17 @@ void generation::evaluate_service_ring(ServiceRingOp op)
service_idx < balancer_services_count;
++service_idx, service_start += YANET_CONFIG_BALANCER_REAL_WEIGHT_MAX)
{
balancer_service_t* service = balancer_services + balancer_active_services[service_idx];
const balancer_service_t& service = balancer_services[balancer_active_services[service_idx]];

balancer_service_range_t* range = ring->ranges + balancer_active_services[service_idx];
balancer_service_range_t& range = ring->ranges[balancer_active_services[service_idx]];

range->start = std::distance(ring->reals, service_start);
range.start = std::distance(ring->reals, service_start);
auto service_end = evaluate_service_ring_one(
op,
service_start,
service_start + YANET_CONFIG_BALANCER_REAL_WEIGHT_MAX,
service);
range->size = std::distance(service_start, service_end);
range.size = std::distance(service_start, service_end);
}
}

Expand Down
13 changes: 7 additions & 6 deletions dataplane/globalbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,25 +194,26 @@ class generation
Rebuild
};

std::vector<std::pair<balancer_real_id_t, decltype(balancer_real_state_t::weight)>>
ServiceWeights(const balancer_service_t* service);
using RealWeight = std::pair<balancer_real_id_t, decltype(balancer_real_state_t::weight)>;

std::vector<RealWeight> ServiceWeights(const balancer_service_t& service);
balancer_real_id_t* rebuild_service_ring_one_wrr(
balancer_real_id_t* start,
const balancer_real_id_t* const do_not_exceed,
const balancer_service_t* service);
const balancer_service_t& service);
balancer_real_id_t* rebuild_service_ring_one_chash(
balancer_real_id_t* start,
const balancer_real_id_t* const do_not_exceed,
const balancer_service_t* service);
const balancer_service_t& service);
balancer_real_id_t* update_service_ring_one_chash(
balancer_real_id_t* start,
const balancer_real_id_t* const do_not_exceed,
const balancer_service_t* service);
const balancer_service_t& service);
balancer_real_id_t* evaluate_service_ring_one(
ServiceRingOp op,
balancer_real_id_t* start,
const balancer_real_id_t* const do_not_exceed,
const balancer_service_t* service);
const balancer_service_t& service);
void evaluate_service_ring(ServiceRingOp op);
inline uint64_t count_real_connections(uint32_t counter_id);

Expand Down

0 comments on commit a490f75

Please sign in to comment.