be/src/exec/exchange/vdata_stream_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 | | |
23 | | #include <memory> |
24 | | #include <mutex> |
25 | | #include <set> |
26 | | #include <shared_mutex> |
27 | | #include <unordered_map> |
28 | | #include <utility> |
29 | | |
30 | | #include "common/be_mock_util.h" |
31 | | #include "common/global_types.h" |
32 | | #include "common/status.h" |
33 | | #include "runtime/runtime_profile.h" |
34 | | |
35 | | namespace google { |
36 | | #include "common/compile_check_begin.h" |
37 | | namespace protobuf { |
38 | | class Closure; |
39 | | } |
40 | | } // namespace google |
41 | | |
42 | | namespace doris { |
43 | | class RuntimeState; |
44 | | class RowDescriptor; |
45 | | class PTransmitDataParams; |
46 | | class ExchangeLocalState; |
47 | | |
48 | | class VDataStreamRecvr; |
49 | | |
50 | | class VDataStreamMgr { |
51 | | public: |
52 | | VDataStreamMgr(); |
53 | | MOCK_FUNCTION ~VDataStreamMgr(); |
54 | | |
55 | | std::shared_ptr<VDataStreamRecvr> create_recvr( |
56 | | RuntimeState* state, RuntimeProfile::HighWaterMarkCounter* memory_used_counter, |
57 | | const TUniqueId& fragment_instance_id, PlanNodeId dest_node_id, int num_senders, |
58 | | RuntimeProfile* profile, bool is_merging, size_t data_queue_capacity); |
59 | | |
60 | | MOCK_FUNCTION Status find_recvr(const TUniqueId& fragment_instance_id, PlanNodeId node_id, |
61 | | std::shared_ptr<VDataStreamRecvr>* res, |
62 | | bool acquire_lock = true); |
63 | | |
64 | | Status deregister_recvr(const TUniqueId& fragment_instance_id, PlanNodeId node_id); |
65 | | |
66 | | Status transmit_block(const PTransmitDataParams* request, ::google::protobuf::Closure** done, |
67 | | const int64_t wait_for_worker); |
68 | | |
69 | | void cancel(const TUniqueId& fragment_instance_id, Status exec_status); |
70 | | |
71 | | private: |
72 | | std::shared_mutex _lock; |
73 | | using StreamMap = std::unordered_multimap<uint32_t, std::shared_ptr<VDataStreamRecvr>>; |
74 | | StreamMap _receiver_map; |
75 | | |
76 | | struct ComparisonOp { |
77 | | bool operator()(const std::pair<doris::TUniqueId, PlanNodeId>& a, |
78 | 9.34M | const std::pair<doris::TUniqueId, PlanNodeId>& b) const { |
79 | 9.34M | if (a.first.hi < b.first.hi) { |
80 | 2.73M | return true; |
81 | 6.60M | } else if (a.first.hi > b.first.hi) { |
82 | 1.61M | return false; |
83 | 4.99M | } else if (a.first.lo < b.first.lo) { |
84 | 2.15M | return true; |
85 | 2.84M | } else if (a.first.lo > b.first.lo) { |
86 | 1.70M | return false; |
87 | 1.70M | } |
88 | 1.14M | return a.second < b.second; |
89 | 9.34M | } |
90 | | }; |
91 | | using FragmentStreamSet = std::set<std::pair<TUniqueId, PlanNodeId>, ComparisonOp>; |
92 | | FragmentStreamSet _fragment_stream_set; |
93 | | |
94 | | uint32_t get_hash_value(const TUniqueId& fragment_instance_id, PlanNodeId node_id); |
95 | | }; |
96 | | } // namespace doris |
97 | | |
98 | | #include "common/compile_check_end.h" |