@@ -134,7 +134,6 @@ HttpBrpcStubCache* HttpBrpcStubCache::getInstance() {
134
134
135
135
HttpBrpcStubCache::HttpBrpcStubCache () {
136
136
_stub_map.init (500 );
137
- _task_map.init (500 );
138
137
_pipeline_timer = ExecEnv::GetInstance ()->pipeline_timer ();
139
138
}
140
139
@@ -143,8 +142,8 @@ HttpBrpcStubCache::~HttpBrpcStubCache() {
143
142
144
143
{
145
144
std::lock_guard<SpinLock> l (_lock);
146
- for (auto & stub : _task_map ) {
147
- task_to_cleanup.push_back (stub.second );
145
+ for (auto & stub : _stub_map ) {
146
+ task_to_cleanup.push_back (stub.second . second );
148
147
}
149
148
}
150
149
@@ -153,7 +152,6 @@ HttpBrpcStubCache::~HttpBrpcStubCache() {
153
152
}
154
153
155
154
_stub_map.clear ();
156
- _task_map.clear ();
157
155
}
158
156
159
157
StatusOr<std::shared_ptr<PInternalService_RecoverableStub>> HttpBrpcStubCache::get_http_stub (
@@ -176,40 +174,34 @@ StatusOr<std::shared_ptr<PInternalService_RecoverableStub>> HttpBrpcStubCache::g
176
174
// get is exist
177
175
std::lock_guard<SpinLock> l (_lock);
178
176
179
- // schedule clean up task
180
- auto task = _task_map. seek (endpoint);
181
- if (task == nullptr ) {
177
+ auto stub_pair_ptr = _stub_map. seek (endpoint);
178
+ if (stub_pair_ptr == nullptr ) {
179
+ // create
182
180
auto new_task = std::make_shared<HttpEndpointCleanupTask>(this , endpoint);
183
- _task_map.insert (endpoint, new_task);
184
- task = _task_map.seek (endpoint);
181
+ auto stub = std::make_shared<PInternalService_RecoverableStub>(endpoint, " http" );
182
+ if (!stub->reset_channel ().ok ()) {
183
+ return Status::RuntimeError (" init brpc http channel error on " + taddr.hostname + " :" +
184
+ std::to_string (taddr.port ));
185
+ }
186
+ _stub_map.insert (endpoint, std::make_pair (stub, new_task));
187
+ stub_pair_ptr = _stub_map.seek (endpoint);
185
188
}
186
- _pipeline_timer->unschedule ((*task).get ());
189
+
190
+ // schedule clean up task
191
+ _pipeline_timer->unschedule ((*stub_pair_ptr).second .get ());
187
192
timespec tm = butil::seconds_from_now (config::brpc_stub_expire_s);
188
- auto status = _pipeline_timer->schedule ((*task) .get (), tm);
193
+ auto status = _pipeline_timer->schedule ((*stub_pair_ptr). second .get (), tm);
189
194
if (!status.ok ()) {
190
195
LOG (WARNING) << " Failed to schedule http brpc cleanup task: " << endpoint;
191
196
}
192
-
193
- auto stub_ptr = _stub_map.seek (endpoint);
194
- if (stub_ptr != nullptr ) {
195
- return *stub_ptr;
196
- }
197
- // create
198
- auto stub = std::make_shared<PInternalService_RecoverableStub>(endpoint, " http" );
199
- if (!stub->reset_channel ().ok ()) {
200
- return Status::RuntimeError (" init brpc http channel error on " + taddr.hostname + " :" +
201
- std::to_string (taddr.port ));
202
- }
203
- _stub_map.insert (endpoint, stub);
204
- return stub;
197
+ return (*stub_pair_ptr).first ;
205
198
}
206
199
207
200
void HttpBrpcStubCache::cleanup_expired (const butil::EndPoint& endpoint) {
208
201
std::lock_guard<SpinLock> l (_lock);
209
202
210
203
LOG (INFO) << " cleanup http stubs from endpoint:" << endpoint;
211
204
_stub_map.erase (endpoint);
212
- _task_map.erase (endpoint);
213
205
}
214
206
215
207
LakeServiceBrpcStubCache* LakeServiceBrpcStubCache::getInstance () {
@@ -219,7 +211,6 @@ LakeServiceBrpcStubCache* LakeServiceBrpcStubCache::getInstance() {
219
211
220
212
LakeServiceBrpcStubCache::LakeServiceBrpcStubCache () {
221
213
_stub_map.init (500 );
222
- _task_map.init (500 );
223
214
_pipeline_timer = ExecEnv::GetInstance ()->pipeline_timer ();
224
215
}
225
216
@@ -228,8 +219,8 @@ LakeServiceBrpcStubCache::~LakeServiceBrpcStubCache() {
228
219
229
220
{
230
221
std::lock_guard<SpinLock> l (_lock);
231
- for (auto & stub : _task_map ) {
232
- task_to_cleanup.push_back (stub.second );
222
+ for (auto & stub : _stub_map ) {
223
+ task_to_cleanup.push_back (stub.second . second );
233
224
}
234
225
}
235
226
@@ -238,7 +229,6 @@ LakeServiceBrpcStubCache::~LakeServiceBrpcStubCache() {
238
229
}
239
230
240
231
_stub_map.clear ();
241
- _task_map.clear ();
242
232
}
243
233
244
234
DEFINE_FAIL_POINT (get_stub_return_nullptr);
@@ -258,41 +248,34 @@ StatusOr<std::shared_ptr<starrocks::LakeService_RecoverableStub>> LakeServiceBrp
258
248
// get if exist
259
249
std::lock_guard<SpinLock> l (_lock);
260
250
261
- // schedule clean up task
262
- auto task = _task_map.seek (endpoint);
263
- if (task == nullptr ) {
251
+ auto stub_pair_ptr = _stub_map.seek (endpoint);
252
+ FAIL_POINT_TRIGGER_EXECUTE (get_stub_return_nullptr, { stub_pair_ptr = nullptr ; });
253
+ if (stub_pair_ptr == nullptr ) {
254
+ // create
255
+ auto stub = std::make_shared<starrocks::LakeService_RecoverableStub>(endpoint, " " );
264
256
auto new_task = std::make_shared<LakeEndpointCleanupTask>(this , endpoint);
265
- _task_map.insert (endpoint, new_task);
266
- task = _task_map.seek (endpoint);
257
+ if (!stub->reset_channel ().ok ()) {
258
+ return Status::RuntimeError (" init brpc lake channel error on " + host + " :" + std::to_string (port));
259
+ }
260
+ _stub_map.insert (endpoint, std::make_pair (stub, new_task));
261
+ stub_pair_ptr = _stub_map.seek (endpoint);
267
262
}
268
- _pipeline_timer->unschedule ((*task).get ());
263
+
264
+ // schedule clean up task
265
+ _pipeline_timer->unschedule ((*stub_pair_ptr).second .get ());
269
266
timespec tm = butil::seconds_from_now (config::brpc_stub_expire_s);
270
- auto status = _pipeline_timer->schedule ((*task) .get (), tm);
267
+ auto status = _pipeline_timer->schedule ((*stub_pair_ptr). second .get (), tm);
271
268
if (!status.ok ()) {
272
269
LOG (WARNING) << " Failed to schedule lake brpc cleanup task: " << endpoint;
273
270
}
274
-
275
- auto stub_ptr = _stub_map.seek (endpoint);
276
- FAIL_POINT_TRIGGER_EXECUTE (get_stub_return_nullptr, { stub_ptr = nullptr ; });
277
- if (stub_ptr != nullptr ) {
278
- return *stub_ptr;
279
- }
280
- // create
281
- auto stub = std::make_shared<starrocks::LakeService_RecoverableStub>(endpoint, " " );
282
-
283
- if (!stub->reset_channel ().ok ()) {
284
- return Status::RuntimeError (" init brpc http channel error on " + host + " :" + std::to_string (port));
285
- }
286
- _stub_map.insert (endpoint, stub);
287
- return stub;
271
+ return (*stub_pair_ptr).first ;
288
272
}
289
273
290
274
void LakeServiceBrpcStubCache::cleanup_expired (const butil::EndPoint& endpoint) {
291
275
std::lock_guard<SpinLock> l (_lock);
292
276
293
277
LOG (INFO) << " cleanup lake service stubs from endpoint:" << endpoint;
294
278
_stub_map.erase (endpoint);
295
- _task_map.erase (endpoint);
296
279
}
297
280
298
281
void EndpointCleanupTask::Run () {
0 commit comments