Coverage Report

Created: 2026-10-23 15:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/util/thrift_rpc_helper.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 <functional>
24
#include <string>
25
26
#include "common/config.h"
27
#include "common/status.h"
28
29
namespace doris {
30
31
class ExecEnv;
32
class FrontendServiceClient;
33
class TStatus;
34
template <class T>
35
class ClientConnection;
36
37
// this class is a helper for jni call. easy for unit test
38
class ThriftRpcHelper {
39
public:
40
    static void setup(ExecEnv* exec_env);
41
42
    // for default timeout
43
    template <typename T>
44
    static Status rpc(const std::string& ip, const int32_t port,
45
22.2k
                      std::function<void(ClientConnection<T>&)> callback) {
46
22.2k
        return rpc(ip, port, callback, config::thrift_rpc_timeout_ms);
47
22.2k
    }
_ZN5doris15ThriftRpcHelper3rpcINS_21FrontendServiceClientEEENS_6StatusERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiSt8functionIFvRNS_16ClientConnectionIT_EEEE
Line
Count
Source
45
22.2k
                      std::function<void(ClientConnection<T>&)> callback) {
46
22.2k
        return rpc(ip, port, callback, config::thrift_rpc_timeout_ms);
47
22.2k
    }
Unexecuted instantiation: _ZN5doris15ThriftRpcHelper3rpcINS_20BackendServiceClientEEENS_6StatusERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiSt8functionIFvRNS_16ClientConnectionIT_EEEE
48
49
    template <typename T>
50
    static Status rpc(std::function<TNetworkAddress()> address_provider,
51
                      std::function<void(ClientConnection<T>&)> callback) {
52
        return rpc(address_provider, callback, config::thrift_rpc_timeout_ms);
53
    }
54
55
    template <typename T>
56
    static Status rpc(const std::string& ip, const int32_t port,
57
                      std::function<void(ClientConnection<T>&)> callback, int timeout_ms);
58
59
    template <typename T>
60
    static Status rpc(std::function<TNetworkAddress()> address_provider,
61
                      std::function<void(ClientConnection<T>&)> callback, int timeout_ms);
62
63
    static ExecEnv* get_exec_env() { return _s_exec_env; }
64
65
    // Only for stream-load operations with a stable request_id / transaction id.
66
    // Application errors other than NOT_MASTER are returned without replaying the RPC.
67
    static Status rpc_fe_with_master_refresh(
68
            std::function<TNetworkAddress()> address_provider,
69
            std::function<void(ClientConnection<FrontendServiceClient>&)> callback,
70
            std::function<TStatus()> response_status,
71
            int timeout_ms = config::thrift_rpc_timeout_ms);
72
73
private:
74
    static Status _retry_fe_rpc(const std::function<TNetworkAddress()>& address_provider,
75
                                const std::function<Status(const TNetworkAddress&)>& attempt,
76
                                const std::function<TStatus()>& response_status,
77
                                int retry_interval_ms);
78
79
    static ExecEnv* _s_exec_env;
80
};
81
82
} // namespace doris