Coverage Report

Created: 2026-05-18 16:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
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 "common/thread_safety_annotations.h"
34
#include "runtime/runtime_profile.h"
35
36
namespace google {
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
63
    Status deregister_recvr(const TUniqueId& fragment_instance_id, PlanNodeId node_id);
64
65
    Status transmit_block(const PTransmitDataParams* request, ::google::protobuf::Closure** done,
66
                          const int64_t wait_for_worker);
67
68
    void cancel(const TUniqueId& fragment_instance_id, Status exec_status);
69
70
private:
71
    AnnotatedSharedMutex _lock;
72
    using StreamMap = std::unordered_multimap<uint32_t, std::shared_ptr<VDataStreamRecvr>>;
73
    StreamMap _receiver_map GUARDED_BY(_lock);
74
75
    struct ComparisonOp {
76
        bool operator()(const std::pair<doris::TUniqueId, PlanNodeId>& a,
77
8.67M
                        const std::pair<doris::TUniqueId, PlanNodeId>& b) const {
78
8.67M
            if (a.first.hi < b.first.hi) {
79
2.81M
                return true;
80
5.85M
            } else if (a.first.hi > b.first.hi) {
81
1.70M
                return false;
82
4.15M
            } else if (a.first.lo < b.first.lo) {
83
1.80M
                return true;
84
2.34M
            } else if (a.first.lo > b.first.lo) {
85
1.14M
                return false;
86
1.14M
            }
87
1.20M
            return a.second < b.second;
88
8.67M
        }
89
    };
90
    using FragmentStreamSet = std::set<std::pair<TUniqueId, PlanNodeId>, ComparisonOp>;
91
    FragmentStreamSet _fragment_stream_set GUARDED_BY(_lock);
92
93
    Status _find_recvr(uint32_t hash_value, const TUniqueId& fragment_instance_id,
94
                       PlanNodeId node_id, std::shared_ptr<VDataStreamRecvr>* res)
95
            REQUIRES_SHARED(_lock);
96
97
    uint32_t get_hash_value(const TUniqueId& fragment_instance_id, PlanNodeId node_id);
98
};
99
} // namespace doris