MCPcopy Create free account
hub / github.com/baidu/tera / StartRead

Method StartRead

src/tabletnode/tabletnode_impl.cc:1282–1334  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1280}
1281
1282void ReadTabletTask::StartRead() {
1283 if (total_row_num_ == 0) {
1284 response_->set_status(kTabletNodeOk);
1285 response_->set_success_num(read_success_num_.Get());
1286 done_->Run();
1287 return;
1288 }
1289
1290 response_->mutable_detail()->mutable_status()->Reserve(total_row_num_);
1291 for (int i = 0; i != total_row_num_; ++i) {
1292 response_->mutable_detail()->mutable_status()->AddAlreadyReserved();
1293 }
1294
1295 int64_t max_task_num = FLAGS_tera_tabletnode_parallel_read_task_num;
1296 int64_t min_rows_per_task = FLAGS_tera_tabletnode_parallel_read_rows_per_task;
1297 int64_t max_size = max_task_num * min_rows_per_task;
1298 int64_t rows_per_task;
1299
1300 if (max_size >= total_row_num_) {
1301 rows_per_task = min_rows_per_task;
1302 } else {
1303 if (max_task_num <= 1) {
1304 rows_per_task = total_row_num_;
1305 } else {
1306 rows_per_task = total_row_num_ / max_task_num + 1;
1307 }
1308 }
1309 int64_t shard_cnt = total_row_num_ / rows_per_task + 1;
1310
1311 row_results_list_.reserve(shard_cnt);
1312
1313 int64_t row_to_read = total_row_num_;
1314 int64_t offset = 0;
1315 while (row_to_read > 0) {
1316 row_results_list_.emplace_back();
1317 auto shard_request = make_shared<ShardRequest>(offset, std::min(rows_per_task, row_to_read),
1318 &row_results_list_.back());
1319 row_to_read -= rows_per_task;
1320 offset += rows_per_task;
1321 // We split one read request to several shard_request.
1322 // row_to_read <= 0 means this is the last sharded request(No more rows need
1323 // to read).
1324 // So this sharded request is processed in current thread for reducing cost
1325 // of switching thread.
1326 // Otherwise, shard_request is added to read_thread_pool.
1327 if (row_to_read <= 0) {
1328 DoRead(shard_request);
1329 } else {
1330 read_thread_pool_->AddTask(
1331 std::bind(&ReadTabletTask::DoRead, shared_from_this(), shard_request));
1332 }
1333 }
1334}
1335
1336void ReadTabletTask::DoRead(std::shared_ptr<ShardRequest> shard_req) {
1337 bool is_timeout{false};

Callers 2

ReadTabletMethod · 0.80
TEST_FFunction · 0.80

Calls 3

AddTaskMethod · 0.80
GetMethod · 0.45
RunMethod · 0.45

Tested by 1

TEST_FFunction · 0.64