Coverage Report

Created: 2026-09-28 21:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/runtime/cdc_client_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/internal_service.pb.h>
21
22
#include <atomic>
23
#include <cstdint>
24
#include <mutex>
25
#include <string>
26
27
#include "common/status.h"
28
29
namespace google::protobuf {
30
class Closure;
31
class RpcController;
32
} // namespace google::protobuf
33
34
namespace doris {
35
36
class CdcClientMgr {
37
public:
38
    CdcClientMgr();
39
    ~CdcClientMgr();
40
41
    void stop();
42
43
    // Request CDC client to handle a request
44
    void request_cdc_client_impl(const PRequestCdcClientRequest* request,
45
                                 PRequestCdcClientResult* result, google::protobuf::Closure* done);
46
47
    Status send_request_to_cdc_client(const std::string& api, const std::string& params_body,
48
                                      std::string* response);
49
50
    Status start_cdc_client(PRequestCdcClientResult* result);
51
52
#ifdef BE_TEST
53
    // For testing only: get current child PID
54
227
    pid_t get_child_pid() const { return _get_child_pid(); }
55
    // For testing only: publish a PID and return its generation-qualified identity.
56
    uint64_t set_child_pid_for_test(pid_t pid);
57
6
    uint64_t get_child_identity_for_test() const { return _get_child_identity(); }
58
    // For testing only: run the production cleanup gate for an exact identity.
59
    bool terminate_child_identity_for_test(uint64_t identity);
60
    // For testing only: inspect the exact identity through the normal WNOHANG path.
61
    bool inspect_child_identity_for_test(uint64_t identity);
62
    // For testing only: invoke the installed handler body deterministically.
63
    static void invoke_sigchld_handler_for_test();
64
    // For testing only: pause a deterministic handler after it has copied the published identity.
65
    static void pause_sigchld_handler_for_test(bool pause);
66
    static bool sigchld_handler_paused_for_test();
67
    // For testing only: observe a normal thread failing to claim an owned child.
68
    static void reset_child_claim_failed_for_test();
69
    static bool child_claim_failed_for_test();
70
    // For testing only: pause after inspect's WNOHANG=0 observation and before claim release.
71
    static void pause_child_inspection_after_running_for_test(bool pause);
72
    static bool child_inspection_paused_for_test();
73
    // Pause a handler before claiming a copied identity, and after claiming a stale identity.
74
    static void pause_sigchld_before_claim_for_test(bool pause);
75
    static bool sigchld_before_claim_paused_for_test();
76
    static void pause_stale_child_claim_for_test(bool pause);
77
    static bool stale_child_claim_paused_for_test();
78
    // For testing only: inspect / drive the adopt-external flag
79
5
    bool get_adopted_external_for_test() const { return _adopted_external.load(); }
80
2
    void set_adopted_external_for_test(bool v) { _adopted_external.store(v); }
81
#endif
82
83
private:
84
    uint64_t _get_child_identity() const;
85
    pid_t _get_child_pid() const;
86
    uint64_t _publish_child_pid(pid_t pid);
87
    bool _terminate_child_identity(uint64_t identity);
88
89
    std::mutex _start_mutex;
90
    std::atomic<bool> _adopted_external {false};
91
};
92
93
} // namespace doris