Coverage Report

Created: 2026-08-22 00:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/service/backend_service.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/BackendService.h>
21
#include <gen_cpp/Status_types.h>
22
23
#include <memory>
24
#include <string>
25
#include <vector>
26
27
#include "agent/agent_server.h"
28
#include "agent/topic_subscriber.h"
29
#include "common/status.h"
30
#include "load/stream_load/stream_load_recorder.h"
31
32
namespace doris {
33
34
class StorageEngine;
35
class ExecEnv;
36
class TAgentResult;
37
class TAgentTaskRequest;
38
class TAgentPublishRequest;
39
class TStreamLoadRecordResult;
40
class TDiskTrashInfo;
41
class TCheckStorageFormatResult;
42
class TRoutineLoadTask;
43
class TScanBatchResult;
44
class TScanCloseParams;
45
class TScanCloseResult;
46
class TScanNextBatchParams;
47
class TScanOpenParams;
48
class TScanOpenResult;
49
class TSnapshotRequest;
50
class TStatus;
51
class TTabletStatResult;
52
class TUniqueId;
53
class TIngestBinlogRequest;
54
class TIngestBinlogResult;
55
class ThreadPool;
56
57
// This class just forward rpc for actual handler
58
// make this class because we can bind multiple service on single point
59
class BaseBackendService : public BackendServiceIf {
60
public:
61
    BaseBackendService(ExecEnv* exec_env);
62
63
    ~BaseBackendService() override;
64
65
    // Start runtime workers that the thrift server depends on (agent workers,
66
    // ingest-binlog thread pool, etc.). Must be called before constructing the
67
    // thrift server. The name makes the side effects explicit: this is not a
68
    // lightweight preparation hook.
69
    virtual Status start_thrift_dependencies() = 0;
70
71
    // Agent service
72
    void submit_tasks(TAgentResult& return_value,
73
0
                      const std::vector<TAgentTaskRequest>& tasks) override {
74
0
        _agent_server->submit_tasks(return_value, tasks);
75
0
    }
76
77
0
    void publish_cluster_state(TAgentResult& result, const TAgentPublishRequest& request) override {
78
0
        _agent_server->publish_cluster_state(result, request);
79
0
    }
80
81
    void publish_topic_info(TPublishTopicResult& result,
82
0
                            const TPublishTopicRequest& topic_request) override {
83
0
        _agent_server->get_topic_subscriber()->handle_topic_info(topic_request);
84
0
    }
85
86
    void submit_routine_load_task(TStatus& t_status,
87
                                  const std::vector<TRoutineLoadTask>& tasks) override;
88
89
    // used for external service, open means start the scan procedure
90
    void open_scanner(TScanOpenResult& result_, const TScanOpenParams& params) override;
91
92
    // used for external service, external use getNext to fetch data batch after batch until eos = true
93
    void get_next(TScanBatchResult& result_, const TScanNextBatchParams& params) override;
94
95
    // used for external service, close some context and release resource related with this context
96
    void close_scanner(TScanCloseResult& result_, const TScanCloseParams& params) override;
97
98
    ////////////////////////////////////////////////////////////////////////////
99
    // begin local backend functions
100
    ////////////////////////////////////////////////////////////////////////////
101
    void get_tablet_stat(TTabletStatResult& result) override;
102
103
    int64_t get_trash_used_capacity() override;
104
105
    void get_stream_load_record(TStreamLoadRecordResult& result,
106
                                int64_t last_stream_record_time) override;
107
108
    void get_disk_trash_used_capacity(std::vector<TDiskTrashInfo>& diskTrashInfos) override;
109
110
    void make_snapshot(TAgentResult& return_value,
111
                       const TSnapshotRequest& snapshot_request) override;
112
113
    void release_snapshot(TAgentResult& return_value, const std::string& snapshot_path) override;
114
115
    void check_storage_format(TCheckStorageFormatResult& result) override;
116
117
    void ingest_binlog(TIngestBinlogResult& result, const TIngestBinlogRequest& request) override;
118
119
    void query_ingest_binlog(TQueryIngestBinlogResult& result,
120
                             const TQueryIngestBinlogRequest& request) override;
121
122
    void get_realtime_exec_status(TGetRealtimeExecStatusResponse& response,
123
                                  const TGetRealtimeExecStatusRequest& request) override;
124
125
    void get_dictionary_status(TDictionaryStatusList& result,
126
                               const std::vector<int64_t>& dictionary_id) override;
127
128
    void test_storage_connectivity(TTestStorageConnectivityResponse& response,
129
                                   const TTestStorageConnectivityRequest& request) override;
130
131
    void get_python_envs(std::vector<TPythonEnvInfo>& result) override;
132
133
    void get_python_packages(std::vector<TPythonPackageInfo>& result,
134
                             const std::string& python_version) override;
135
136
    ////////////////////////////////////////////////////////////////////////////
137
    // begin cloud backend functions
138
    ////////////////////////////////////////////////////////////////////////////
139
    void warm_up_cache_async(TWarmUpCacheAsyncResponse& response,
140
                             const TWarmUpCacheAsyncRequest& request) override;
141
142
    void check_warm_up_cache_async(TCheckWarmUpCacheAsyncResponse& response,
143
                                   const TCheckWarmUpCacheAsyncRequest& request) override;
144
145
    // If another cluster load, FE need to notify the cluster to sync the load data
146
    void sync_load_for_tablets(TSyncLoadForTabletsResponse& response,
147
                               const TSyncLoadForTabletsRequest& request) override;
148
149
    void get_top_n_hot_partitions(TGetTopNHotPartitionsResponse& response,
150
                                  const TGetTopNHotPartitionsRequest& request) override;
151
152
    void warm_up_tablets(TWarmUpTabletsResponse& response,
153
                         const TWarmUpTabletsRequest& request) override;
154
155
0
    void stop_works() { _agent_server->stop_report_workers(); }
156
157
protected:
158
    void get_stream_load_record(TStreamLoadRecordResult& result, int64_t last_stream_record_time,
159
                                std::shared_ptr<StreamLoadRecorder> stream_load_recorder);
160
161
    ExecEnv* _exec_env = nullptr;
162
    std::unique_ptr<AgentServer> _agent_server;
163
    std::unique_ptr<ThreadPool> _ingest_binlog_workers;
164
};
165
166
// `StorageEngine` mixin for `BaseBackendService`
167
class BackendService final : public BaseBackendService {
168
public:
169
    BackendService(StorageEngine& engine, ExecEnv* exec_env);
170
171
    ~BackendService() override;
172
173
    Status start_thrift_dependencies() override;
174
175
    void get_tablet_stat(TTabletStatResult& result) override;
176
177
    int64_t get_trash_used_capacity() override;
178
179
    void get_stream_load_record(TStreamLoadRecordResult& result,
180
                                int64_t last_stream_record_time) override;
181
182
    void get_disk_trash_used_capacity(std::vector<TDiskTrashInfo>& diskTrashInfos) override;
183
184
    void make_snapshot(TAgentResult& return_value,
185
                       const TSnapshotRequest& snapshot_request) override;
186
187
    void release_snapshot(TAgentResult& return_value, const std::string& snapshot_path) override;
188
189
    void check_storage_format(TCheckStorageFormatResult& result) override;
190
191
    void ingest_binlog(TIngestBinlogResult& result, const TIngestBinlogRequest& request) override;
192
193
    void query_ingest_binlog(TQueryIngestBinlogResult& result,
194
                             const TQueryIngestBinlogRequest& request) override;
195
196
private:
197
    StorageEngine& _engine;
198
};
199
200
} // namespace doris