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

panxiaolei pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new e8bafdf576 [Bug](upgrade) fix core dump at join node when rolling 
upgrade (#22763)
e8bafdf576 is described below

commit e8bafdf5763a0686883dd2ef732a5371c7a1df85
Author: Pxl <pxl...@qq.com>
AuthorDate: Wed Aug 9 13:27:50 2023 +0800

    [Bug](upgrade) fix core dump at join node when rolling upgrade (#22763)
    
    fix core dump at join node when rolling upgrade
---
 be/src/vec/columns/column_nullable.cpp |  2 +-
 be/src/vec/common/assert_cast.h        | 35 +++++++++++++++++++++++++++++++---
 2 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/be/src/vec/columns/column_nullable.cpp 
b/be/src/vec/columns/column_nullable.cpp
index bda5029c31..6ef951dcd4 100644
--- a/be/src/vec/columns/column_nullable.cpp
+++ b/be/src/vec/columns/column_nullable.cpp
@@ -293,7 +293,7 @@ void ColumnNullable::insert_range_from(const IColumn& src, 
size_t start, size_t
 
 void ColumnNullable::insert_indices_from(const IColumn& src, const int* 
indices_begin,
                                          const int* indices_end) {
-    const ColumnNullable& src_concrete = assert_cast<const 
ColumnNullable&>(src);
+    const ColumnNullable& src_concrete = assert_cast_safe<const 
ColumnNullable&>(src);
     get_nested_column().insert_indices_from(src_concrete.get_nested_column(), 
indices_begin,
                                             indices_end);
     
_get_null_map_column().insert_indices_from(src_concrete.get_null_map_column(), 
indices_begin,
diff --git a/be/src/vec/common/assert_cast.h b/be/src/vec/common/assert_cast.h
index 922cb74c61..a853f8a8ab 100644
--- a/be/src/vec/common/assert_cast.h
+++ b/be/src/vec/common/assert_cast.h
@@ -25,7 +25,9 @@
 #include <typeindex>
 #include <typeinfo>
 
+#include "common/exception.h"
 #include "common/logging.h"
+#include "common/status.h"
 #include "fmt/format.h"
 #include "vec/common/demangle.h"
 
@@ -38,8 +40,10 @@ To assert_cast(From&& from) {
 #ifndef NDEBUG
     try {
         if constexpr (std::is_pointer_v<To>) {
-            if (typeid(*from) == typeid(std::remove_pointer_t<To>)) return 
static_cast<To>(from);
-            if constexpr (std::is_pointer_v<From>) {
+            if (typeid(*from) == typeid(std::remove_pointer_t<To>)) {
+                return static_cast<To>(from);
+            }
+            if constexpr (std::is_pointer_v<std::remove_reference_t<From>>) {
                 if (auto ptr = dynamic_cast<To>(from); ptr != nullptr) {
                     return ptr;
                 }
@@ -48,7 +52,9 @@ To assert_cast(From&& from) {
                                           demangle(typeid(To).name()));
             }
         } else {
-            if (typeid(from) == typeid(To)) return static_cast<To>(from);
+            if (typeid(from) == typeid(To)) {
+                return static_cast<To>(from);
+            }
         }
     } catch (const std::exception& e) {
         LOG(FATAL) << "assert cast err:" << e.what();
@@ -61,3 +67,26 @@ To assert_cast(From&& from) {
     return static_cast<To>(from);
 #endif
 }
+
+// there is a performance loss in the release version, but it can avoid core 
dump
+template <typename To, typename From>
+To assert_cast_safe(From&& from) {
+    if constexpr (std::is_pointer_v<To>) {
+        if (typeid(*from) == typeid(std::remove_pointer_t<To>)) {
+            return static_cast<To>(from);
+        }
+        if constexpr (std::is_pointer_v<std::remove_reference_t<From>>) {
+            if (auto ptr = dynamic_cast<To>(from); ptr != nullptr) {
+                return ptr;
+            }
+            throw doris::Exception(doris::ErrorCode::INTERNAL_ERROR, "Bad cast 
from type:{}* to {}",
+                                   demangle(typeid(*from).name()), 
demangle(typeid(To).name()));
+        }
+    } else {
+        if (typeid(from) == typeid(To)) {
+            return static_cast<To>(from);
+        }
+    }
+    throw doris::Exception(doris::ErrorCode::INTERNAL_ERROR, "Bad cast from 
type:{} to {}",
+                           demangle(typeid(from).name()), 
demangle(typeid(To).name()));
+}


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

Reply via email to