dbms: Server: queries with several replicas: development [#METR-14410]

This commit is contained in:
Alexey Arno 2015-01-21 15:42:02 +03:00
parent 2201c073a8
commit a5dec52f9a
4 changed files with 173 additions and 173 deletions

View File

@ -6,14 +6,11 @@
namespace DB
{
class PartsWithRangesSplitter;
/** Выполняет запросы SELECT на данных из merge-дерева.
*/
class MergeTreeDataSelectExecutor
{
friend class PartsWithRangesSplitter;
public:
MergeTreeDataSelectExecutor(MergeTreeData & data_);
@ -30,11 +27,7 @@ public:
unsigned threads = 1,
size_t * inout_part_index = nullptr);
private:
MergeTreeData & data;
Logger * log;
public:
struct RangesInDataPart
{
MergeTreeData::DataPartPtr data_part;
@ -49,10 +42,13 @@ private:
}
};
public:
typedef std::vector<RangesInDataPart> RangesInDataParts;
private:
MergeTreeData & data;
Logger * log;
size_t min_marks_for_seek;
size_t min_marks_for_concurrent_read;
size_t max_marks_to_use_cache;

View File

@ -1,20 +1,21 @@
#pragma once
#include <DB/Storages/MergeTree/MergeTreeDataSelectExecutor.h>
namespace DB
{
/// Разбиваем parts_with_ranges на n частей.
/// Следующие условия должны быть выполнены:
/// - 1 <= n <= settings.max_clusters_count;
/// - каждая из n частей имеет >= min_cluster_size записей.
/// 3 levels: cluster / part / range
class PartsWithRangesSplitter
{
public:
/// Разбиваем parts_with_ranges на n частей.
/// Следующие условия должны быть выполнены:
/// - 1 <= n <= settings.max_clusters_count;
/// - каждая из n частей имеет >= min_cluster_size записей.
/// 3 levels: cluster / part / range
class PartsWithRangesSplitter
{
public:
typedef MergeTreeDataSelectExecutor::RangesInDataParts Cluster;
public:
public:
PartsWithRangesSplitter(const Cluster & input_cluster_,
size_t total_size_, size_t min_cluster_size_, size_t max_clusters_count_);
@ -24,7 +25,7 @@ namespace DB
std::vector<Cluster> perform();
private:
private:
void init();
bool emit();
bool updateCluster();
@ -35,7 +36,7 @@ namespace DB
bool isRangeConsumed() const { return range_begin == range_end; }
bool isClusterConsumed() const { return cluster_begin == cluster_end; }
private:
private:
// Input data.
const Cluster & input_cluster;
Cluster::const_iterator input_part;
@ -57,5 +58,6 @@ namespace DB
size_t cluster_begin;
size_t cluster_end;
};
};
}

View File

@ -14,8 +14,9 @@
namespace
{
std::pair<UInt64, UInt64> computeHash(const DB::MergeTreeDataSelectExecutor::RangesInDataParts & cluster)
{
std::pair<UInt64, UInt64> computeHash(const DB::MergeTreeDataSelectExecutor::RangesInDataParts & cluster)
{
SipHash hash;
for (const auto & part_with_ranges : cluster)
{
@ -34,7 +35,8 @@ namespace
hash.get128(lo, hi);
return std::make_pair(lo, hi);
}
}
}
namespace DB

View File

@ -3,25 +3,25 @@
namespace DB
{
PartsWithRangesSplitter::PartsWithRangesSplitter(const Cluster & input_cluster_,
PartsWithRangesSplitter::PartsWithRangesSplitter(const Cluster & input_cluster_,
size_t total_size_, size_t min_cluster_size_, size_t max_clusters_count_)
: input_cluster(input_cluster_),
total_size(total_size_),
remaining_size(total_size_),
min_cluster_size(min_cluster_size_),
max_clusters_count(max_clusters_count_)
{
}
: input_cluster(input_cluster_),
total_size(total_size_),
remaining_size(total_size_),
min_cluster_size(min_cluster_size_),
max_clusters_count(max_clusters_count_)
{
}
std::vector<PartsWithRangesSplitter::Cluster> PartsWithRangesSplitter::perform()
{
std::vector<PartsWithRangesSplitter::Cluster> PartsWithRangesSplitter::perform()
{
init();
while (emit()) {}
return output_clusters;
}
}
void PartsWithRangesSplitter::init()
{
void PartsWithRangesSplitter::init()
{
size_t clusters_count = max_clusters_count;
while ((clusters_count > 0) && (total_size < (min_cluster_size * clusters_count)))
--clusters_count;
@ -39,10 +39,10 @@ namespace DB
current_output_cluster = output_clusters.begin();
addPart();
initClusterInfo();
}
}
bool PartsWithRangesSplitter::emit()
{
bool PartsWithRangesSplitter::emit()
{
size_t new_size = std::min(range_end - range_begin, cluster_end - cluster_begin);
current_output_part->ranges.push_back(MarkRange(range_begin, range_begin + new_size));
@ -55,10 +55,10 @@ namespace DB
return updateRange(true);
else
return false;
}
}
bool PartsWithRangesSplitter::updateCluster()
{
bool PartsWithRangesSplitter::updateCluster()
{
++current_output_cluster;
if (current_output_cluster == output_clusters.end())
return false;
@ -70,10 +70,10 @@ namespace DB
addPart();
initClusterInfo();
return true;
}
}
bool PartsWithRangesSplitter::updateRange(bool add_part)
{
bool PartsWithRangesSplitter::updateRange(bool add_part)
{
++input_range;
if (input_range == input_part->ranges.end())
{
@ -89,30 +89,30 @@ namespace DB
initRangeInfo();
return true;
}
}
void PartsWithRangesSplitter::addPart()
{
void PartsWithRangesSplitter::addPart()
{
MergeTreeDataSelectExecutor::RangesInDataPart new_part;
new_part.data_part = input_part->data_part;
current_output_cluster->push_back(new_part);
current_output_part = &(current_output_cluster->back());
}
}
void PartsWithRangesSplitter::initRangeInfo()
{
void PartsWithRangesSplitter::initRangeInfo()
{
range_begin = 0;
range_end = input_range->end - input_range->begin;
}
}
void PartsWithRangesSplitter::initClusterInfo()
{
void PartsWithRangesSplitter::initClusterInfo()
{
cluster_begin = 0;
cluster_end = cluster_size;
remaining_size -= cluster_size;
if (remaining_size < cluster_size)
cluster_end += remaining_size;
}
}
}