Skip to content

Commit e679879

Browse files
Gabriel39dataroaring
authored andcommitted
[Improvement](schema scan) Use async scanner for schema scanners (#38403)
1 parent b6dac2c commit e679879

File tree

54 files changed

+163
-69
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+163
-69
lines changed

be/src/exec/schema_scanner.cpp

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@
5151
#include "exec/schema_scanner/schema_workload_groups_scanner.h"
5252
#include "exec/schema_scanner/schema_workload_sched_policy_scanner.h"
5353
#include "olap/hll.h"
54+
#include "pipeline/dependency.h"
5455
#include "runtime/define_primitive_type.h"
56+
#include "runtime/fragment_mgr.h"
57+
#include "runtime/types.h"
5558
#include "util/string_util.h"
5659
#include "util/types.h"
5760
#include "vec/columns/column.h"
@@ -65,6 +68,7 @@
6568
#include "vec/core/column_with_type_and_name.h"
6669
#include "vec/core/types.h"
6770
#include "vec/data_types/data_type.h"
71+
#include "vec/data_types/data_type_factory.hpp"
6872

6973
namespace doris {
7074
class ObjectPool;
@@ -85,7 +89,60 @@ Status SchemaScanner::start(RuntimeState* state) {
8589
return Status::OK();
8690
}
8791

88-
Status SchemaScanner::get_next_block(vectorized::Block* block, bool* eos) {
92+
Status SchemaScanner::get_next_block(RuntimeState* state, vectorized::Block* block, bool* eos) {
93+
if (_data_block == nullptr) {
94+
return Status::InternalError("No data left!");
95+
}
96+
DCHECK(_async_thread_running == false);
97+
RETURN_IF_ERROR(_scanner_status.status());
98+
for (size_t i = 0; i < block->columns(); i++) {
99+
std::move(*block->get_by_position(i).column)
100+
.mutate()
101+
->insert_range_from(*_data_block->get_by_position(i).column, 0,
102+
_data_block->rows());
103+
}
104+
_data_block->clear_column_data();
105+
*eos = _eos;
106+
if (!*eos) {
107+
RETURN_IF_ERROR(get_next_block_async(state));
108+
}
109+
return Status::OK();
110+
}
111+
112+
Status SchemaScanner::get_next_block_async(RuntimeState* state) {
113+
_dependency->block();
114+
auto task_ctx = state->get_task_execution_context();
115+
RETURN_IF_ERROR(ExecEnv::GetInstance()->fragment_mgr()->get_thread_pool()->submit_func(
116+
[this, task_ctx, state]() {
117+
DCHECK(_async_thread_running == false);
118+
auto task_lock = task_ctx.lock();
119+
if (task_lock == nullptr) {
120+
_scanner_status.update(Status::InternalError("Task context not exists!"));
121+
return;
122+
}
123+
SCOPED_ATTACH_TASK(state);
124+
_dependency->block();
125+
_async_thread_running = true;
126+
_finish_dependency->block();
127+
if (!_opened) {
128+
_data_block = vectorized::Block::create_unique();
129+
_init_block(_data_block.get());
130+
_scanner_status.update(start(state));
131+
_opened = true;
132+
}
133+
bool eos = false;
134+
_scanner_status.update(get_next_block_internal(_data_block.get(), &eos));
135+
_eos = eos;
136+
_async_thread_running = false;
137+
_dependency->set_ready();
138+
if (eos) {
139+
_finish_dependency->set_ready();
140+
}
141+
}));
142+
return Status::OK();
143+
}
144+
145+
Status SchemaScanner::get_next_block_internal(vectorized::Block* block, bool* eos) {
89146
if (!_is_init) {
90147
return Status::InternalError("used before initialized.");
91148
}
@@ -176,6 +233,16 @@ std::unique_ptr<SchemaScanner> SchemaScanner::create(TSchemaTableType::type type
176233
}
177234
}
178235

236+
void SchemaScanner::_init_block(vectorized::Block* src_block) {
237+
const std::vector<SchemaScanner::ColumnDesc>& columns_desc(get_column_desc());
238+
for (int i = 0; i < columns_desc.size(); ++i) {
239+
TypeDescriptor descriptor(columns_desc[i].type);
240+
auto data_type = vectorized::DataTypeFactory::instance().create_data_type(descriptor, true);
241+
src_block->insert(vectorized::ColumnWithTypeAndName(data_type->create_column(), data_type,
242+
columns_desc[i].name));
243+
}
244+
}
245+
179246
Status SchemaScanner::fill_dest_column_for_range(vectorized::Block* block, size_t pos,
180247
const std::vector<void*>& datas) {
181248
const ColumnDesc& col_desc = _columns[pos];

be/src/exec/schema_scanner.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <stddef.h>
2323
#include <stdint.h>
2424

25+
#include <condition_variable>
2526
#include <memory>
2627
#include <string>
2728
#include <vector>
@@ -43,6 +44,10 @@ namespace vectorized {
4344
class Block;
4445
}
4546

47+
namespace pipeline {
48+
class Dependency;
49+
}
50+
4651
struct SchemaScannerCommonParam {
4752
SchemaScannerCommonParam()
4853
: db(nullptr),
@@ -94,15 +99,23 @@ class SchemaScanner {
9499

95100
// init object need information, schema etc.
96101
virtual Status init(SchemaScannerParam* param, ObjectPool* pool);
102+
Status get_next_block(RuntimeState* state, vectorized::Block* block, bool* eos);
97103
// Start to work
98104
virtual Status start(RuntimeState* state);
99-
virtual Status get_next_block(vectorized::Block* block, bool* eos);
105+
virtual Status get_next_block_internal(vectorized::Block* block, bool* eos);
100106
const std::vector<ColumnDesc>& get_column_desc() const { return _columns; }
101107
// factory function
102108
static std::unique_ptr<SchemaScanner> create(TSchemaTableType::type type);
103109
TSchemaTableType::type type() const { return _schema_table_type; }
110+
void set_dependency(std::shared_ptr<pipeline::Dependency> dep,
111+
std::shared_ptr<pipeline::Dependency> fin_dep) {
112+
_dependency = dep;
113+
_finish_dependency = fin_dep;
114+
}
115+
Status get_next_block_async(RuntimeState* state);
104116

105117
protected:
118+
void _init_block(vectorized::Block* src_block);
106119
Status fill_dest_column_for_range(vectorized::Block* block, size_t pos,
107120
const std::vector<void*>& datas);
108121

@@ -125,6 +138,15 @@ class SchemaScanner {
125138
RuntimeProfile::Counter* _get_table_timer = nullptr;
126139
RuntimeProfile::Counter* _get_describe_timer = nullptr;
127140
RuntimeProfile::Counter* _fill_block_timer = nullptr;
141+
142+
std::shared_ptr<pipeline::Dependency> _dependency = nullptr;
143+
std::shared_ptr<pipeline::Dependency> _finish_dependency = nullptr;
144+
145+
std::unique_ptr<vectorized::Block> _data_block;
146+
AtomicStatus _scanner_status;
147+
std::atomic<bool> _eos = false;
148+
std::atomic<bool> _opened = false;
149+
std::atomic<bool> _async_thread_running = false;
128150
};
129151

130152
} // namespace doris

be/src/exec/schema_scanner/schema_active_queries_scanner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Status SchemaActiveQueriesScanner::_get_active_queries_block_from_fe() {
137137
return Status::OK();
138138
}
139139

140-
Status SchemaActiveQueriesScanner::get_next_block(vectorized::Block* block, bool* eos) {
140+
Status SchemaActiveQueriesScanner::get_next_block_internal(vectorized::Block* block, bool* eos) {
141141
if (!_is_init) {
142142
return Status::InternalError("Used before initialized.");
143143
}

be/src/exec/schema_scanner/schema_active_queries_scanner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class SchemaActiveQueriesScanner : public SchemaScanner {
3636
~SchemaActiveQueriesScanner() override;
3737

3838
Status start(RuntimeState* state) override;
39-
Status get_next_block(vectorized::Block* block, bool* eos) override;
39+
Status get_next_block_internal(vectorized::Block* block, bool* eos) override;
4040

4141
static std::vector<SchemaScanner::ColumnDesc> _s_tbls_columns;
4242

be/src/exec/schema_scanner/schema_backend_active_tasks.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ Status SchemaBackendActiveTasksScanner::start(RuntimeState* state) {
5151
return Status::OK();
5252
}
5353

54-
Status SchemaBackendActiveTasksScanner::get_next_block(vectorized::Block* block, bool* eos) {
54+
Status SchemaBackendActiveTasksScanner::get_next_block_internal(vectorized::Block* block,
55+
bool* eos) {
5556
if (!_is_init) {
5657
return Status::InternalError("Used before initialized.");
5758
}

be/src/exec/schema_scanner/schema_backend_active_tasks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class SchemaBackendActiveTasksScanner : public SchemaScanner {
3636
~SchemaBackendActiveTasksScanner() override;
3737

3838
Status start(RuntimeState* state) override;
39-
Status get_next_block(vectorized::Block* block, bool* eos) override;
39+
Status get_next_block_internal(vectorized::Block* block, bool* eos) override;
4040

4141
static std::vector<SchemaScanner::ColumnDesc> _s_tbls_columns;
4242

be/src/exec/schema_scanner/schema_charsets_scanner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ SchemaCharsetsScanner::SchemaCharsetsScanner()
4848

4949
SchemaCharsetsScanner::~SchemaCharsetsScanner() {}
5050

51-
Status SchemaCharsetsScanner::get_next_block(vectorized::Block* block, bool* eos) {
51+
Status SchemaCharsetsScanner::get_next_block_internal(vectorized::Block* block, bool* eos) {
5252
if (!_is_init) {
5353
return Status::InternalError("call this before initial.");
5454
}

be/src/exec/schema_scanner/schema_charsets_scanner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class SchemaCharsetsScanner : public SchemaScanner {
3636
SchemaCharsetsScanner();
3737
~SchemaCharsetsScanner() override;
3838

39-
Status get_next_block(vectorized::Block* block, bool* eos) override;
39+
Status get_next_block_internal(vectorized::Block* block, bool* eos) override;
4040

4141
private:
4242
struct CharsetStruct {

be/src/exec/schema_scanner/schema_collations_scanner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ SchemaCollationsScanner::SchemaCollationsScanner()
5050

5151
SchemaCollationsScanner::~SchemaCollationsScanner() {}
5252

53-
Status SchemaCollationsScanner::get_next_block(vectorized::Block* block, bool* eos) {
53+
Status SchemaCollationsScanner::get_next_block_internal(vectorized::Block* block, bool* eos) {
5454
if (!_is_init) {
5555
return Status::InternalError("call this before initial.");
5656
}

be/src/exec/schema_scanner/schema_collations_scanner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class SchemaCollationsScanner : public SchemaScanner {
3636
SchemaCollationsScanner();
3737
~SchemaCollationsScanner() override;
3838

39-
Status get_next_block(vectorized::Block* block, bool* eos) override;
39+
Status get_next_block_internal(vectorized::Block* block, bool* eos) override;
4040

4141
private:
4242
struct CollationStruct {

0 commit comments

Comments
 (0)