ClickHouse/programs/copier/ShardPartition.h

103 lines
3.1 KiB
C++
Raw Normal View History

2020-02-13 10:52:46 +00:00
#pragma once
2020-02-20 09:01:06 +00:00
#include "Aliases.h"
#include "TaskTableAndShard.h"
2020-02-13 10:52:46 +00:00
2020-03-17 18:07:54 +00:00
namespace DB
{
2020-02-13 10:52:46 +00:00
/// Just destination partition of a shard
/// I don't know what this comment means.
/// In short, when we discovered what shards contain currently processing partition,
/// This class describes a partition (name) that is stored on the shard (parent).
2020-03-17 18:07:54 +00:00
struct ShardPartition
{
2020-02-13 10:52:46 +00:00
ShardPartition(TaskShard &parent, String name_quoted_, size_t number_of_splits = 10)
: task_shard(parent), name(std::move(name_quoted_)) { pieces.reserve(number_of_splits); }
2020-03-17 18:07:54 +00:00
String getPartitionPath() const;
2020-02-13 10:52:46 +00:00
2020-03-17 18:07:54 +00:00
String getPartitionPiecePath(size_t current_piece_number) const;
2020-02-13 10:52:46 +00:00
2020-03-17 18:07:54 +00:00
String getPartitionCleanStartPath() const;
2020-02-13 10:52:46 +00:00
2020-03-17 18:07:54 +00:00
String getPartitionPieceCleanStartPath(size_t current_piece_number) const;
2020-02-13 10:52:46 +00:00
2020-03-17 18:07:54 +00:00
String getCommonPartitionIsDirtyPath() const;
2020-02-13 10:52:46 +00:00
2020-03-17 18:07:54 +00:00
String getCommonPartitionIsCleanedPath() const;
2020-02-13 10:52:46 +00:00
2020-03-17 18:07:54 +00:00
String getPartitionActiveWorkersPath() const;
2020-02-13 10:52:46 +00:00
2020-03-17 18:07:54 +00:00
String getActiveWorkerPath() const;
2020-02-13 10:52:46 +00:00
2020-03-17 18:07:54 +00:00
String getPartitionShardsPath() const;
2020-02-13 10:52:46 +00:00
2020-03-17 18:07:54 +00:00
String getShardStatusPath() const;
2020-02-13 10:52:46 +00:00
/// What partition pieces are present in current shard.
/// FYI: Piece is a part of partition which has modulo equals to concrete constant (less than number_of_splits obliously)
/// For example SELECT ... from ... WHERE partition=current_partition AND cityHash64(*) == const;
/// Absent pieces have field is_absent_piece equals to true.
PartitionPieces pieces;
TaskShard & task_shard;
String name;
};
2020-03-17 18:07:54 +00:00
inline String ShardPartition::getPartitionCleanStartPath() const
{
2020-02-13 10:52:46 +00:00
return getPartitionPath() + "/clean_start";
}
2020-03-17 18:07:54 +00:00
inline String ShardPartition::getPartitionPieceCleanStartPath(size_t current_piece_number) const
{
2020-02-13 10:52:46 +00:00
assert(current_piece_number < task_shard.task_table.number_of_splits);
return getPartitionPiecePath(current_piece_number) + "/clean_start";
}
2020-03-17 18:07:54 +00:00
inline String ShardPartition::getPartitionPath() const
{
2020-02-13 10:52:46 +00:00
return task_shard.task_table.getPartitionPath(name);
}
2020-03-17 18:07:54 +00:00
inline String ShardPartition::getPartitionPiecePath(size_t current_piece_number) const
{
2020-02-13 10:52:46 +00:00
assert(current_piece_number < task_shard.task_table.number_of_splits);
return task_shard.task_table.getPartitionPiecePath(name, current_piece_number);
}
2020-03-17 18:07:54 +00:00
inline String ShardPartition::getShardStatusPath() const
{
2020-02-13 10:52:46 +00:00
// schema: /<root...>/tables/<table>/<partition>/shards/<shard>
// e.g. /root/table_test.hits/201701/shards/1
return getPartitionShardsPath() + "/" + toString(task_shard.numberInCluster());
}
2020-03-17 18:07:54 +00:00
inline String ShardPartition::getPartitionShardsPath() const
{
2020-02-13 10:52:46 +00:00
return getPartitionPath() + "/shards";
}
2020-03-17 18:07:54 +00:00
inline String ShardPartition::getPartitionActiveWorkersPath() const
{
2020-02-13 10:52:46 +00:00
return getPartitionPath() + "/partition_active_workers";
}
2020-03-17 18:07:54 +00:00
inline String ShardPartition::getActiveWorkerPath() const
{
2020-02-13 10:52:46 +00:00
return getPartitionActiveWorkersPath() + "/" + toString(task_shard.numberInCluster());
}
2020-03-17 18:07:54 +00:00
inline String ShardPartition::getCommonPartitionIsDirtyPath() const
{
2020-02-13 10:52:46 +00:00
return getPartitionPath() + "/is_dirty";
}
2020-03-17 18:07:54 +00:00
inline String ShardPartition::getCommonPartitionIsCleanedPath() const
{
2020-02-13 10:52:46 +00:00
return getCommonPartitionIsDirtyPath() + "/cleaned";
}
}