get tablet key range
| 1103 | |
| 1104 | // get tablet key range |
| 1105 | int ScanTabletMeta(const std::string& table_name, const std::string& prefix_path, |
| 1106 | std::map<std::string, std::pair<std::string, std::string>>* map_scan, |
| 1107 | std::vector<std::string>* fail_tablet, uint64_t* tablet_num) { |
| 1108 | std::vector<std::string> tablets; |
| 1109 | char table_path[512] = {0}; |
| 1110 | |
| 1111 | snprintf(table_path, sizeof(table_path), "%s/%s", prefix_path.c_str(), table_name.c_str()); |
| 1112 | int ret = DfsListDir(table_path, &tablets); |
| 1113 | if (0 != ret) { |
| 1114 | LOG(INFO) << "get table path fail:" << table_path; |
| 1115 | return ret; |
| 1116 | } |
| 1117 | *tablet_num = GetTabletNumFromName(tablets[tablets.size() - 1]); |
| 1118 | LOG(INFO) << "table:" << table_name << "tablet count" << tablets.size() |
| 1119 | << "largest tablet_num:" << *tablet_num; |
| 1120 | |
| 1121 | std::string startkey_scan; |
| 1122 | std::string endkey_scan; |
| 1123 | std::pair<std::string, std::string> keyrange_scan; |
| 1124 | |
| 1125 | for (size_t i = 0; i < tablets.size(); i++) { |
| 1126 | ret = GetTabletKeyRange(prefix_path, table_name, tablets[i], startkey_scan, endkey_scan); |
| 1127 | if (0 != ret) { |
| 1128 | LOG(INFO) << "fail table:" << table_name << "tablet:" << tablets[i]; |
| 1129 | fail_tablet->push_back(tablets[i]); |
| 1130 | continue; |
| 1131 | } |
| 1132 | // add to tablet scan map |
| 1133 | keyrange_scan = make_pair(endkey_scan, table_name + "/" + tablets[i]); |
| 1134 | |
| 1135 | auto it = map_scan->find(startkey_scan); |
| 1136 | if (it == map_scan->end()) { |
| 1137 | map_scan->insert(make_pair(startkey_scan, keyrange_scan)); |
| 1138 | } else { |
| 1139 | // the same startkey, save the tablet num bigger one |
| 1140 | LOG(INFO) << "start key overlap : 1." << tablets[i] << "2." << it->second.second; |
| 1141 | if (keyrange_scan.second > it->second.second) { |
| 1142 | map_scan->erase(it->first); |
| 1143 | map_scan->insert(make_pair(startkey_scan, keyrange_scan)); |
| 1144 | } |
| 1145 | } |
| 1146 | } |
| 1147 | |
| 1148 | LOG(INFO) << "table:" << table_name << "abnormal count" << fail_tablet->size(); |
| 1149 | return 0; |
| 1150 | } |
| 1151 | |
| 1152 | // get tablet key range |
| 1153 | int ScanAndDiff(const std::string& table_name, const std::string& prefix_path) { |
no test coverage detected