Skip to content

Commit

Permalink
References
Browse files Browse the repository at this point in the history
  • Loading branch information
vimes committed Dec 17, 2024
1 parent 20297e6 commit 9eb04b3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 37 deletions.
62 changes: 31 additions & 31 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,15 @@ 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;
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,14 +1661,15 @@ 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);
}
Expand All @@ -1679,27 +1679,27 @@ balancer_real_id_t* generation::rebuild_service_ring_one_chash(
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 +1708,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 +1739,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 +1752,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 9eb04b3

Please sign in to comment.