This is an automated email from the ASF dual-hosted git repository.

gavinchou 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 92e4857309a [fix](sync point) Fix sync point not reg but construct 
default value (#43461)
92e4857309a is described below

commit 92e4857309aaadf51fe7566b4d4f16146855f8b7
Author: deardeng <deng...@selectdb.com>
AuthorDate: Tue Nov 12 10:23:52 2024 +0800

    [fix](sync point) Fix sync point not reg but construct default value 
(#43461)
    
    Fix open ENABLE_INJECTION_POINT complie switch, be log
    
    ```
    W20241107 11:43:11.205868   788 status.h:423] meet error status: 
[IO_ERROR]inject io error
    W20241107 11:43:11.275723   788 status.h:423] meet error status: 
[IO_ERROR]inject io error
    W20241107 11:43:11.415167   788 status.h:423] meet error status: 
[IO_ERROR]inject io error
    W20241107 11:43:11.484220   788 status.h:423] meet error status: 
[IO_ERROR]inject io error
    W20241107 11:43:11.553351   788 status.h:423] meet error status: 
[IO_ERROR]inject io error
    W20241107 11:43:11.622395   788 status.h:423] meet error status: 
[IO_ERROR]inject io error
    W20241107 11:43:11.691509   788 status.h:423] meet error status: 
[IO_ERROR]inject io error
    W20241107 11:43:11.830601   788 status.h:423] meet error status: 
[IO_ERROR]inject io error
    W20241107 11:43:11.899286   788 status.h:423] meet error status: 
[IO_ERROR]inject io error
    W20241107 11:43:11.967985   788 status.h:423] meet error status: 
[IO_ERROR]inject io error
    W20241107 11:43:13.841727  1032 status.h:423] meet error status: 
[IO_ERROR]inject io error
    W20241107 11:43:13.945942  1032 status.h:423] meet error status: 
[IO_ERROR]inject io error
    W20241107 11:43:14.156761  1032 status.h:423] meet error status: 
[IO_ERROR]inject io error
    W20241107 11:43:38.900395  3064 status.h:423] meet error status: 
[IO_ERROR]inject io error
    W20241107 11:43:39.397446  3064 status.h:423] meet error status: 
[IO_ERROR]inject io error
    W20241107 11:43:39.896116  3064 status.h:423] meet error status: 
[IO_ERROR]inject io error
    ```
    
    For example, in the BE code:
    ```
    TEST_SYNC_POINT_RETURN_WITH_VALUE("LocalFileReader::read_at_impl",
                                       Status::IOError("inject io error"))
    ```
    
    However, this sync point is not used in the BE, although it is used in
    the unit tests. But this macro, when expanded, will construct a default
    value, and Status::IOError will print the stack log as soon as it is
    constructed.
---
 common/cpp/sync_point.cpp | 19 +++++++++++++++++++
 common/cpp/sync_point.h   | 18 +++++++++++++-----
 2 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/common/cpp/sync_point.cpp b/common/cpp/sync_point.cpp
index 18069582f5b..c2263415d30 100644
--- a/common/cpp/sync_point.cpp
+++ b/common/cpp/sync_point.cpp
@@ -50,6 +50,8 @@ public:
   void enable_processing();
   void disable_processing();
   void clear_trace();
+  bool has_point(const std::string& point);
+  bool get_enable();
 private:
   bool disable_by_marker(const std::string& point, std::thread::id thread_id);
 private:
@@ -107,6 +109,13 @@ void SyncPoint::clear_trace() {
 void SyncPoint::process(const std::string& point, std::vector<std::any>&& 
cb_arg) {
   impl_->process(point, std::move(cb_arg));
 }
+bool SyncPoint::has_point(const std::string& point) {
+  return impl_->has_point(point);
+}
+
+bool SyncPoint::get_enable() {
+  return impl_->get_enable();
+}
 
 // 
=============================================================================
 // SyncPoint implementation
@@ -237,6 +246,16 @@ void SyncPoint::Data::disable_processing() {
   enabled_ = false;
 }
 
+bool SyncPoint::Data::has_point(const std::string& point) {
+  std::unique_lock lock(mutex_);
+  auto marked_point_iter = marked_thread_id_.find(point);
+  return marked_point_iter != marked_thread_id_.end();
+}
+
+bool SyncPoint::Data::get_enable() {
+  return enabled_;
+}
+
 } // namespace doris
 // clang-format on
 // vim: et tw=80 ts=2 sw=2 cc=80:
diff --git a/common/cpp/sync_point.h b/common/cpp/sync_point.h
index 0378918f627..25f8a5136cc 100644
--- a/common/cpp/sync_point.h
+++ b/common/cpp/sync_point.h
@@ -153,6 +153,11 @@ public:
   // And/or call registered callback function, with argument `cb_args`
   void process(const std::string& point, std::vector<std::any>&& cb_args = {});
 
+  // Check if this point is registered
+  bool has_point(const std::string& point);
+
+  // Get this point if enabled
+  bool get_enable();
   // TODO: it might be useful to provide a function that blocks until all
   //       sync points are cleared.
   // We want this to be public so we can subclass the implementation
@@ -187,11 +192,14 @@ auto try_any_cast_ret(std::vector<std::any>& any) {
 #define SYNC_POINT_CALLBACK(x, ...) 
doris::SyncPoint::get_instance()->process(x, {__VA_ARGS__})
 #define SYNC_POINT_RETURN_WITH_VALUE(x, default_ret_val, ...) \
 { \
-  std::pair ret {default_ret_val, false}; \
-  std::vector<std::any> args {__VA_ARGS__}; \
-  args.emplace_back(&ret); \
-  doris::SyncPoint::get_instance()->process(x, std::move(args)); \
-  if (ret.second) return std::move(ret.first); \
+  auto sync_point = doris::SyncPoint::get_instance(); \
+  if (sync_point->get_enable() && sync_point->has_point(x)) { \
+    std::pair ret {default_ret_val, false}; \
+    std::vector<std::any> args {__VA_ARGS__}; \
+    args.emplace_back(&ret); \
+    sync_point->process(x, std::move(args)); \
+    if (ret.second) return std::move(ret.first); \
+  } \
 }
 #define SYNC_POINT_RETURN_WITH_VOID(x, ...) \
 { \


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to