This is an automated email from the ASF dual-hosted git repository. zouxinyi pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new c82f3ac6819 [enhance](test) inject fault during allocating memory (#34911) c82f3ac6819 is described below commit c82f3ac681909756a560ad6f1fbdd83e3b65c175 Author: zhiqiang <seuhezhiqi...@163.com> AuthorDate: Mon May 20 23:41:12 2024 +0800 [enhance](test) inject fault during allocating memory (#34911) --- be/src/common/config.cpp | 3 +++ be/src/common/config.h | 3 +++ be/src/vec/common/allocator.cpp | 28 ++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/be/src/common/config.cpp b/be/src/common/config.cpp index 76e5dbcf838..07ec3df598f 100644 --- a/be/src/common/config.cpp +++ b/be/src/common/config.cpp @@ -1268,6 +1268,9 @@ DEFINE_mInt64(hdfs_jni_write_max_retry_time, "3"); DEFINE_Int64(min_nonblock_close_thread_num, "12"); // The max thread num for NonBlockCloseThreadPool DEFINE_Int64(max_nonblock_close_thread_num, "64"); +// The possibility that mem allocator throws an exception during memory allocation +// This config is for test usage, be careful when changing it. +DEFINE_mDouble(mem_alloc_fault_probability, "0.0"); // clang-format off #ifdef BE_TEST diff --git a/be/src/common/config.h b/be/src/common/config.h index e1c2ed305d9..b06c45cfef2 100644 --- a/be/src/common/config.h +++ b/be/src/common/config.h @@ -1343,6 +1343,9 @@ DECLARE_mInt64(hdfs_jni_write_max_retry_time); DECLARE_Int64(min_nonblock_close_thread_num); // The max thread num for NonBlockCloseThreadPool DECLARE_Int64(max_nonblock_close_thread_num); +// The possibility that mem allocator throws an exception during memory allocation +// This config is for test usage, be careful when changing it. +DECLARE_mDouble(mem_alloc_fault_probability); #ifdef BE_TEST // test s3 diff --git a/be/src/vec/common/allocator.cpp b/be/src/vec/common/allocator.cpp index 88de7be96e9..a012cdee41a 100644 --- a/be/src/vec/common/allocator.cpp +++ b/be/src/vec/common/allocator.cpp @@ -24,9 +24,12 @@ #include <chrono> // IWYU pragma: keep #include <memory> #include <new> +#include <random> #include <thread> // Allocator is used by too many files. For compilation speed, put dependencies in `.cpp` as much as possible. +#include "common/compiler_util.h" +#include "common/status.h" #include "runtime/fragment_mgr.h" #include "runtime/memory/global_memory_arbitrator.h" #include "runtime/memory/mem_tracker_limiter.h" @@ -47,6 +50,31 @@ void Allocator<clear_memory_, mmap_populate, use_mmap>::sys_memory_check(size_t if (doris::thread_context()->skip_memory_check != 0) { return; } + + if (UNLIKELY(doris::config::mem_alloc_fault_probability > 0.0)) { + std::random_device rd; + std::mt19937 gen(rd()); + std::bernoulli_distribution fault(doris::config::mem_alloc_fault_probability); + if (fault(gen)) { + const std::string injection_err_msg = fmt::format( + "[MemAllocInjectFault] Query {} alloc memory failed due to fault " + "injection.", + print_id(doris::thread_context()->task_id())); + // Print stack trace for debug. + [[maybe_unused]] auto stack_trace_st = + doris::Status::Error<doris::ErrorCode::MEM_ALLOC_FAILED, true>( + injection_err_msg); +#ifndef ENABLE_STACKTRACE + LOG(INFO) << stack_trace_st.to_string(); +#endif + if (!doris::enable_thread_catch_bad_alloc) { + doris::thread_context()->thread_mem_tracker_mgr->cancel_query(injection_err_msg); + } else { + throw doris::Exception(doris::ErrorCode::MEM_ALLOC_FAILED, injection_err_msg); + } + } + } + if (doris::GlobalMemoryArbitrator::is_exceed_hard_mem_limit(size)) { // Only thread attach query, and has not completely waited for thread_wait_gc_max_milliseconds, // will wait for gc, asynchronous cancel or throw bad::alloc. --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org