Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make system.replicas parallel #43998

Merged
merged 6 commits into from Jan 13, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 32 additions & 6 deletions src/Storages/System/StorageSystemReplicas.cpp
Expand Up @@ -10,6 +10,7 @@
#include <Common/typeid_cast.h>
#include <Databases/IDatabase.h>
#include <Processors/Sources/SourceFromSingleChunk.h>
#include <Common/getNumberOfPhysicalCPUCores.h>


namespace DB
Expand Down Expand Up @@ -151,14 +152,39 @@ Pipe StorageSystemReplicas::read(

MutableColumns res_columns = storage_snapshot->metadata->getSampleBlock().cloneEmptyColumns();

for (size_t i = 0, size = col_database->size(); i < size; ++i)
size_t tables_size = col_database->size();
std::vector<StorageReplicatedMergeTree::Status> statuses(tables_size);

size_t thread_pool_size = std::min(tables_size, static_cast<size_t>(getNumberOfPhysicalCPUCores()));
auto settings = context->getSettingsRef();
if (settings.max_threads != 0)
thread_pool_size = std::min(thread_pool_size, static_cast<size_t>(settings.max_threads));

ThreadPool thread_pool(thread_pool_size);

for (size_t i = 0; i < tables_size; ++i)
{
StorageReplicatedMergeTree::Status status;
dynamic_cast<StorageReplicatedMergeTree &>(
*replicated_tables
[(*col_database)[i].safeGet<const String &>()]
[(*col_table)[i].safeGet<const String &>()]).getStatus(status, with_zk_fields);
try
{
thread_pool.scheduleOrThrowOnError([&, i=i]
{
dynamic_cast<StorageReplicatedMergeTree &>(
*replicated_tables
[(*col_database)[i].safeGet<const String &>()]
[(*col_table)[i].safeGet<const String &>()]).getStatus(statuses[i], with_zk_fields);
});
}
catch (...)
{
thread_pool.wait();
evillique marked this conversation as resolved.
Show resolved Hide resolved
throw;
}
}

thread_pool.wait();

for (const auto & status: statuses)
{
size_t col_num = 3;
res_columns[col_num++]->insert(status.is_leader);
res_columns[col_num++]->insert(status.can_become_leader);
Expand Down