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

Method GetTabletAddrOrScheduleUpdateMeta

src/sdk/table_impl.cc:1452–1498  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1450}
1451
1452bool TableImpl::GetTabletAddrOrScheduleUpdateMeta(const std::string& row, SdkTask* task,
1453 std::string* server_addr) {
1454 CHECK_NOTNULL(task);
1455 MutexLock lock(&meta_mutex_);
1456 TabletMetaNode* node = GetTabletMetaNodeForKey(row);
1457 if (node == NULL) {
1458 VLOG(10) << "no meta for key: " << row;
1459 pending_task_id_list_[row].push_back(task->GetId());
1460 task->DecRef();
1461 TabletMetaNode& new_node = tablet_meta_list_[row];
1462 new_node.meta.mutable_key_range()->set_key_start(row);
1463 new_node.meta.mutable_key_range()->set_key_end(row + '\0');
1464 new_node.status = WAIT_UPDATE;
1465 UpdateMetaAsync();
1466 return false;
1467 }
1468 if (node->status != NORMAL) {
1469 VLOG(10) << "abnormal meta for key: " << row;
1470 pending_task_id_list_[row].push_back(task->GetId());
1471 task->DecRef();
1472 return false;
1473 }
1474 if ((task->GetInternalError() == kKeyNotInRange || task->GetInternalError() == kConnectError) &&
1475 task->GetMetaTimeStamp() >= node->update_time) {
1476 pending_task_id_list_[row].push_back(task->GetId());
1477 task->DecRef();
1478 int64_t update_interval =
1479 node->update_time + FLAGS_tera_sdk_update_meta_internal - get_micros() / 1000;
1480 if (update_interval <= 0) {
1481 VLOG(10) << "update meta now for key: " << row;
1482 node->status = WAIT_UPDATE;
1483 UpdateMetaAsync();
1484 } else {
1485 VLOG(10) << "update meta in " << update_interval << " (ms) for key:" << row;
1486 node->status = DELAY_UPDATE;
1487 ThreadPool::Task delay_task =
1488 std::bind(&TableImpl::DelayUpdateMeta, this, node->meta.key_range().key_start(),
1489 node->meta.key_range().key_end());
1490 thread_pool_->DelayTask(update_interval, delay_task);
1491 }
1492 return false;
1493 }
1494 CHECK_EQ(node->status, NORMAL);
1495 task->SetMetaTimeStamp(node->update_time);
1496 *server_addr = node->meta.server_addr();
1497 return true;
1498}
1499
1500TableImpl::TabletMetaNode* TableImpl::GetTabletMetaNodeForKey(const std::string& key) {
1501 meta_mutex_.AssertHeld();

Callers

nothing calls this directly

Calls 8

push_backMethod · 0.80
GetInternalErrorMethod · 0.80
GetMetaTimeStampMethod · 0.80
DelayTaskMethod · 0.80
SetMetaTimeStampMethod · 0.80
get_microsFunction · 0.50
GetIdMethod · 0.45
DecRefMethod · 0.45

Tested by

no test coverage detected