Coverage Report

Created: 2026-03-15 18:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/agent/topic_subscriber.cpp
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
#include "agent/topic_subscriber.h"
19
20
#include <pthread.h>
21
22
#include <mutex>
23
#include <utility>
24
25
#include "agent/topic_listener.h"
26
27
namespace doris {
28
29
7
TopicSubscriber::TopicSubscriber() {}
30
31
void TopicSubscriber::register_listener(TTopicInfoType::type topic_type,
32
14
                                        std::unique_ptr<TopicListener> topic_listener) {
33
    // Unique lock here to prevent access to listeners
34
14
    std::lock_guard<std::shared_mutex> lock(_listener_mtx);
35
14
    this->_registered_listeners.emplace(topic_type, std::move(topic_listener));
36
14
}
37
38
1.18k
void TopicSubscriber::handle_topic_info(const TPublishTopicRequest& topic_request) {
39
    // NOTE(wb): if we found there is bottleneck for handle_topic_info by LOG(INFO)
40
    // eg, update workload info may delay other listener, then we need add a thread here
41
    // to handle_topic_info asynchronous
42
1.18k
    std::shared_lock lock(_listener_mtx);
43
2.37k
    for (auto& listener_pair : _registered_listeners) {
44
2.37k
        if (topic_request.topic_map.find(listener_pair.first) != topic_request.topic_map.end()) {
45
2.37k
            listener_pair.second->handle_topic_info(
46
2.37k
                    topic_request.topic_map.at(listener_pair.first));
47
            LOG(INFO) << "[topic_publish]finish handle topic " << listener_pair.first
48
2.37k
                      << ", size=" << topic_request.topic_map.at(listener_pair.first).size();
49
2.37k
        }
50
2.37k
    }
51
1.18k
}
52
} // namespace doris