2021-10-20 08:35:37 +00:00
|
|
|
#pragma once
|
|
|
|
|
2024-07-11 17:58:54 +00:00
|
|
|
#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_)
|
|
|
|
{
|
|
|
|
}
|
2023-12-27 15:06:41 +00:00
|
|
|
GetPriorityForLoadBalancing() = default;
|
2023-12-01 22:00:53 +00:00
|
|
|
|
2022-03-21 14:55:01 +00:00
|
|
|
bool operator == (const GetPriorityForLoadBalancing & other) const
|
2021-10-20 08:35:37 +00:00
|
|
|
{
|
2023-09-27 02:46:39 +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
|
|
|
|
2023-09-27 02:46:39 +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:
|
2023-12-27 15:06:41 +00:00
|
|
|
mutable size_t last_used = 0; /// Last used for round_robin policy.
|
2021-10-20 08:35:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|