Coverage Report

Created: 2024-11-21 12:22

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