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

caiconghui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 7b3865b524 [fix](ut)(vectorized) fix a potential stack overflow bug 
and some unit test (#9140)
7b3865b524 is described below

commit 7b3865b5249977f06df876671f621bec6e3b8bd3
Author: Mingyu Chen <morningman....@gmail.com>
AuthorDate: Thu Apr 21 12:17:03 2022 +0800

    [fix](ut)(vectorized) fix a potential stack overflow bug and some unit test 
(#9140)
---
 be/src/vec/io/var_int.h                            |   2 +-
 be/test/CMakeLists.txt                             |   1 -
 be/test/runtime/free_list_test.cpp                 | 153 ---------------------
 .../apache/doris/common/util/VectorizedUtil.java   |   7 +-
 .../java/org/apache/doris/utframe/DorisAssert.java |   2 +
 5 files changed, 9 insertions(+), 156 deletions(-)

diff --git a/be/src/vec/io/var_int.h b/be/src/vec/io/var_int.h
index b5f675610d..e932c506b7 100644
--- a/be/src/vec/io/var_int.h
+++ b/be/src/vec/io/var_int.h
@@ -125,7 +125,7 @@ inline void read_var_uint(UInt64& x, BufferReadable& buf) {
 }
 
 inline void write_var_uint(UInt64 x, BufferWritable& ostr) {
-    char bytes[8];
+    char bytes[9];
     uint8_t i = 0;
     while (i < 9) {
         uint8_t byte = x & 0x7F;
diff --git a/be/test/CMakeLists.txt b/be/test/CMakeLists.txt
index a1b0cfddbf..c443bcaa95 100644
--- a/be/test/CMakeLists.txt
+++ b/be/test/CMakeLists.txt
@@ -230,7 +230,6 @@ set(RUNTIME_TEST_FILES
     # runtime/export_task_mgr_test.cpp
     # runtime/minidump_test.cpp
     runtime/mem_pool_test.cpp
-    runtime/free_list_test.cpp
     runtime/string_buffer_test.cpp
     runtime/decimalv2_value_test.cpp
     runtime/large_int_value_test.cpp
diff --git a/be/test/runtime/free_list_test.cpp 
b/be/test/runtime/free_list_test.cpp
deleted file mode 100644
index 875c97ad8c..0000000000
--- a/be/test/runtime/free_list_test.cpp
+++ /dev/null
@@ -1,153 +0,0 @@
-// 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 "runtime/free_list.hpp"
-
-#include <gtest/gtest.h>
-
-#include <string>
-
-#include "runtime/mem_pool.h"
-#include "runtime/mem_tracker.h"
-
-namespace doris {
-
-TEST(FreeListTest, Basic) {
-    MemTracker tracker;
-    MemPool pool(&tracker);
-    FreeList list;
-
-    int allocated_size;
-    uint8_t* free_list_mem = list.allocate(FreeList::min_size(), 
&allocated_size);
-    EXPECT_EQ(nullptr, free_list_mem);
-    EXPECT_EQ(allocated_size, 0);
-
-    uint8_t* mem = pool.allocate(FreeList::min_size());
-    EXPECT_TRUE(mem != nullptr);
-
-    list.add(mem, FreeList::min_size());
-    free_list_mem = list.allocate(FreeList::min_size(), &allocated_size);
-    EXPECT_EQ(mem, free_list_mem);
-    EXPECT_EQ(allocated_size, FreeList::min_size());
-
-    free_list_mem = list.allocate(FreeList::min_size(), &allocated_size);
-    EXPECT_EQ(nullptr, free_list_mem);
-    EXPECT_EQ(allocated_size, 0);
-
-    // Make 3 allocations and add them to the free list.
-    // Get them all back from the free list, scribbling to the
-    // returned memory in between.
-    // Attempt a 4th allocation from the free list and make sure
-    // we get nullptr.
-    // Repeat with the same memory blocks.
-    uint8_t* free_list_mem1 = nullptr;
-    uint8_t* free_list_mem2 = nullptr;
-    uint8_t* free_list_mem3 = nullptr;
-
-    mem = pool.allocate(FreeList::min_size());
-    list.add(mem, FreeList::min_size());
-    mem = pool.allocate(FreeList::min_size());
-    list.add(mem, FreeList::min_size());
-    mem = pool.allocate(FreeList::min_size());
-    list.add(mem, FreeList::min_size());
-
-    free_list_mem1 = list.allocate(FreeList::min_size(), &allocated_size);
-    EXPECT_TRUE(free_list_mem1 != nullptr);
-    EXPECT_EQ(allocated_size, FreeList::min_size());
-    bzero(free_list_mem1, FreeList::min_size());
-
-    free_list_mem2 = list.allocate(FreeList::min_size(), &allocated_size);
-    EXPECT_TRUE(free_list_mem2 != nullptr);
-    EXPECT_EQ(allocated_size, FreeList::min_size());
-    bzero(free_list_mem2, FreeList::min_size());
-
-    free_list_mem3 = list.allocate(FreeList::min_size(), &allocated_size);
-    EXPECT_TRUE(free_list_mem3 != nullptr);
-    EXPECT_EQ(allocated_size, FreeList::min_size());
-    bzero(free_list_mem3, FreeList::min_size());
-
-    free_list_mem = list.allocate(FreeList::min_size(), &allocated_size);
-    EXPECT_EQ(nullptr, free_list_mem);
-    EXPECT_EQ(allocated_size, 0);
-
-    list.add(free_list_mem1, FreeList::min_size());
-    list.add(free_list_mem2, FreeList::min_size());
-    list.add(free_list_mem3, FreeList::min_size());
-
-    free_list_mem1 = list.allocate(FreeList::min_size(), &allocated_size);
-    EXPECT_TRUE(free_list_mem1 != nullptr);
-    EXPECT_EQ(allocated_size, FreeList::min_size());
-    bzero(free_list_mem1, FreeList::min_size());
-
-    free_list_mem2 = list.allocate(FreeList::min_size(), &allocated_size);
-    EXPECT_TRUE(free_list_mem2 != nullptr);
-    EXPECT_EQ(allocated_size, FreeList::min_size());
-    bzero(free_list_mem2, FreeList::min_size());
-
-    free_list_mem3 = list.allocate(FreeList::min_size(), &allocated_size);
-    EXPECT_TRUE(free_list_mem3 != nullptr);
-    EXPECT_EQ(allocated_size, FreeList::min_size());
-    bzero(free_list_mem3, FreeList::min_size());
-
-    free_list_mem = list.allocate(FreeList::min_size(), &allocated_size);
-    EXPECT_EQ(nullptr, free_list_mem);
-    EXPECT_EQ(allocated_size, 0);
-
-    // Try some allocations with different sizes
-    int size1 = FreeList::min_size();
-    int size2 = FreeList::min_size() * 2;
-    int size4 = FreeList::min_size() * 4;
-
-    uint8_t* mem1 = pool.allocate(size1);
-    uint8_t* mem2 = pool.allocate(size2);
-    uint8_t* mem4 = pool.allocate(size4);
-
-    list.add(mem2, size2);
-    free_list_mem = list.allocate(size4, &allocated_size);
-    EXPECT_EQ(nullptr, free_list_mem);
-    EXPECT_EQ(allocated_size, 0);
-
-    free_list_mem = list.allocate(size1, &allocated_size);
-    EXPECT_TRUE(free_list_mem != nullptr);
-    EXPECT_EQ(allocated_size, size2);
-    bzero(free_list_mem, size1);
-
-    free_list_mem = list.allocate(size1, &allocated_size);
-    EXPECT_EQ(nullptr, free_list_mem);
-    EXPECT_EQ(allocated_size, 0);
-
-    list.add(mem2, size2);
-    list.add(mem4, size4);
-    list.add(mem1, size1);
-
-    free_list_mem = list.allocate(size4, &allocated_size);
-    EXPECT_EQ(mem4, free_list_mem);
-    EXPECT_EQ(allocated_size, size4);
-    bzero(free_list_mem, size4);
-
-    free_list_mem = list.allocate(size2, &allocated_size);
-    EXPECT_EQ(mem2, free_list_mem);
-    EXPECT_EQ(allocated_size, size2);
-    bzero(free_list_mem, size2);
-
-    free_list_mem = list.allocate(size1, &allocated_size);
-    EXPECT_EQ(mem1, free_list_mem);
-    EXPECT_EQ(allocated_size, size1);
-    bzero(free_list_mem, size1);
-}
-
-} // namespace doris
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/common/util/VectorizedUtil.java 
b/fe/fe-core/src/main/java/org/apache/doris/common/util/VectorizedUtil.java
index b094389db9..4b793a0e9b 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/common/util/VectorizedUtil.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/common/util/VectorizedUtil.java
@@ -19,6 +19,7 @@ package org.apache.doris.common.util;
 
 import org.apache.doris.analysis.Analyzer;
 import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.StmtExecutor;
 
 public class VectorizedUtil {
     /**
@@ -32,7 +33,11 @@ public class VectorizedUtil {
         if (connectContext == null) {
             return false;
         }
-        Analyzer analyzer = connectContext.getExecutor().getAnalyzer();
+        StmtExecutor stmtExecutor = connectContext.getExecutor();
+        if (stmtExecutor == null) {
+            return 
connectContext.getSessionVariable().enableVectorizedEngine();
+        }
+        Analyzer analyzer = stmtExecutor.getAnalyzer();
         if (analyzer == null) {
             return 
connectContext.getSessionVariable().enableVectorizedEngine();
         }
diff --git a/fe/fe-core/src/test/java/org/apache/doris/utframe/DorisAssert.java 
b/fe/fe-core/src/test/java/org/apache/doris/utframe/DorisAssert.java
index f6d763433e..eabaab95c8 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/utframe/DorisAssert.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/utframe/DorisAssert.java
@@ -191,6 +191,8 @@ public class DorisAssert {
 
         private String internalExecute(String sql) throws Exception {
             StmtExecutor stmtExecutor = new StmtExecutor(connectContext, sql);
+            connectContext.setExecutor(stmtExecutor);
+            ConnectContext.get().setExecutor(stmtExecutor);
             stmtExecutor.execute();
             QueryState queryState = connectContext.getState();
             if (queryState.getStateType() == QueryState.MysqlStateType.ERR) {


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

Reply via email to