yiguolei commented on code in PR #47783: URL: https://github.com/apache/doris/pull/47783#discussion_r1956202969
########## be/test/scan/scanner_context_test.cpp: ########## @@ -0,0 +1,603 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "vec/exec/scan/scanner_context.h" + +#include <gen_cpp/Descriptors_types.h> +#include <gen_cpp/Metrics_types.h> +#include <gen_cpp/PaloInternalService_types.h> +#include <gen_cpp/Types_types.h> +#include <gtest/gtest.h> + +#include <list> +#include <memory> +#include <mutex> +#include <tuple> + +#include "common/object_pool.h" +#include "mock_scanner_scheduler.h" +#include "mock_simplified_scan_scheduler.h" +#include "pipeline/dependency.h" +#include "pipeline/exec/olap_scan_operator.h" +#include "runtime/descriptors.h" +#include "vec/core/block.h" +#include "vec/exec/scan/new_olap_scanner.h" +#include "vec/exec/scan/scanner_scheduler.h" +#include "vec/exec/scan/vscan_node.h" + +namespace doris::vectorized { +class ScannerContextTest : public testing::Test { +public: + void SetUp() override { + obj_pool = std::make_unique<ObjectPool>(); + // This ScanNode has two tuples. + // First one is input tuple, second one is output tuple. + tnode.row_tuples.push_back(TTupleId(0)); + tnode.row_tuples.push_back(TTupleId(1)); + tbl_desc.tableType = TTableType::OLAP_TABLE; + + tuple_desc.id = 0; + tuple_descs.push_back(tuple_desc); + tuple_desc.id = 1; + tuple_descs.push_back(tuple_desc); + + type_node.type = TTypeNodeType::SCALAR; + + scalar_type.__set_type(TPrimitiveType::STRING); + type_node.__set_scalar_type(scalar_type); + slot_desc.slotType.types.push_back(type_node); + slot_desc.id = 0; + slot_desc.parent = 0; + slot_descs.push_back(slot_desc); + slot_desc.id = 1; + slot_desc.parent = 1; + slot_descs.push_back(slot_desc); + std::vector<bool> null_map {false, false}; + tnode.nullable_tuples = null_map; + thrift_tbl.tableDescriptors.push_back(tbl_desc); + thrift_tbl.tupleDescriptors = tuple_descs; + thrift_tbl.slotDescriptors = slot_descs; + std::ignore = DescriptorTbl::create(obj_pool.get(), thrift_tbl, &descs); + auto task_exec_ctx = std::make_shared<TaskExecutionContext>(); + state->set_task_execution_context(task_exec_ctx); + output_tuple_desc = descs->get_tuple_descriptor(0); + } + +private: + std::unique_ptr<ObjectPool> obj_pool; + TPlanNode tnode; + TTableDescriptor tbl_desc; + std::vector<TTupleDescriptor> tuple_descs; + TTupleDescriptor tuple_desc; + std::vector<TSlotDescriptor> slot_descs; + TSlotDescriptor slot_desc; + TTypeNode type_node; + TScalarType scalar_type; + TDescriptorTable thrift_tbl; + DescriptorTbl* descs = nullptr; + std::unique_ptr<RuntimeState> state = std::make_unique<RuntimeState>(); + std::unique_ptr<RuntimeProfile> profile = std::make_unique<RuntimeProfile>("TestProfile"); + std::unique_ptr<RuntimeProfile::Counter> max_concurrency_counter = + std::make_unique<RuntimeProfile::Counter>(TUnit::UNIT, 1, 3); + std::unique_ptr<RuntimeProfile::Counter> min_concurrency_counter = + std::make_unique<RuntimeProfile::Counter>(TUnit::UNIT, 1, 3); + TupleDescriptor* output_tuple_desc = nullptr; + RowDescriptor* output_row_descriptor = nullptr; + std::shared_ptr<pipeline::Dependency> scan_dependency = + pipeline::Dependency::create_shared(0, 0, "TestScanDependency"); + std::shared_ptr<CgroupCpuCtl> cgroup_cpu_ctl = std::make_shared<CgroupV2CpuCtl>(1); + std::unique_ptr<SimplifiedScanScheduler> scan_scheduler = + std::make_unique<SimplifiedScanScheduler>("ForTest", cgroup_cpu_ctl); +}; + +TEST_F(ScannerContextTest, test_init) { + const int parallel_tasks = 1; + auto scan_operator = std::make_unique<pipeline::OlapScanOperatorX>( + obj_pool.get(), tnode, 0, *descs, parallel_tasks, TQueryCacheParam {}); + + auto olap_scan_local_state = + pipeline::OlapScanLocalState::create_unique(state.get(), scan_operator.get()); + + const int64_t limit = 100; + + NewOlapScanner::Params scanner_params; + scanner_params.state = state.get(); + scanner_params.profile = profile.get(); + scanner_params.limit = limit; + scanner_params.key_ranges = std::vector<OlapScanRange*>(); // empty + + std::shared_ptr<VScanner> scanner = + NewOlapScanner::create_shared(olap_scan_local_state.get(), std::move(scanner_params)); + + std::list<std::shared_ptr<ScannerDelegate>> scanners; + for (int i = 0; i < 11; ++i) { + scanners.push_back(std::make_shared<ScannerDelegate>(scanner)); + } + + std::shared_ptr<ScannerContext> scanner_context = ScannerContext::create_shared( + state.get(), olap_scan_local_state.get(), output_tuple_desc, output_row_descriptor, + scanners, limit, scan_dependency, parallel_tasks); + + scan_operator->_should_run_serial = false; + + olap_scan_local_state->_max_scan_concurrency = max_concurrency_counter.get(); + olap_scan_local_state->_min_scan_concurrency = min_concurrency_counter.get(); + + olap_scan_local_state->_parent = scan_operator.get(); + + TQueryOptions query_options; + query_options.__set_num_scanner_threads(2); + query_options.__set_max_column_reader_num(0); + state->set_query_options(query_options); + std::unique_ptr<MockSimplifiedScanScheduler> scheduler = + std::make_unique<MockSimplifiedScanScheduler>(cgroup_cpu_ctl); + EXPECT_CALL(*scheduler, schedule_scan_task(testing::_, testing::_, testing::_)) + .WillRepeatedly(testing::Return(Status::OK())); + scanner_context->_scanner_scheduler = scheduler.get(); + + scanner_context->_min_scan_concurrency_of_scan_scheduler = 10; + Status st = scanner_context->init(); + ASSERT_TRUE(st.ok()); + ASSERT_EQ(scanner_context->_max_scan_concurrency, 2); + + query_options.__set_num_scanner_threads(0); + state->set_query_options(query_options); + + st = scanner_context->init(); + ASSERT_TRUE(st.ok()); + + ASSERT_EQ(scanner_context->_max_scan_concurrency, + scanner_context->_min_scan_concurrency_of_scan_scheduler / parallel_tasks); +} + +TEST_F(ScannerContextTest, test_serial_run) { Review Comment: 补充一下limit 的测试,比如不带where 条件的时候,max scanner = 1;带where 条件的时候,不影响;补充测试,假如用户设置了max scanner,那么我们自己推断的原来可能比较多scanner的时候,会受max scanner 限制 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org