Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions be/src/exec/scan/scanner_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "exec/operator/scan_operator.h"
#include "exec/scan/scan_node.h"
#include "exec/scan/scanner_scheduler.h"
#include "exec/scan/task_executor/task_executor.h"
#include "runtime/descriptors.h"
#include "runtime/exec_env.h"
#include "runtime/runtime_profile.h"
Expand Down Expand Up @@ -123,6 +124,7 @@ Status ScannerContext::init() {
if (auto* task_executor_scheduler =
dynamic_cast<TaskExecutorSimplifiedScanScheduler*>(_scanner_scheduler)) {
std::shared_ptr<TaskExecutor> task_executor = task_executor_scheduler->task_executor();
_task_executor = task_executor;
TaskId task_id(fmt::format("{}-{}", print_id(_state->query_id()), ctx_id));
_task_handle = DORIS_TRY(task_executor->create_task(
task_id, []() { return 0.0; },
Expand Down Expand Up @@ -187,11 +189,11 @@ ScannerContext::~ScannerContext() {
block.reset();
DorisMetrics::instance()->scanner_ctx_cnt->increment(-1);
if (_task_handle) {
if (auto* task_executor_scheduler =
dynamic_cast<TaskExecutorSimplifiedScanScheduler*>(_scanner_scheduler)) {
static_cast<void>(task_executor_scheduler->task_executor()->remove_task(_task_handle));
if (auto task_executor = _task_executor.lock()) {
static_cast<void>(task_executor->remove_task(_task_handle));
}
_task_handle = nullptr;
_task_executor.reset();
}
}

Expand Down Expand Up @@ -389,11 +391,11 @@ void ScannerContext::stop_scanners(RuntimeState* state) {
}
_tasks_queue.clear();
if (_task_handle) {
if (auto* task_executor_scheduler =
dynamic_cast<TaskExecutorSimplifiedScanScheduler*>(_scanner_scheduler)) {
static_cast<void>(task_executor_scheduler->task_executor()->remove_task(_task_handle));
if (auto task_executor = _task_executor.lock()) {
static_cast<void>(task_executor->remove_task(_task_handle));
}
_task_handle = nullptr;
_task_executor.reset();
}
// TODO yiguolei, call mark close to scanners
if (state->enable_profile()) {
Expand Down
1 change: 1 addition & 0 deletions be/src/exec/scan/scanner_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ class ScannerContext : public std::enable_shared_from_this<ScannerContext>,
std::shared_ptr<ResourceContext> _resource_ctx;
std::shared_ptr<Dependency> _dependency = nullptr;
std::shared_ptr<doris::TaskHandle> _task_handle;
std::weak_ptr<doris::TaskExecutor> _task_executor;

std::atomic<int64_t> _block_memory_usage = 0;

Expand Down
8 changes: 6 additions & 2 deletions be/src/exec/scan/scanner_scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,14 @@ class TaskExecutorSimplifiedScanScheduler final : public ScannerScheduler {
: std::max(48, CpuInfo::num_cores() * 2),
std::chrono::milliseconds(100), std::nullopt));

auto wrapped_scan_func = [this, task_handle, scan_func = scan_task.scan_func]() {
std::weak_ptr<TaskExecutor> task_executor = _task_executor;
auto wrapped_scan_func = [task_executor, task_handle,
scan_func = scan_task.scan_func]() {
bool result = scan_func();
if (result) {
static_cast<void>(_task_executor->remove_task(task_handle));
if (auto executor = task_executor.lock()) {
static_cast<void>(executor->remove_task(task_handle));
}
}
return result;
};
Expand Down
Loading