forked from oceanbase/seekdb
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathob_executor_rpc_impl.cpp
More file actions
234 lines (217 loc) · 8.81 KB
/
Copy pathob_executor_rpc_impl.cpp
File metadata and controls
234 lines (217 loc) · 8.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
* Copyright (c) 2025 OceanBase.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define USING_LOG_PREFIX SQL_EXE
#include "ob_executor_rpc_impl.h"
#include "sql/executor/ob_remote_executor_processor.h"
using namespace oceanbase::common;
namespace oceanbase
{
namespace sql
{
RemoteExecuteStreamHandle::~RemoteExecuteStreamHandle()
{
}
int ObExecutorRpcImpl::init(obrpc::ObExecutorRpcProxy *rpc_proxy, obrpc::ObBatchRpc *batch_rpc)
{
int ret = OB_SUCCESS;
proxy_ = rpc_proxy;
batch_rpc_ = batch_rpc;
return ret;
}
int ObExecutorRpcImpl::task_execute(ObExecutorRpcCtx &rpc_ctx,
ObTask &task,
const common::ObAddr &svr,
RemoteExecuteStreamHandle &handler,
bool &has_sent_task,
bool &has_transfer_err)
{
int ret = OB_SUCCESS;
uint64_t tenant_id = rpc_ctx.get_rpc_tenant_id();
has_sent_task = false;
has_transfer_err = false;
handler.set_task_id(task.get_ob_task_id());
if (THIS_WORKER.get_rpc_tenant() > 0) {
tenant_id = THIS_WORKER.get_rpc_tenant();
}
RemoteStreamHandle &real_handler = handler.get_remote_stream_handle();
RemoteStreamHandle::MyHandle &h = real_handler.get_handle();
int64_t timeout_timestamp = rpc_ctx.get_timeout_timestamp();
const int32_t group_id = rpc_ctx.get_group_id();
if (OB_ISNULL(proxy_) || OB_ISNULL(real_handler.get_result())) {
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("not init", K(ret), K_(proxy), "result", real_handler.get_result());
} else {
int64_t timeout = timeout_timestamp - ::oceanbase::common::ObTimeUtility::current_time();
obrpc::ObExecutorRpcProxy to_proxy = proxy_->to(svr);
if (OB_UNLIKELY(timeout <= 0)) {
ret = OB_TIMEOUT;
LOG_WARN("task_execute timeout before rpc",
K(ret),
K(svr),
K(timeout),
K(timeout_timestamp));
} else if (FALSE_IT(has_sent_task = true)) {
} else if (OB_FAIL(to_proxy
.by(tenant_id)
.timeout(timeout)
.group_id(group_id)
.task_execute(task, *real_handler.get_result(), h))) {
LOG_WARN("rpc task_execute fail",
K(ret),
K(tenant_id),
K(svr),
K(timeout),
K(timeout_timestamp));
// rcode.rcode_ will be set in ObRpcProcessor<T>::part_response() of remote server,
// and return to local server from remote server. so:
// 1. if we get OB_SUCCESS from rcode.rcode_ here, transfer process must has error,
// such as network error or crash of remote server.
// 2. if we get some error from rcode.rcode_ here, transfer process must has no error,
// otherwise we can not get rcode.rcode_ from remote server.
const obrpc::ObRpcResultCode &rcode = to_proxy.get_result_code();
if (OB_LIKELY(OB_SUCCESS != rcode.rcode_)) {
FORWARD_USER_ERROR(rcode.rcode_, rcode.msg_);
} else if (OB_RPC_SEND_ERROR == ret || OB_RPC_POST_ERROR == ret) {
// these two error means the request hasn't been sent out to network
// either because the server is in blacklist or network link breaks
has_sent_task = false;
} else {
has_transfer_err = true;
}
deal_with_rpc_timeout_err(rpc_ctx, ret, svr);
}
}
handler.set_result_code(ret);
return ret;
}
int ObExecutorRpcImpl::task_execute_v2(ObExecutorRpcCtx &rpc_ctx,
ObRemoteTask &task,
const common::ObAddr &svr,
RemoteExecuteStreamHandle &handler,
bool &has_sent_task,
bool &has_transfer_err)
{
int ret = OB_SUCCESS;
uint64_t tenant_id = rpc_ctx.get_rpc_tenant_id();
has_sent_task = false;
has_transfer_err = false;
handler.set_task_id(task.get_task_id());
if (THIS_WORKER.get_rpc_tenant() > 0) {
tenant_id = THIS_WORKER.get_rpc_tenant();
}
RemoteStreamHandleV2 &real_handler = handler.get_remote_stream_handle_v2();
RemoteStreamHandleV2::MyHandle &h = real_handler.get_handle();
int64_t timeout_timestamp = rpc_ctx.get_timeout_timestamp();
const int32_t group_id = rpc_ctx.get_group_id();
if (OB_ISNULL(proxy_) || OB_ISNULL(real_handler.get_result())) {
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("not init", K(ret), K_(proxy), "result", real_handler.get_result());
} else {
int64_t timeout = timeout_timestamp - ::oceanbase::common::ObTimeUtility::current_time();
obrpc::ObExecutorRpcProxy to_proxy = proxy_->to(svr);
if (OB_UNLIKELY(timeout <= 0)) {
ret = OB_TIMEOUT;
LOG_WARN("task_execute timeout before rpc",
K(ret), K(svr), K(timeout), K(timeout_timestamp));
} else if (FALSE_IT(has_sent_task = true)) {
} else if (OB_FAIL(to_proxy
.by(tenant_id)
.timeout(timeout)
.group_id(group_id)
.remote_task_execute(task, *real_handler.get_result(), h))) {
LOG_WARN("rpc task_execute fail",
K(ret), K(tenant_id), K(svr), K(timeout), K(timeout_timestamp));
// rcode.rcode_ will be set in ObRpcProcessor<T>::part_response() of remote server,
// and return to local server from remote server. so:
// 1. if we get OB_SUCCESS from rcode.rcode_ here, transfer process must has error,
// such as network error or crash of remote server.
// 2. if we get some error from rcode.rcode_ here, transfer process must has no error,
// otherwise we can not get rcode.rcode_ from remote server.
const obrpc::ObRpcResultCode &rcode = to_proxy.get_result_code();
if (OB_LIKELY(OB_SUCCESS != rcode.rcode_)) {
FORWARD_USER_ERROR(rcode.rcode_, rcode.msg_);
} else {
has_transfer_err = true;
}
deal_with_rpc_timeout_err(rpc_ctx, ret, svr);
}
}
handler.set_result_code(ret);
return ret;
}
/*
* Send a command to kill a task and block waiting for the peer to return the execution status
* */
int ObExecutorRpcImpl::task_kill(
ObExecutorRpcCtx &rpc_ctx,
const ObTaskID &task_id,
const common::ObAddr &svr)
{
int ret = OB_SUCCESS;
uint64_t tenant_id = rpc_ctx.get_rpc_tenant_id();
if (THIS_WORKER.get_rpc_tenant() > 0) {
tenant_id = THIS_WORKER.get_rpc_tenant();
}
int64_t timeout_timestamp = rpc_ctx.get_timeout_timestamp();
if (OB_ISNULL(proxy_)) {
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("proxy_ is NULL", K(ret));
} else {
int64_t timeout = timeout_timestamp - ::oceanbase::common::ObTimeUtility::current_time();
if (OB_UNLIKELY(timeout <= 0)) {
ret = OB_TIMEOUT;
LOG_WARN("task_execute timeout before rpc",
K(ret),
K(svr),
K(timeout),
K(timeout_timestamp));
} else if (OB_FAIL(proxy_
->to(svr)
.by(tenant_id)
.timeout(timeout)
.task_kill(task_id))) {
LOG_WARN("rpc task_kill fail", K(ret), K(svr), K(tenant_id),
K(timeout), K(timeout_timestamp));
deal_with_rpc_timeout_err(rpc_ctx, ret, svr);
}
}
return ret;
}
void ObExecutorRpcImpl::deal_with_rpc_timeout_err(ObExecutorRpcCtx &rpc_ctx,
int &err,
const ObAddr &dist_server) const
{
if (OB_TIMEOUT == err) {
int64_t timeout_timestamp = rpc_ctx.get_ps_timeout_timestamp();
int64_t cur_timestamp = ::oceanbase::common::ObTimeUtility::current_time();
if (timeout_timestamp - cur_timestamp > 0) {
LOG_DEBUG("rpc return OB_TIMEOUT, but it is actually not timeout, "
"change error code to OB_CONNECT_ERROR", K(err),
K(timeout_timestamp), K(cur_timestamp));
err = OB_RPC_CONNECT_ERROR;
} else {
LOG_DEBUG("rpc return OB_TIMEOUT, and it is actually timeout, "
"do not change error code", K(err),
K(timeout_timestamp), K(cur_timestamp));
ObQueryRetryInfo *retry_info = rpc_ctx.get_retry_info_for_update();
if (NULL != retry_info) {
retry_info->set_is_rpc_timeout(true);
}
}
}
}
}/* ns sql*/
}/* ns oceanbase */