marising commented on a change in pull request #4005:
URL: https://github.com/apache/incubator-doris/pull/4005#discussion_r465446439



##########
File path: be/src/runtime/cache/result_node.h
##########
@@ -0,0 +1,197 @@
+// 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.
+
+#ifndef DORIS_BE_SRC_RUNTIME_RESULT_NODE_H
+#define DORIS_BE_SRC_RUNTIME_RESULT_NODE_H
+
+#include <sys/time.h>
+
+#include <algorithm>
+#include <cassert>
+#include <cstdio>
+#include <cstdlib>
+#include <exception>
+#include <iostream>
+#include <list>
+#include <map>
+#include <string>
+
+#include "common/config.h"
+#include "olap/olap_define.h"
+#include "runtime/cache/cache_utils.h"
+#include "runtime/mem_pool.h"
+#include "runtime/row_batch.h"
+#include "runtime/tuple_row.h"
+#include "util/uid_util.h"
+
+namespace doris {
+
+enum PCacheStatus;
+class PCacheParam;
+class PCacheValue;
+class PCacheResponse;
+class PFetchCacheRequest;
+class PFetchCacheResult;
+class PUpdateCacheRequest;
+class PClearCacheRequest;
+
+/**
+* Cache one partition data, request param must match version and time of cache
+*/
+class PartitionRowBatch {
+public:
+    PartitionRowBatch(int64 partition_key)
+            : _partition_key(partition_key), _cache_value(NULL), _data_size(0) 
{}
+
+    ~PartitionRowBatch() {}
+
+    void set_row_batch(const PCacheValue& value);
+    bool is_hit_cache(const PCacheParam& param);
+    void clear();
+
+    int64 get_partition_key() const { return _partition_key; }
+
+    PCacheValue* get_value() { return _cache_value; }
+
+    size_t get_data_size() { return _data_size; }
+
+    const CacheStat* get_stat() const { return &_cache_stat; }
+
+private:
+    bool check_match(const PCacheParam& req_param) {
+        if (req_param.last_version() > _cache_value->param().last_version()) {
+            return false;
+        }
+        if (req_param.last_version_time() > 
_cache_value->param().last_version_time()) {
+            return false;
+        }
+        return true;
+    }
+
+    bool check_newer(const PCacheParam& up_param) {
+        //for init data of sql cache
+        if (up_param.last_version() == 0 || up_param.last_version_time() == 0) 
{
+            return true;
+        }
+        if (up_param.last_version_time() > 
_cache_value->param().last_version_time()) {
+            return true;
+        }
+        if (up_param.last_version() > _cache_value->param().last_version()) {
+            return true;
+        }
+        return false;
+    }
+
+private:
+    int64 _partition_key;
+    PCacheValue* _cache_value;
+    size_t _data_size;
+    CacheStat _cache_stat;
+};
+
+typedef std::list<PartitionRowBatch*> PartitionRowBatchList;
+typedef boost::unordered_map<int64, PartitionRowBatch*> PartitionRowBatchMap;
+
+/**
+* Cache the result of one SQL, include many partition rowsets.
+* Sql Cache: The partiton ID comes from the partition lastest updated.
+* Partition Cache: The partition ID comes from the partition scanned by query.
+* The above two modes use the same cache structure.
+*/
+class ResultNode {
+public:
+    ResultNode() : _sql_key(0, 0), _prev(NULL), _next(NULL), _data_size(0) {}
+
+    ResultNode(const UniqueId& sql_key)
+            : _sql_key(sql_key), _prev(NULL), _next(NULL), _data_size(0) {}
+
+    virtual ~ResultNode() {}
+
+    PCacheStatus update_partition(const PUpdateCacheRequest* request, bool& 
update_first);
+    PCacheStatus fetch_partition(const PFetchCacheRequest* request,
+                                 PartitionRowBatchList& rowBatchList, bool& 
hit_first);
+
+    size_t prune_first();
+    void clear();
+
+    bool operator()(const ResultNode* left_node, const ResultNode* right_node) 
{

Review comment:
       yes




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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

Reply via email to