github-actions[bot] commented on code in PR #40171:
URL: https://github.com/apache/doris/pull/40171#discussion_r1737872632


##########
be/src/pipeline/exec/cache_source_operator.h:
##########
@@ -0,0 +1,109 @@
+// 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.
+#pragma once
+
+#include <stdint.h>

Review Comment:
   warning: inclusion of deprecated C++ header 'stdint.h'; consider using 
'cstdint' instead [modernize-deprecated-headers]
   
   ```suggestion
   #include <cstdint>
   ```
   



##########
be/src/pipeline/query_cache/query_cache.cpp:
##########
@@ -0,0 +1,70 @@
+// 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 "query_cache.h"
+
+namespace doris {
+
+std::vector<int>* QueryCacheHandle::get_cache_slot_orders() {
+    DCHECK(_handle);
+    auto result_ptr = reinterpret_cast<LRUHandle*>(_handle)->value;
+    return &((QueryCache::CacheValue*)(result_ptr))->slot_orders;
+}
+
+CacheResult* QueryCacheHandle::get_cache_result() {
+    DCHECK(_handle);
+    auto result_ptr = reinterpret_cast<LRUHandle*>(_handle)->value;

Review Comment:
   warning: 'auto result_ptr' can be declared as 'auto *result_ptr' 
[readability-qualified-auto]
   
   ```suggestion
       auto *result_ptr = reinterpret_cast<LRUHandle*>(_handle)->value;
   ```
   



##########
be/src/pipeline/query_cache/query_cache.h:
##########
@@ -0,0 +1,151 @@
+// 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.
+
+#pragma once
+
+#include <butil/macros.h>

Review Comment:
   warning: 'butil/macros.h' file not found [clang-diagnostic-error]
   ```cpp
   #include <butil/macros.h>
            ^
   ```
   



##########
be/src/pipeline/query_cache/query_cache.h:
##########
@@ -0,0 +1,151 @@
+// 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.
+
+#pragma once
+
+#include <butil/macros.h>
+#include <glog/logging.h>
+#include <stddef.h>

Review Comment:
   warning: inclusion of deprecated C++ header 'stddef.h'; consider using 
'cstddef' instead [modernize-deprecated-headers]
   
   ```suggestion
   #include <cstddef>
   ```
   



##########
be/src/pipeline/exec/cache_sink_operator.h:
##########
@@ -0,0 +1,74 @@
+// 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.
+
+#pragma once
+
+#include <stdint.h>

Review Comment:
   warning: inclusion of deprecated C++ header 'stdint.h'; consider using 
'cstdint' instead [modernize-deprecated-headers]
   
   ```suggestion
   #include <cstdint>
   ```
   



##########
be/src/pipeline/query_cache/query_cache.h:
##########
@@ -0,0 +1,151 @@
+// 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.
+
+#pragma once
+
+#include <butil/macros.h>
+#include <glog/logging.h>
+#include <stddef.h>
+#include <stdint.h>

Review Comment:
   warning: inclusion of deprecated C++ header 'stdint.h'; consider using 
'cstdint' instead [modernize-deprecated-headers]
   
   ```suggestion
   #include <cstdint>
   ```
   



##########
be/src/pipeline/query_cache/query_cache.cpp:
##########
@@ -0,0 +1,70 @@
+// 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 "query_cache.h"
+
+namespace doris {
+
+std::vector<int>* QueryCacheHandle::get_cache_slot_orders() {
+    DCHECK(_handle);
+    auto result_ptr = reinterpret_cast<LRUHandle*>(_handle)->value;
+    return &((QueryCache::CacheValue*)(result_ptr))->slot_orders;
+}
+
+CacheResult* QueryCacheHandle::get_cache_result() {
+    DCHECK(_handle);
+    auto result_ptr = reinterpret_cast<LRUHandle*>(_handle)->value;
+    return &((QueryCache::CacheValue*)(result_ptr))->result;
+}
+
+int64_t QueryCacheHandle::get_cache_version() {
+    DCHECK(_handle);
+    auto result_ptr = reinterpret_cast<LRUHandle*>(_handle)->value;

Review Comment:
   warning: 'auto result_ptr' can be declared as 'auto *result_ptr' 
[readability-qualified-auto]
   
   ```suggestion
       auto *result_ptr = reinterpret_cast<LRUHandle*>(_handle)->value;
   ```
   



##########
be/src/pipeline/query_cache/query_cache.cpp:
##########
@@ -0,0 +1,70 @@
+// 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 "query_cache.h"
+
+namespace doris {
+
+std::vector<int>* QueryCacheHandle::get_cache_slot_orders() {
+    DCHECK(_handle);
+    auto result_ptr = reinterpret_cast<LRUHandle*>(_handle)->value;

Review Comment:
   warning: 'auto result_ptr' can be declared as 'auto *result_ptr' 
[readability-qualified-auto]
   
   ```suggestion
       auto *result_ptr = reinterpret_cast<LRUHandle*>(_handle)->value;
   ```
   



##########
be/src/pipeline/query_cache/query_cache.h:
##########
@@ -0,0 +1,151 @@
+// 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.
+
+#pragma once
+
+#include <butil/macros.h>
+#include <glog/logging.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#include <atomic>
+#include <memory>
+#include <roaring/roaring.hh>
+#include <string>
+
+#include "common/config.h"
+#include "common/status.h"
+#include "io/fs/file_system.h"
+#include "io/fs/path.h"
+#include "olap/lru_cache.h"
+#include "runtime/exec_env.h"
+#include "runtime/memory/lru_cache_policy.h"
+#include "runtime/memory/mem_tracker.h"
+#include "util/slice.h"
+#include "util/time.h"
+
+namespace doris {
+
+using CacheResult = std::vector<vectorized::BlockUPtr>;
+// A handle for mid-result from query lru cache.
+// The handle will automatically release the cache entry when it is destroyed.
+// So the caller need to make sure the handle is valid in lifecycle.
+class QueryCacheHandle {
+public:
+    QueryCacheHandle() = default;
+    QueryCacheHandle(LRUCachePolicy* cache, Cache::Handle* handle)
+            : _cache(cache), _handle(handle) {}
+
+    ~QueryCacheHandle() {
+        if (_handle != nullptr) {
+            CHECK(_cache != nullptr);
+            {
+                SCOPED_SWITCH_THREAD_MEM_TRACKER_LIMITER(
+                        ExecEnv::GetInstance()->query_cache_mem_tracker());
+                _cache->release(_handle);
+            }
+        }
+    }
+
+    QueryCacheHandle(QueryCacheHandle&& other) noexcept {
+        std::swap(_cache, other._cache);
+        std::swap(_handle, other._handle);
+    }
+
+    QueryCacheHandle& operator=(QueryCacheHandle&& other) noexcept {
+        std::swap(_cache, other._cache);
+        std::swap(_handle, other._handle);
+        return *this;
+    }
+
+    std::vector<int>* get_cache_slot_orders();
+
+    CacheResult* get_cache_result();
+
+    int64_t get_cache_version();
+
+private:
+    LRUCachePolicy* _cache = nullptr;
+    Cache::Handle* _handle = nullptr;
+
+    // Don't allow copy and assign
+    DISALLOW_COPY_AND_ASSIGN(QueryCacheHandle);

Review Comment:
   warning: prefer deleting copy constructor and assignment operator over using 
macro 'DISALLOW_COPY_AND_ASSIGN' 
[modernize-replace-disallow-copy-and-assign-macro]
   
   ```suggestion
       QueryCacheHandle(const QueryCacheHandle &) = delete;
   const QueryCacheHandle &operator=(const QueryCacheHandle &) = delete;
   ```
   



##########
be/src/pipeline/query_cache/query_cache.h:
##########
@@ -0,0 +1,151 @@
+// 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.
+
+#pragma once
+
+#include <butil/macros.h>
+#include <glog/logging.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#include <atomic>
+#include <memory>
+#include <roaring/roaring.hh>
+#include <string>
+
+#include "common/config.h"
+#include "common/status.h"
+#include "io/fs/file_system.h"
+#include "io/fs/path.h"
+#include "olap/lru_cache.h"
+#include "runtime/exec_env.h"
+#include "runtime/memory/lru_cache_policy.h"
+#include "runtime/memory/mem_tracker.h"
+#include "util/slice.h"
+#include "util/time.h"
+
+namespace doris {
+
+using CacheResult = std::vector<vectorized::BlockUPtr>;
+// A handle for mid-result from query lru cache.
+// The handle will automatically release the cache entry when it is destroyed.
+// So the caller need to make sure the handle is valid in lifecycle.
+class QueryCacheHandle {
+public:
+    QueryCacheHandle() = default;
+    QueryCacheHandle(LRUCachePolicy* cache, Cache::Handle* handle)
+            : _cache(cache), _handle(handle) {}
+
+    ~QueryCacheHandle() {
+        if (_handle != nullptr) {
+            CHECK(_cache != nullptr);
+            {
+                SCOPED_SWITCH_THREAD_MEM_TRACKER_LIMITER(
+                        ExecEnv::GetInstance()->query_cache_mem_tracker());
+                _cache->release(_handle);
+            }
+        }
+    }
+
+    QueryCacheHandle(QueryCacheHandle&& other) noexcept {
+        std::swap(_cache, other._cache);
+        std::swap(_handle, other._handle);
+    }
+
+    QueryCacheHandle& operator=(QueryCacheHandle&& other) noexcept {
+        std::swap(_cache, other._cache);
+        std::swap(_handle, other._handle);
+        return *this;
+    }
+
+    std::vector<int>* get_cache_slot_orders();
+
+    CacheResult* get_cache_result();
+
+    int64_t get_cache_version();
+
+private:
+    LRUCachePolicy* _cache = nullptr;
+    Cache::Handle* _handle = nullptr;
+
+    // Don't allow copy and assign
+    DISALLOW_COPY_AND_ASSIGN(QueryCacheHandle);
+};
+
+class QueryCache : public LRUCachePolicyTrackingManual {
+public:
+    using LRUCachePolicyTrackingManual::insert;
+
+    struct CacheValue : public LRUCacheValueBase {
+        int64_t version;
+        CacheResult result;
+        std::vector<int> slot_orders;
+
+        CacheValue(int64_t v, CacheResult&& r, const std::vector<int>& so)
+                : LRUCacheValueBase(), version(v), result(std::move(r)), 
slot_orders(so) {}
+    };
+
+    // Create global instance of this class
+    static QueryCache* create_global_cache(size_t capacity, uint32_t 
num_shards = 16) {
+        auto* res = new QueryCache(capacity, num_shards);
+        return res;
+    }
+
+    static Status build_cache_key(const std::vector<TScanRangeParams>& 
scan_ranges,
+                                  const TQueryCacheParam& cache_param, 
std::string* cache_key,
+                                  int64_t* version) {

Review Comment:
   warning: pointer parameter 'version' can be pointer to const 
[readability-non-const-parameter]
   
   ```suggestion
                                     const int64_t* version) {
   ```
   



-- 
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