| 969 | } |
| 970 | |
| 971 | void MasterImpl::ShowTables(const ShowTablesRequest *request, ShowTablesResponse *response, |
| 972 | google::protobuf::Closure *done) { |
| 973 | response->set_sequence_id(request->sequence_id()); |
| 974 | MasterStatus master_status = GetMasterStatus(); |
| 975 | if (master_status != kIsRunning && master_status != kIsReadonly) { |
| 976 | LOG(ERROR) << "master is not ready, status_ = " |
| 977 | << StatusCodeToString(static_cast<StatusCode>(master_status)); |
| 978 | response->set_status(static_cast<StatusCode>(master_status)); |
| 979 | done->Run(); |
| 980 | return; |
| 981 | } |
| 982 | |
| 983 | std::string start_table_name; |
| 984 | if (request->has_start_table_name()) { |
| 985 | start_table_name = request->start_table_name(); |
| 986 | } |
| 987 | std::string start_tablet_key; |
| 988 | if (request->has_start_tablet_key()) { |
| 989 | start_tablet_key = request->start_tablet_key(); |
| 990 | } |
| 991 | uint32_t max_table_found = std::numeric_limits<unsigned int>::max(); |
| 992 | if (request->has_max_table_num()) { |
| 993 | max_table_found = request->max_table_num(); |
| 994 | } |
| 995 | uint32_t max_tablet_found = std::numeric_limits<unsigned int>::max(); |
| 996 | if (request->has_max_tablet_num()) { |
| 997 | max_tablet_found = request->max_tablet_num(); |
| 998 | } |
| 999 | |
| 1000 | StatusCode status = kMasterOk; |
| 1001 | std::vector<TablePtr> table_list; |
| 1002 | std::vector<TabletPtr> tablet_list; |
| 1003 | bool is_more = false; |
| 1004 | bool ret = |
| 1005 | tablet_manager_->ShowTable(&table_list, &tablet_list, start_table_name, start_tablet_key, |
| 1006 | max_table_found, max_tablet_found, &is_more, &status); |
| 1007 | if (ret) { |
| 1008 | TableMetaList *table_meta_list = response->mutable_table_meta_list(); |
| 1009 | for (uint32_t i = 0; i < table_list.size(); ++i) { |
| 1010 | TablePtr table = table_list[i]; |
| 1011 | CopyTableMetaToUser(table, table_meta_list->add_meta()); |
| 1012 | } |
| 1013 | TabletMetaList *tablet_meta_list = response->mutable_tablet_meta_list(); |
| 1014 | for (uint32_t i = 0; i < tablet_list.size(); ++i) { |
| 1015 | TabletPtr tablet = tablet_list[i]; |
| 1016 | TabletMeta meta; |
| 1017 | tablet->ToMeta(&meta); |
| 1018 | meta.set_last_move_time_us(tablet->LastMoveTime()); |
| 1019 | meta.set_data_size_on_flash(tablet->GetDataSizeOnFlash()); |
| 1020 | tablet_meta_list->add_meta()->CopyFrom(meta); |
| 1021 | tablet_meta_list->add_counter()->CopyFrom(tablet->GetCounter()); |
| 1022 | tablet_meta_list->add_timestamp(tablet->UpdateTime()); |
| 1023 | } |
| 1024 | response->set_is_more(is_more); |
| 1025 | } else { |
| 1026 | LOG(ERROR) << "fail to show all tables, status_: " << StatusCodeToString(status); |
| 1027 | } |
| 1028 |
no test coverage detected