style check final

This commit is contained in:
nikitamikhaylov 2020-02-19 23:50:27 +03:00
parent 6ca0776a61
commit 3c1f2b6124
4 changed files with 23 additions and 12 deletions

View File

@ -5,7 +5,8 @@
namespace DB
{
/// Contains info about all shards that contain a partition
struct ClusterPartition {
struct ClusterPartition
{
double elapsed_time_seconds = 0;
UInt64 bytes_copied = 0;
UInt64 rows_copied = 0;

View File

@ -1,6 +1,7 @@
#include "Internals.h"
namespace DB {
namespace DB
{
ConfigurationPtr getConfigurationFromXMLString(const std::string & xml_data)
{

View File

@ -106,17 +106,20 @@ struct TaskStateWithOwner
TaskState state{TaskState::Unknown};
String owner;
static String getData(TaskState state, const String &owner) {
static String getData(TaskState state, const String &owner)
{
return TaskStateWithOwner(state, owner).toString();
}
String toString() {
String toString()
{
WriteBufferFromOwnString wb;
wb << static_cast<UInt32>(state) << "\n" << escape << owner;
return wb.str();
}
static TaskStateWithOwner fromString(const String &data) {
static TaskStateWithOwner fromString(const String & data)
{
ReadBufferFromString rb(data);
TaskStateWithOwner res;
UInt32 state;
@ -139,7 +142,8 @@ struct ShardPriority
size_t hostname_difference = 0;
UInt8 random = 0;
static bool greaterPriority(const ShardPriority & current, const ShardPriority & other) {
static bool greaterPriority(const ShardPriority & current, const ShardPriority & other)
{
return std::forward_as_tuple(current.is_remote, current.hostname_difference, current.random)
< std::forward_as_tuple(other.is_remote, other.hostname_difference, other.random);
}

View File

@ -84,10 +84,11 @@ struct TaskTable
};
struct TaskShard {
struct TaskShard
{
TaskShard(TaskTable &parent, const ShardInfo &info_) : task_table(parent), info(info_) {}
TaskTable &task_table;
TaskTable & task_table;
ShardInfo info;
@ -221,12 +222,14 @@ inline TaskTable::TaskTable(TaskCluster & parent, const Poco::Util::AbstractConf
}
template<typename RandomEngine>
inline void TaskTable::initShards(RandomEngine && random_engine) {
inline void TaskTable::initShards(RandomEngine && random_engine)
{
const String & fqdn_name = getFQDNOrHostName();
std::uniform_int_distribution<UInt8> get_urand(0, std::numeric_limits<UInt8>::max());
// Compute the priority
for (auto & shard_info : cluster_pull->getShardsInfo()) {
for (auto & shard_info : cluster_pull->getShardsInfo())
{
TaskShardPtr task_shard = std::make_shared<TaskShard>(*this, shard_info);
const auto & replicas = cluster_pull->getShardsAddresses().at(task_shard->indexInCluster());
task_shard->priority = getReplicasPriority(replicas, fqdn_name, get_urand(random_engine));
@ -236,13 +239,15 @@ inline void TaskTable::initShards(RandomEngine && random_engine) {
// Sort by priority
std::sort(all_shards.begin(), all_shards.end(),
[](const TaskShardPtr & lhs, const TaskShardPtr & rhs) {
[](const TaskShardPtr & lhs, const TaskShardPtr & rhs)
{
return ShardPriority::greaterPriority(lhs->priority, rhs->priority);
});
// Cut local shards
auto it_first_remote = std::lower_bound(all_shards.begin(), all_shards.end(), 1,
[](const TaskShardPtr & lhs, UInt8 is_remote) {
[](const TaskShardPtr & lhs, UInt8 is_remote)
{
return lhs->priority.is_remote < is_remote;
});