2021-10-20 08:35:37 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Core/SettingsEnums.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class GetPriorityForLoadBalancing
|
|
|
|
{
|
|
|
|
public:
|
2021-10-22 12:23:25 +00:00
|
|
|
GetPriorityForLoadBalancing(LoadBalancing load_balancing_) : load_balancing(load_balancing_) {}
|
2021-10-20 08:35:37 +00:00
|
|
|
GetPriorityForLoadBalancing(){}
|
|
|
|
|
2022-03-21 14:55:01 +00:00
|
|
|
bool operator == (const GetPriorityForLoadBalancing & other) const
|
2021-10-20 08:35:37 +00:00
|
|
|
{
|
2022-03-21 14:55:01 +00:00
|
|
|
return load_balancing == other.load_balancing && hostname_differences == other.hostname_differences;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator != (const GetPriorityForLoadBalancing & other) const
|
|
|
|
{
|
|
|
|
return !(*this == other);
|
2021-10-20 08:35:37 +00:00
|
|
|
}
|
|
|
|
|
2021-10-26 04:45:09 +00:00
|
|
|
std::function<size_t(size_t index)> getPriorityFunc(LoadBalancing load_balance, size_t offset, size_t pool_size) const;
|
2021-10-21 09:59:24 +00:00
|
|
|
|
2021-10-20 08:35:37 +00:00
|
|
|
std::vector<size_t> hostname_differences; /// 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.
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|