lgbo-ustc commented on code in PR #6558:
URL: https://github.com/apache/incubator-gluten/pull/6558#discussion_r1687688074


##########
cpp-ch/local-engine/Common/QueryContext.cpp:
##########
@@ -33,14 +36,23 @@ namespace ErrorCodes
 namespace local_engine
 {
 using namespace DB;
-thread_local std::shared_ptr<CurrentThread::QueryScope> query_scope;
 thread_local std::shared_ptr<ThreadStatus> thread_status;
-ConcurrentMap<int64_t, NativeAllocatorContextPtr> allocator_map;
+thread_local std::shared_ptr<ThreadGroup> thread_group;
+thread_local ContextMutablePtr query_context;
 
-int64_t initializeQuery(ReservationListenerWrapperPtr listener)
+struct QueryContextSettings

Review Comment:
   `QueryContextSettings`的目的是什么? 这里只有一个字段,容易让人迷惑



##########
cpp-ch/local-engine/Common/QueryContext.h:
##########
@@ -15,30 +15,29 @@
  * limitations under the License.
  */
 #pragma once
-#include <unordered_map>
 #include <Interpreters/Context_fwd.h>
-#include <jni/ReservationListenerWrapper.h>
-#include <Common/CurrentThread.h>
 #include <Common/ThreadStatus.h>
 
 namespace local_engine
 {
-int64_t initializeQuery(ReservationListenerWrapperPtr listener);
-
-void releaseAllocator(int64_t allocator_id);
-
-int64_t allocatorMemoryUsage(int64_t allocator_id);
-
-struct NativeAllocatorContext
+class QueryContextManager
 {
-    std::shared_ptr<DB::CurrentThread::QueryScope> query_scope;
-    std::shared_ptr<DB::ThreadStatus> thread_status;
-    DB::ContextMutablePtr query_context;
-    std::shared_ptr<DB::ThreadGroup> group;
-    ReservationListenerWrapperPtr listener;
-};
+public:
+    static QueryContextManager & instance()
+    {
+        static QueryContextManager instance;
+        return instance;
+    }
+    DB::ContextMutablePtr initializeQuery();
+    DB::ContextMutablePtr currentQueryContext();
+    void logCurrentPerformanceCounters();
+    size_t currentPeakMemory();
+    void finalizeQuery();
 
-using NativeAllocatorContextPtr = std::shared_ptr<NativeAllocatorContext>;
+private:

Review Comment:
   make the constructor be a protected method



##########
cpp-ch/local-engine/Common/QueryContext.cpp:
##########
@@ -33,14 +36,23 @@ namespace ErrorCodes
 namespace local_engine
 {
 using namespace DB;
-thread_local std::shared_ptr<CurrentThread::QueryScope> query_scope;
 thread_local std::shared_ptr<ThreadStatus> thread_status;
-ConcurrentMap<int64_t, NativeAllocatorContextPtr> allocator_map;
+thread_local std::shared_ptr<ThreadGroup> thread_group;
+thread_local ContextMutablePtr query_context;
 
-int64_t initializeQuery(ReservationListenerWrapperPtr listener)
+struct QueryContextSettings
 {
-    if (thread_status) return -1;
-    auto query_context = 
Context::createCopy(SerializedPlanParser::global_context);
+    size_t extra_memory_hard_limit = 0;
+
+    void loadFromContext(ContextPtr context)

Review Comment:
   实现为静态函数是不是更好
   ```c++
   static QueryContextSettingsPtr loadFromContext(ContextPtr context)
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to