| 3315 | } |
| 3316 | |
| 3317 | void TabletImpl::GetTableFollower( |
| 3318 | RpcController* controller, |
| 3319 | const ::fedb::api::GetTableFollowerRequest* request, |
| 3320 | ::fedb::api::GetTableFollowerResponse* response, Closure* done) { |
| 3321 | brpc::ClosureGuard done_guard(done); |
| 3322 | uint32_t tid = request->tid(); |
| 3323 | uint32_t pid = request->pid(); |
| 3324 | std::shared_ptr<Table> table = GetTable(tid, pid); |
| 3325 | if (!table) { |
| 3326 | DEBUGLOG("table is not exist. tid %u pid %u", tid, pid); |
| 3327 | response->set_code(::fedb::base::ReturnCode::kTableIsNotExist); |
| 3328 | response->set_msg("table is not exist"); |
| 3329 | return; |
| 3330 | } |
| 3331 | if (!table->IsLeader()) { |
| 3332 | DEBUGLOG("table is follower. tid %u, pid %u", tid, pid); |
| 3333 | response->set_msg("table is follower"); |
| 3334 | response->set_code(::fedb::base::ReturnCode::kTableIsFollower); |
| 3335 | return; |
| 3336 | } |
| 3337 | std::shared_ptr<LogReplicator> replicator = GetReplicator(tid, pid); |
| 3338 | if (!replicator) { |
| 3339 | DEBUGLOG("replicator is not exist. tid %u pid %u", tid, pid); |
| 3340 | response->set_msg("replicator is not exist"); |
| 3341 | response->set_code(::fedb::base::ReturnCode::kReplicatorIsNotExist); |
| 3342 | return; |
| 3343 | } |
| 3344 | response->set_offset(replicator->GetOffset()); |
| 3345 | std::map<std::string, uint64_t> info_map; |
| 3346 | replicator->GetReplicateInfo(info_map); |
| 3347 | if (info_map.empty()) { |
| 3348 | response->set_msg("has no follower"); |
| 3349 | response->set_code(::fedb::base::ReturnCode::kNoFollower); |
| 3350 | } |
| 3351 | for (const auto& kv : info_map) { |
| 3352 | ::fedb::api::FollowerInfo* follower_info = |
| 3353 | response->add_follower_info(); |
| 3354 | follower_info->set_endpoint(kv.first); |
| 3355 | follower_info->set_offset(kv.second); |
| 3356 | } |
| 3357 | response->set_msg("ok"); |
| 3358 | response->set_code(::fedb::base::ReturnCode::kOk); |
| 3359 | } |
| 3360 | |
| 3361 | int32_t TabletImpl::GetSnapshotOffset(uint32_t tid, uint32_t pid, |
| 3362 | std::string& msg, uint64_t& term, |