github-actions[bot] commented on code in PR #23053: URL: https://github.com/apache/doris/pull/23053#discussion_r1295618871
########## be/test/olap/wal_manager_test.cpp: ########## @@ -0,0 +1,192 @@ +// 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 "olap/wal_manager.h" + +#include <filesystem> +#include <map> +#include <string> +#include <vector> + +#include "common/config.h" +#include "gen_cpp/HeartbeatService_types.h" +#include "gen_cpp/internal_service.pb.h" +#include "gtest/gtest.h" +#include "io/fs/local_file_system.h" +#include "runtime/decimalv2_value.h" +#include "runtime/exec_env.h" +#include "runtime/result_queue_mgr.h" +#include "runtime/runtime_state.h" +#include "runtime/stream_load/new_load_stream_mgr.h" +#include "runtime/types.h" +#include "service/brpc.h" +#include "util/brpc_client_cache.h" +#include "util/cpu_info.h" +#include "util/debug/leakcheck_disabler.h" +#include "util/proto_util.h" + +namespace doris { + +extern TCheckWalResult k_check_wal_result; +extern TLoadTxnBeginResult k_stream_load_begin_result; +extern Status k_stream_load_plan_status; + +class WalManagerTest : public testing::Test { +public: + WalManagerTest() {} Review Comment: warning: use '= default' to define a trivial default constructor [modernize-use-equals-default] ```suggestion WalManagerTest() = default; ``` ########## be/test/olap/wal_manager_test.cpp: ########## @@ -0,0 +1,192 @@ +// 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 "olap/wal_manager.h" + +#include <filesystem> +#include <map> +#include <string> +#include <vector> + +#include "common/config.h" +#include "gen_cpp/HeartbeatService_types.h" +#include "gen_cpp/internal_service.pb.h" +#include "gtest/gtest.h" +#include "io/fs/local_file_system.h" +#include "runtime/decimalv2_value.h" +#include "runtime/exec_env.h" +#include "runtime/result_queue_mgr.h" +#include "runtime/runtime_state.h" +#include "runtime/stream_load/new_load_stream_mgr.h" +#include "runtime/types.h" +#include "service/brpc.h" +#include "util/brpc_client_cache.h" +#include "util/cpu_info.h" +#include "util/debug/leakcheck_disabler.h" +#include "util/proto_util.h" + +namespace doris { + +extern TCheckWalResult k_check_wal_result; +extern TLoadTxnBeginResult k_stream_load_begin_result; +extern Status k_stream_load_plan_status; + +class WalManagerTest : public testing::Test { +public: + WalManagerTest() {} + virtual ~WalManagerTest() {} Review Comment: warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [modernize-use-override] ```suggestion ~WalManagerTest() override {} ``` ########## be/test/olap/wal_manager_test.cpp: ########## @@ -0,0 +1,192 @@ +// 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 "olap/wal_manager.h" Review Comment: warning: 'olap/wal_manager.h' file not found [clang-diagnostic-error] ```cpp #include "olap/wal_manager.h" ^ ``` ########## be/test/olap/wal_manager_test.cpp: ########## @@ -0,0 +1,192 @@ +// 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 "olap/wal_manager.h" + +#include <filesystem> +#include <map> +#include <string> +#include <vector> + +#include "common/config.h" +#include "gen_cpp/HeartbeatService_types.h" +#include "gen_cpp/internal_service.pb.h" +#include "gtest/gtest.h" +#include "io/fs/local_file_system.h" +#include "runtime/decimalv2_value.h" +#include "runtime/exec_env.h" +#include "runtime/result_queue_mgr.h" +#include "runtime/runtime_state.h" +#include "runtime/stream_load/new_load_stream_mgr.h" +#include "runtime/types.h" +#include "service/brpc.h" +#include "util/brpc_client_cache.h" +#include "util/cpu_info.h" +#include "util/debug/leakcheck_disabler.h" +#include "util/proto_util.h" + +namespace doris { + +extern TCheckWalResult k_check_wal_result; +extern TLoadTxnBeginResult k_stream_load_begin_result; +extern Status k_stream_load_plan_status; + +class WalManagerTest : public testing::Test { +public: + WalManagerTest() {} + virtual ~WalManagerTest() {} + void SetUp() override { + prepare(); + _env = ExecEnv::GetInstance(); + _env->_master_info = new TMasterInfo(); + _env->_master_info->network_address.hostname = "host name"; + _env->_master_info->network_address.port = 1234; + _env->new_load_stream_mgr() = NewLoadStreamMgr::create_shared(); + _env->_internal_client_cache = new BrpcClientCache<PBackendService_Stub>(); + _env->_function_client_cache = new BrpcClientCache<PFunctionService_Stub>(); + _env->_stream_load_executor = StreamLoadExecutor::create_shared(_env); + _env->_wal_manager = new WalManager(_env, wal_dir); + k_check_wal_result = TCheckWalResult(); + k_stream_load_begin_result = TLoadTxnBeginResult(); + k_stream_load_plan_status = Status::OK(); + } + void TearDown() override { + io::global_local_filesystem()->delete_directory(wal_dir); + SAFE_DELETE(_env->_wal_manager); + SAFE_DELETE(_env->_function_client_cache); + SAFE_DELETE(_env->_internal_client_cache); + SAFE_DELETE(_env->_master_info); + } + + void prepare() { io::global_local_filesystem()->create_directory(wal_dir); } + + void createWal(const std::string& wal_path) { + auto wal_writer = WalWriter(wal_path); + wal_writer.init(); + wal_writer.finalize(); + } + +private: + ExecEnv* _env = nullptr; + std::string wal_dir = "./wal_test"; + std::string tmp_dir = "./wal_test/tmp"; +}; + +TEST_F(WalManagerTest, recovery_normal) { + k_check_wal_result.__set_need_recovery(true); + + std::string db_id = "1"; + std::string tb_1_id = "1"; + std::string wal_100_id = "100"; + std::string wal_101_id = "101"; + std::string tb_2_id = "2"; + std::string wal_200_id = "200"; + std::string wal_201_id = "201"; + + std::filesystem::create_directory(wal_dir + "/" + db_id); + std::filesystem::create_directory(wal_dir + "/" + db_id + "/" + tb_1_id); + std::string wal_100 = wal_dir + "/" + db_id + "/" + tb_1_id + "/" + wal_100_id; + std::string wal_101 = wal_dir + "/" + db_id + "/" + tb_1_id + "/" + wal_101_id; + createWal(wal_100); + createWal(wal_101); + + std::filesystem::create_directory(wal_dir + "/" + db_id); + std::filesystem::create_directory(wal_dir + "/" + db_id + "/" + tb_2_id); + std::string wal_200 = wal_dir + "/" + db_id + "/" + tb_2_id + "/" + wal_200_id; + std::string wal_201 = wal_dir + "/" + db_id + "/" + tb_2_id + "/" + wal_201_id; + createWal(wal_200); + createWal(wal_201); + _env->wal_mgr()->init(); + + while (_env->_wal_manager->get_wal_table_size(tb_1_id) > 0 || + _env->_wal_manager->get_wal_table_size(tb_2_id) > 0) { + sleep(1); + continue; + } Review Comment: warning: redundant continue statement at the end of loop statement [readability-redundant-control-flow] ```suggestion } ``` ########## be/test/olap/wal_reader_writer_test.cpp: ########## @@ -0,0 +1,146 @@ +// 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 <filesystem> + +#include "agent/be_exec_version_manager.h" +#include "common/logging.h" +#include "common/object_pool.h" +#include "gen_cpp/internal_service.pb.h" +#include "gmock/gmock.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/service.h" +#include "gtest/gtest.h" +#include "io/fs/local_file_system.h" +#include "olap/wal_reader.h" +#include "olap/wal_writer.h" +#include "runtime/exec_env.h" +#include "service/brpc.h" +#include "testutil/desc_tbl_builder.h" +#include "testutil/test_util.h" +#include "util/proto_util.h" +#include "vec/columns/columns_number.h" +#include "vec/core/types.h" +#include "vec/data_types/data_type_number.h" +#include "vec/runtime/vdata_stream_mgr.h" +#include "vec/runtime/vdata_stream_recvr.h" +#include "vec/sink/vdata_stream_sender.h" + +#ifndef BE_TEST +#define BE_TEST +#endif + +using ::testing::_; +using ::testing::Return; +using ::testing::SetArgPointee; +using std::string; + +namespace doris { + +class WalReaderWriterTest : public testing::Test { +public: + // create a mock cgroup folder + virtual void SetUp() { io::global_local_filesystem()->create_directory(_s_test_data_path); } Review Comment: warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [modernize-use-override] ```suggestion void SetUp() override { io::global_local_filesystem()->create_directory(_s_test_data_path); } ``` ########## be/test/olap/wal_manager_test.cpp: ########## @@ -0,0 +1,192 @@ +// 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 "olap/wal_manager.h" + +#include <filesystem> +#include <map> +#include <string> +#include <vector> + +#include "common/config.h" +#include "gen_cpp/HeartbeatService_types.h" +#include "gen_cpp/internal_service.pb.h" +#include "gtest/gtest.h" +#include "io/fs/local_file_system.h" +#include "runtime/decimalv2_value.h" +#include "runtime/exec_env.h" +#include "runtime/result_queue_mgr.h" +#include "runtime/runtime_state.h" +#include "runtime/stream_load/new_load_stream_mgr.h" +#include "runtime/types.h" +#include "service/brpc.h" +#include "util/brpc_client_cache.h" +#include "util/cpu_info.h" +#include "util/debug/leakcheck_disabler.h" +#include "util/proto_util.h" + +namespace doris { + +extern TCheckWalResult k_check_wal_result; +extern TLoadTxnBeginResult k_stream_load_begin_result; +extern Status k_stream_load_plan_status; + +class WalManagerTest : public testing::Test { +public: + WalManagerTest() {} + virtual ~WalManagerTest() {} + void SetUp() override { + prepare(); + _env = ExecEnv::GetInstance(); + _env->_master_info = new TMasterInfo(); + _env->_master_info->network_address.hostname = "host name"; + _env->_master_info->network_address.port = 1234; + _env->new_load_stream_mgr() = NewLoadStreamMgr::create_shared(); + _env->_internal_client_cache = new BrpcClientCache<PBackendService_Stub>(); + _env->_function_client_cache = new BrpcClientCache<PFunctionService_Stub>(); + _env->_stream_load_executor = StreamLoadExecutor::create_shared(_env); + _env->_wal_manager = new WalManager(_env, wal_dir); + k_check_wal_result = TCheckWalResult(); + k_stream_load_begin_result = TLoadTxnBeginResult(); + k_stream_load_plan_status = Status::OK(); + } + void TearDown() override { + io::global_local_filesystem()->delete_directory(wal_dir); + SAFE_DELETE(_env->_wal_manager); + SAFE_DELETE(_env->_function_client_cache); + SAFE_DELETE(_env->_internal_client_cache); + SAFE_DELETE(_env->_master_info); + } + + void prepare() { io::global_local_filesystem()->create_directory(wal_dir); } + + void createWal(const std::string& wal_path) { + auto wal_writer = WalWriter(wal_path); + wal_writer.init(); + wal_writer.finalize(); + } + +private: + ExecEnv* _env = nullptr; + std::string wal_dir = "./wal_test"; + std::string tmp_dir = "./wal_test/tmp"; +}; + +TEST_F(WalManagerTest, recovery_normal) { + k_check_wal_result.__set_need_recovery(true); + + std::string db_id = "1"; + std::string tb_1_id = "1"; + std::string wal_100_id = "100"; + std::string wal_101_id = "101"; + std::string tb_2_id = "2"; + std::string wal_200_id = "200"; + std::string wal_201_id = "201"; + + std::filesystem::create_directory(wal_dir + "/" + db_id); + std::filesystem::create_directory(wal_dir + "/" + db_id + "/" + tb_1_id); + std::string wal_100 = wal_dir + "/" + db_id + "/" + tb_1_id + "/" + wal_100_id; + std::string wal_101 = wal_dir + "/" + db_id + "/" + tb_1_id + "/" + wal_101_id; + createWal(wal_100); + createWal(wal_101); + + std::filesystem::create_directory(wal_dir + "/" + db_id); + std::filesystem::create_directory(wal_dir + "/" + db_id + "/" + tb_2_id); + std::string wal_200 = wal_dir + "/" + db_id + "/" + tb_2_id + "/" + wal_200_id; + std::string wal_201 = wal_dir + "/" + db_id + "/" + tb_2_id + "/" + wal_201_id; + createWal(wal_200); + createWal(wal_201); + _env->wal_mgr()->init(); + + while (_env->_wal_manager->get_wal_table_size(tb_1_id) > 0 || + _env->_wal_manager->get_wal_table_size(tb_2_id) > 0) { + sleep(1); + continue; + } + ASSERT_TRUE(!std::filesystem::exists(wal_100)); + ASSERT_TRUE(!std::filesystem::exists(wal_101)); + ASSERT_TRUE(!std::filesystem::exists(wal_200)); + ASSERT_TRUE(!std::filesystem::exists(wal_201)); +} + +TEST_F(WalManagerTest, not_need_recovery) { + std::string db_id = "1"; + std::string tb_id = "1"; + std::string wal_id = "100"; + std::filesystem::create_directory(wal_dir + "/" + db_id); + std::filesystem::create_directory(wal_dir + "/" + db_id + "/" + tb_id); + std::string wal_100 = wal_dir + "/" + db_id + "/" + tb_id + "/" + wal_id; + createWal(wal_100); + + _env->wal_mgr()->init(); + + while (_env->_wal_manager->get_wal_table_size("1") > 0) { + sleep(1); + continue; + } Review Comment: warning: redundant continue statement at the end of loop statement [readability-redundant-control-flow] ```suggestion } ``` ########## be/test/olap/wal_reader_writer_test.cpp: ########## @@ -0,0 +1,146 @@ +// 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 <filesystem> + +#include "agent/be_exec_version_manager.h" +#include "common/logging.h" +#include "common/object_pool.h" +#include "gen_cpp/internal_service.pb.h" +#include "gmock/gmock.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/service.h" +#include "gtest/gtest.h" +#include "io/fs/local_file_system.h" +#include "olap/wal_reader.h" +#include "olap/wal_writer.h" +#include "runtime/exec_env.h" +#include "service/brpc.h" +#include "testutil/desc_tbl_builder.h" +#include "testutil/test_util.h" +#include "util/proto_util.h" +#include "vec/columns/columns_number.h" +#include "vec/core/types.h" +#include "vec/data_types/data_type_number.h" +#include "vec/runtime/vdata_stream_mgr.h" +#include "vec/runtime/vdata_stream_recvr.h" +#include "vec/sink/vdata_stream_sender.h" + +#ifndef BE_TEST +#define BE_TEST +#endif + +using ::testing::_; +using ::testing::Return; +using ::testing::SetArgPointee; +using std::string; + +namespace doris { + +class WalReaderWriterTest : public testing::Test { +public: + // create a mock cgroup folder + virtual void SetUp() { io::global_local_filesystem()->create_directory(_s_test_data_path); } + + // delete the mock cgroup folder + virtual void TearDown() { io::global_local_filesystem()->delete_directory(_s_test_data_path); } Review Comment: warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [modernize-use-override] ```suggestion void TearDown() override { io::global_local_filesystem()->delete_directory(_s_test_data_path); } ``` ########## be/test/olap/wal_manager_test.cpp: ########## @@ -0,0 +1,192 @@ +// 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 "olap/wal_manager.h" + +#include <filesystem> +#include <map> +#include <string> +#include <vector> + +#include "common/config.h" +#include "gen_cpp/HeartbeatService_types.h" +#include "gen_cpp/internal_service.pb.h" +#include "gtest/gtest.h" +#include "io/fs/local_file_system.h" +#include "runtime/decimalv2_value.h" +#include "runtime/exec_env.h" +#include "runtime/result_queue_mgr.h" +#include "runtime/runtime_state.h" +#include "runtime/stream_load/new_load_stream_mgr.h" +#include "runtime/types.h" +#include "service/brpc.h" +#include "util/brpc_client_cache.h" +#include "util/cpu_info.h" +#include "util/debug/leakcheck_disabler.h" +#include "util/proto_util.h" + +namespace doris { + +extern TCheckWalResult k_check_wal_result; +extern TLoadTxnBeginResult k_stream_load_begin_result; +extern Status k_stream_load_plan_status; + +class WalManagerTest : public testing::Test { +public: + WalManagerTest() {} + virtual ~WalManagerTest() {} Review Comment: warning: use '= default' to define a trivial destructor [modernize-use-equals-default] ```suggestion virtual ~WalManagerTest() = default; ``` ########## be/test/olap/wal_manager_test.cpp: ########## @@ -0,0 +1,192 @@ +// 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 "olap/wal_manager.h" + +#include <filesystem> +#include <map> +#include <string> +#include <vector> + +#include "common/config.h" +#include "gen_cpp/HeartbeatService_types.h" +#include "gen_cpp/internal_service.pb.h" +#include "gtest/gtest.h" +#include "io/fs/local_file_system.h" +#include "runtime/decimalv2_value.h" +#include "runtime/exec_env.h" +#include "runtime/result_queue_mgr.h" +#include "runtime/runtime_state.h" +#include "runtime/stream_load/new_load_stream_mgr.h" +#include "runtime/types.h" +#include "service/brpc.h" +#include "util/brpc_client_cache.h" +#include "util/cpu_info.h" +#include "util/debug/leakcheck_disabler.h" +#include "util/proto_util.h" + +namespace doris { + +extern TCheckWalResult k_check_wal_result; +extern TLoadTxnBeginResult k_stream_load_begin_result; +extern Status k_stream_load_plan_status; + +class WalManagerTest : public testing::Test { +public: + WalManagerTest() {} + virtual ~WalManagerTest() {} + void SetUp() override { + prepare(); + _env = ExecEnv::GetInstance(); + _env->_master_info = new TMasterInfo(); + _env->_master_info->network_address.hostname = "host name"; + _env->_master_info->network_address.port = 1234; + _env->new_load_stream_mgr() = NewLoadStreamMgr::create_shared(); + _env->_internal_client_cache = new BrpcClientCache<PBackendService_Stub>(); + _env->_function_client_cache = new BrpcClientCache<PFunctionService_Stub>(); + _env->_stream_load_executor = StreamLoadExecutor::create_shared(_env); + _env->_wal_manager = new WalManager(_env, wal_dir); + k_check_wal_result = TCheckWalResult(); + k_stream_load_begin_result = TLoadTxnBeginResult(); + k_stream_load_plan_status = Status::OK(); + } + void TearDown() override { + io::global_local_filesystem()->delete_directory(wal_dir); + SAFE_DELETE(_env->_wal_manager); + SAFE_DELETE(_env->_function_client_cache); + SAFE_DELETE(_env->_internal_client_cache); + SAFE_DELETE(_env->_master_info); + } + + void prepare() { io::global_local_filesystem()->create_directory(wal_dir); } + + void createWal(const std::string& wal_path) { + auto wal_writer = WalWriter(wal_path); + wal_writer.init(); + wal_writer.finalize(); + } + +private: + ExecEnv* _env = nullptr; + std::string wal_dir = "./wal_test"; + std::string tmp_dir = "./wal_test/tmp"; +}; + +TEST_F(WalManagerTest, recovery_normal) { + k_check_wal_result.__set_need_recovery(true); + + std::string db_id = "1"; + std::string tb_1_id = "1"; + std::string wal_100_id = "100"; + std::string wal_101_id = "101"; + std::string tb_2_id = "2"; + std::string wal_200_id = "200"; + std::string wal_201_id = "201"; + + std::filesystem::create_directory(wal_dir + "/" + db_id); + std::filesystem::create_directory(wal_dir + "/" + db_id + "/" + tb_1_id); + std::string wal_100 = wal_dir + "/" + db_id + "/" + tb_1_id + "/" + wal_100_id; + std::string wal_101 = wal_dir + "/" + db_id + "/" + tb_1_id + "/" + wal_101_id; + createWal(wal_100); + createWal(wal_101); + + std::filesystem::create_directory(wal_dir + "/" + db_id); + std::filesystem::create_directory(wal_dir + "/" + db_id + "/" + tb_2_id); + std::string wal_200 = wal_dir + "/" + db_id + "/" + tb_2_id + "/" + wal_200_id; + std::string wal_201 = wal_dir + "/" + db_id + "/" + tb_2_id + "/" + wal_201_id; + createWal(wal_200); + createWal(wal_201); + _env->wal_mgr()->init(); + + while (_env->_wal_manager->get_wal_table_size(tb_1_id) > 0 || + _env->_wal_manager->get_wal_table_size(tb_2_id) > 0) { + sleep(1); + continue; + } + ASSERT_TRUE(!std::filesystem::exists(wal_100)); + ASSERT_TRUE(!std::filesystem::exists(wal_101)); + ASSERT_TRUE(!std::filesystem::exists(wal_200)); + ASSERT_TRUE(!std::filesystem::exists(wal_201)); +} + +TEST_F(WalManagerTest, not_need_recovery) { + std::string db_id = "1"; + std::string tb_id = "1"; + std::string wal_id = "100"; + std::filesystem::create_directory(wal_dir + "/" + db_id); + std::filesystem::create_directory(wal_dir + "/" + db_id + "/" + tb_id); + std::string wal_100 = wal_dir + "/" + db_id + "/" + tb_id + "/" + wal_id; + createWal(wal_100); + + _env->wal_mgr()->init(); + + while (_env->_wal_manager->get_wal_table_size("1") > 0) { + sleep(1); + continue; + } + ASSERT_TRUE(!std::filesystem::exists(wal_100)); +} + +TEST_F(WalManagerTest, begin_txn_fail) { + Status status = Status::InternalError("TestFail"); + status.to_thrift(&k_stream_load_begin_result.status); + k_check_wal_result.__set_need_recovery(true); + config::group_commit_replay_wal_retry_num = 3; + + std::string db_id = "1"; + std::string tb_id = "1"; + std::string wal_id = "100"; + std::filesystem::create_directory(wal_dir + "/" + db_id); + std::filesystem::create_directory(wal_dir + "/" + db_id + "/" + tb_id); + std::string wal_100 = wal_dir + "/" + db_id + "/" + tb_id + "/" + wal_id; + createWal(wal_100); + + _env->wal_mgr()->init(); + + while (_env->_wal_manager->get_wal_table_size("1") > 0) { + sleep(1); + continue; + } Review Comment: warning: redundant continue statement at the end of loop statement [readability-redundant-control-flow] ```suggestion } ``` ########## be/test/olap/wal_manager_test.cpp: ########## @@ -0,0 +1,192 @@ +// 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 "olap/wal_manager.h" + +#include <filesystem> +#include <map> +#include <string> +#include <vector> + +#include "common/config.h" +#include "gen_cpp/HeartbeatService_types.h" +#include "gen_cpp/internal_service.pb.h" +#include "gtest/gtest.h" +#include "io/fs/local_file_system.h" +#include "runtime/decimalv2_value.h" +#include "runtime/exec_env.h" +#include "runtime/result_queue_mgr.h" +#include "runtime/runtime_state.h" +#include "runtime/stream_load/new_load_stream_mgr.h" +#include "runtime/types.h" +#include "service/brpc.h" +#include "util/brpc_client_cache.h" +#include "util/cpu_info.h" +#include "util/debug/leakcheck_disabler.h" +#include "util/proto_util.h" + +namespace doris { + +extern TCheckWalResult k_check_wal_result; +extern TLoadTxnBeginResult k_stream_load_begin_result; +extern Status k_stream_load_plan_status; + +class WalManagerTest : public testing::Test { +public: + WalManagerTest() {} + virtual ~WalManagerTest() {} + void SetUp() override { + prepare(); + _env = ExecEnv::GetInstance(); + _env->_master_info = new TMasterInfo(); + _env->_master_info->network_address.hostname = "host name"; + _env->_master_info->network_address.port = 1234; + _env->new_load_stream_mgr() = NewLoadStreamMgr::create_shared(); + _env->_internal_client_cache = new BrpcClientCache<PBackendService_Stub>(); + _env->_function_client_cache = new BrpcClientCache<PFunctionService_Stub>(); + _env->_stream_load_executor = StreamLoadExecutor::create_shared(_env); + _env->_wal_manager = new WalManager(_env, wal_dir); + k_check_wal_result = TCheckWalResult(); + k_stream_load_begin_result = TLoadTxnBeginResult(); + k_stream_load_plan_status = Status::OK(); + } + void TearDown() override { + io::global_local_filesystem()->delete_directory(wal_dir); + SAFE_DELETE(_env->_wal_manager); + SAFE_DELETE(_env->_function_client_cache); + SAFE_DELETE(_env->_internal_client_cache); + SAFE_DELETE(_env->_master_info); + } + + void prepare() { io::global_local_filesystem()->create_directory(wal_dir); } + + void createWal(const std::string& wal_path) { + auto wal_writer = WalWriter(wal_path); + wal_writer.init(); + wal_writer.finalize(); + } + +private: + ExecEnv* _env = nullptr; + std::string wal_dir = "./wal_test"; + std::string tmp_dir = "./wal_test/tmp"; +}; + +TEST_F(WalManagerTest, recovery_normal) { + k_check_wal_result.__set_need_recovery(true); + + std::string db_id = "1"; + std::string tb_1_id = "1"; + std::string wal_100_id = "100"; + std::string wal_101_id = "101"; + std::string tb_2_id = "2"; + std::string wal_200_id = "200"; + std::string wal_201_id = "201"; + + std::filesystem::create_directory(wal_dir + "/" + db_id); + std::filesystem::create_directory(wal_dir + "/" + db_id + "/" + tb_1_id); + std::string wal_100 = wal_dir + "/" + db_id + "/" + tb_1_id + "/" + wal_100_id; + std::string wal_101 = wal_dir + "/" + db_id + "/" + tb_1_id + "/" + wal_101_id; + createWal(wal_100); + createWal(wal_101); + + std::filesystem::create_directory(wal_dir + "/" + db_id); + std::filesystem::create_directory(wal_dir + "/" + db_id + "/" + tb_2_id); + std::string wal_200 = wal_dir + "/" + db_id + "/" + tb_2_id + "/" + wal_200_id; + std::string wal_201 = wal_dir + "/" + db_id + "/" + tb_2_id + "/" + wal_201_id; + createWal(wal_200); + createWal(wal_201); + _env->wal_mgr()->init(); + + while (_env->_wal_manager->get_wal_table_size(tb_1_id) > 0 || + _env->_wal_manager->get_wal_table_size(tb_2_id) > 0) { + sleep(1); + continue; + } + ASSERT_TRUE(!std::filesystem::exists(wal_100)); + ASSERT_TRUE(!std::filesystem::exists(wal_101)); + ASSERT_TRUE(!std::filesystem::exists(wal_200)); + ASSERT_TRUE(!std::filesystem::exists(wal_201)); +} + +TEST_F(WalManagerTest, not_need_recovery) { + std::string db_id = "1"; + std::string tb_id = "1"; + std::string wal_id = "100"; + std::filesystem::create_directory(wal_dir + "/" + db_id); + std::filesystem::create_directory(wal_dir + "/" + db_id + "/" + tb_id); + std::string wal_100 = wal_dir + "/" + db_id + "/" + tb_id + "/" + wal_id; + createWal(wal_100); + + _env->wal_mgr()->init(); + + while (_env->_wal_manager->get_wal_table_size("1") > 0) { + sleep(1); + continue; + } + ASSERT_TRUE(!std::filesystem::exists(wal_100)); +} + +TEST_F(WalManagerTest, begin_txn_fail) { + Status status = Status::InternalError("TestFail"); + status.to_thrift(&k_stream_load_begin_result.status); + k_check_wal_result.__set_need_recovery(true); + config::group_commit_replay_wal_retry_num = 3; + + std::string db_id = "1"; + std::string tb_id = "1"; + std::string wal_id = "100"; + std::filesystem::create_directory(wal_dir + "/" + db_id); + std::filesystem::create_directory(wal_dir + "/" + db_id + "/" + tb_id); + std::string wal_100 = wal_dir + "/" + db_id + "/" + tb_id + "/" + wal_id; + createWal(wal_100); + + _env->wal_mgr()->init(); + + while (_env->_wal_manager->get_wal_table_size("1") > 0) { + sleep(1); + continue; + } + std::string tmp_file = tmp_dir + "/" + db_id + "_" + tb_id + "_" + wal_id; + ASSERT_TRUE(std::filesystem::exists(tmp_file)); + ASSERT_TRUE(!std::filesystem::exists(wal_100)); +} + +TEST_F(WalManagerTest, execute_plan_fail) { + k_stream_load_plan_status = Status::InternalError("TestFail"); + k_check_wal_result.__set_need_recovery(true); + config::group_commit_replay_wal_retry_num = 3; + + std::string db_id = "1"; + std::string tb_id = "1"; + std::string wal_id = "100"; + std::filesystem::create_directory(wal_dir + "/" + db_id); + std::filesystem::create_directory(wal_dir + "/" + db_id + "/" + tb_id); + std::string wal_100 = wal_dir + "/" + db_id + "/" + tb_id + "/" + wal_id; + createWal(wal_100); + + _env->wal_mgr()->init(); + + while (_env->_wal_manager->get_wal_table_size("1") > 0) { + sleep(1); + continue; + } Review Comment: warning: redundant continue statement at the end of loop statement [readability-redundant-control-flow] ```suggestion } ``` ########## be/test/olap/wal_reader_writer_test.cpp: ########## @@ -0,0 +1,146 @@ +// 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 <filesystem> + +#include "agent/be_exec_version_manager.h" Review Comment: warning: 'agent/be_exec_version_manager.h' file not found [clang-diagnostic-error] ```cpp #include "agent/be_exec_version_manager.h" ^ ``` -- 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