ClickHouse/src/Common/GetPriorityForLoadBalancing.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.4 KiB
C++
Raw Normal View History

2021-10-20 08:35:37 +00:00
#pragma once
#include <Common/Priority.h>
#include <Core/LoadBalancing.h>
#include <functional>
#include <vector>
2021-10-20 08:35:37 +00:00
namespace DB
{
class GetPriorityForLoadBalancing
{
public:
2024-01-19 12:51:30 +00:00
using Func = std::function<Priority(size_t index)>;
explicit GetPriorityForLoadBalancing(LoadBalancing load_balancing_, size_t last_used_ = 0)
: load_balancing(load_balancing_), last_used(last_used_)
{
}
GetPriorityForLoadBalancing() = default;
2022-03-21 14:55:01 +00:00
bool operator == (const GetPriorityForLoadBalancing & other) const
2021-10-20 08:35:37 +00:00
{
return load_balancing == other.load_balancing
&& hostname_prefix_distance == other.hostname_prefix_distance
&& hostname_levenshtein_distance == other.hostname_levenshtein_distance;
2022-03-21 14:55:01 +00:00
}
bool operator != (const GetPriorityForLoadBalancing & other) const
{
return !(*this == other);
2021-10-20 08:35:37 +00:00
}
2024-01-19 12:51:30 +00:00
Func getPriorityFunc(LoadBalancing load_balance, size_t offset, size_t pool_size) const;
2024-06-22 23:58:28 +00:00
bool hasOptimalNode() const;
2021-10-21 09:59:24 +00:00
std::vector<size_t> hostname_prefix_distance; /// Prefix distances from name of this host to the names of hosts of pools.
std::vector<size_t> hostname_levenshtein_distance; /// Levenshtein Distances from name of this host to the names of hosts of pools.
2021-10-22 12:23:25 +00:00
LoadBalancing load_balancing = LoadBalancing::RANDOM;
2021-10-20 08:35:37 +00:00
private:
mutable size_t last_used = 0; /// Last used for round_robin policy.
2021-10-20 08:35:37 +00:00
};
}