Fixing special build. Disable setting by default.

This commit is contained in:
Nikolai Kochetov 2022-11-22 11:24:24 +00:00
parent c305afd77a
commit 9e84a351c7
5 changed files with 45 additions and 26 deletions

View File

@ -1,4 +1,6 @@
#if defined(OS_LINUX)
#include <Common/EventFD.h>
#include <Common/Exception.h>
#include <sys/eventfd.h>
@ -57,3 +59,5 @@ EventFD::~EventFD()
}
}
#endif

View File

@ -631,7 +631,7 @@ static constexpr UInt64 operator""_GiB(unsigned long long value)
M(Bool, allow_unrestricted_reads_from_keeper, false, "Allow unrestricted (without condition on path) reads from system.zookeeper table, can be handy, but is not safe for zookeeper", 0) \
M(Bool, allow_deprecated_database_ordinary, false, "Allow to create databases with deprecated Ordinary engine", 0) \
M(Bool, allow_deprecated_syntax_for_merge_tree, false, "Allow to create *MergeTree tables with deprecated engine definition syntax", 0) \
M(Bool, allow_asynchronous_read_from_io_pool_for_merge_tree, true, "Use background I/O pool to read from MergeTree tables. This setting may increase performance for I/O bound queries", 0) \
M(Bool, allow_asynchronous_read_from_io_pool_for_merge_tree, false, "Use background I/O pool to read from MergeTree tables. This setting may increase performance for I/O bound queries", 0) \
\
M(Bool, force_grouping_standard_compatibility, true, "Make GROUPING function to return 1 when argument is not used as an aggregation key", 0) \
\

View File

@ -65,7 +65,7 @@ static MergeTreeReaderSettings getMergeTreeReaderSettings(
.checksum_on_read = settings.checksum_on_read,
.read_in_order = query_info.input_order_info != nullptr,
.apply_deleted_mask = context->applyDeletedMask(),
.use_asynchronous_read_from_pool = settings.allow_asynchronous_read_from_io_pool_for_merge_tree,
.use_asynchronous_read_from_pool = settings.allow_asynchronous_read_from_io_pool_for_merge_tree && settings.max_streams_to_max_threads_ratio > 1,
};
}

View File

@ -11,8 +11,10 @@ MergeTreeSource::MergeTreeSource(MergeTreeSelectAlgorithmPtr algorithm_)
: ISource(algorithm_->getHeader())
, algorithm(std::move(algorithm_))
{
#if defined(OS_LINUX)
if (algorithm->getSettings().use_asynchronous_read_from_pool)
async_reading_state = std::make_unique<AsyncReadingState>();
#endif
}
MergeTreeSource::~MergeTreeSource() = default;
@ -27,6 +29,7 @@ void MergeTreeSource::onCancel()
algorithm->cancel();
}
#if defined(OS_LINUX)
struct MergeTreeSource::AsyncReadingState
{
/// NotStarted -> InProgress -> IsFinished -> NotStarted ...
@ -137,10 +140,11 @@ private:
ThreadPoolCallbackRunner<void> callback_runner;
std::shared_ptr<Control> control;
};
#endif
ISource::Status MergeTreeSource::prepare()
{
#if defined(OS_LINUX)
if (!async_reading_state)
return ISource::prepare();
@ -153,6 +157,7 @@ ISource::Status MergeTreeSource::prepare()
if (async_reading_state && async_reading_state->getStage() == AsyncReadingState::Stage::InProgress)
return ISource::Status::Async;
#endif
return ISource::prepare();
}
@ -172,39 +177,44 @@ std::optional<Chunk> MergeTreeSource::reportProgress(ChunkAndProgress chunk)
std::optional<Chunk> MergeTreeSource::tryGenerate()
{
if (!async_reading_state)
return reportProgress(algorithm->read());
if (async_reading_state->getStage() == AsyncReadingState::Stage::IsFinished)
return reportProgress(async_reading_state->getResult());
chassert(async_reading_state->getStage() == AsyncReadingState::Stage::NotStarted);
/// It is important to store control into job.
/// Otherwise, race between job and ~MergeTreeBaseSelectProcessor is possible.
auto job = [this, control = async_reading_state->start()]() mutable
#if defined(OS_LINUX)
if (async_reading_state)
{
auto holder = std::move(control);
if (async_reading_state->getStage() == AsyncReadingState::Stage::IsFinished)
return reportProgress(async_reading_state->getResult());
try
chassert(async_reading_state->getStage() == AsyncReadingState::Stage::NotStarted);
/// It is important to store control into job.
/// Otherwise, race between job and ~MergeTreeBaseSelectProcessor is possible.
auto job = [this, control = async_reading_state->start()]() mutable
{
holder->setResult(algorithm->read());
}
catch (...)
{
holder->setException(std::current_exception());
}
};
auto holder = std::move(control);
async_reading_state->schedule(std::move(job));
try
{
holder->setResult(algorithm->read());
}
catch (...)
{
holder->setException(std::current_exception());
}
};
return Chunk();
async_reading_state->schedule(std::move(job));
return Chunk();
}
#endif
return reportProgress(algorithm->read());
}
#if defined(OS_LINUX)
int MergeTreeSource::schedule()
{
return async_reading_state->getFD();
}
#endif
}

View File

@ -18,7 +18,10 @@ public:
std::string getName() const override;
Status prepare() override;
#if defined(OS_LINUX)
int schedule() override;
#endif
protected:
std::optional<Chunk> tryGenerate() override;
@ -28,8 +31,10 @@ protected:
private:
MergeTreeSelectAlgorithmPtr algorithm;
#if defined(OS_LINUX)
struct AsyncReadingState;
std::unique_ptr<AsyncReadingState> async_reading_state;
#endif
std::optional<Chunk> reportProgress(ChunkAndProgress chunk);
};