be/src/runtime/external_scan_context_mgr.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <gen_cpp/Types_types.h> |
21 | | #include <stdint.h> |
22 | | #include <time.h> |
23 | | |
24 | | #include <map> |
25 | | #include <memory> |
26 | | #include <mutex> |
27 | | #include <string> |
28 | | #include <utility> |
29 | | |
30 | | #include "common/status.h" |
31 | | #include "util/countdown_latch.h" |
32 | | |
33 | | namespace doris { |
34 | | class ExecEnv; |
35 | | class Thread; |
36 | | |
37 | | struct ScanContext { |
38 | | public: |
39 | | TUniqueId fragment_instance_id; |
40 | | TUniqueId query_id; |
41 | | int64_t offset; |
42 | | // use this access_time to clean zombie context |
43 | | time_t last_access_time; |
44 | | std::mutex _local_lock; |
45 | | std::string context_id; |
46 | | short keep_alive_min; |
47 | 6 | ScanContext(std::string id) : context_id(std::move(id)) {} |
48 | | }; |
49 | | |
50 | | class ExternalScanContextMgr { |
51 | | public: |
52 | | ExternalScanContextMgr(ExecEnv* exec_env); |
53 | 7 | ~ExternalScanContextMgr() = default; |
54 | | |
55 | | void stop(); |
56 | | |
57 | | Status create_scan_context(std::shared_ptr<ScanContext>* p_context); |
58 | | |
59 | | Status get_scan_context(const std::string& context_id, std::shared_ptr<ScanContext>* p_context); |
60 | | |
61 | | Status clear_scan_context(const std::string& context_id); |
62 | | |
63 | | private: |
64 | | ExecEnv* _exec_env = nullptr; |
65 | | std::map<std::string, std::shared_ptr<ScanContext>> _active_contexts; |
66 | | void gc_expired_context(); |
67 | | |
68 | | CountDownLatch _stop_background_threads_latch; |
69 | | std::shared_ptr<Thread> _keep_alive_reaper; |
70 | | |
71 | | std::mutex _lock; |
72 | | }; |
73 | | |
74 | | } // namespace doris |