| 2982 | } |
| 2983 | |
| 2984 | void HandleNSClientSetTablePartition(const std::vector<std::string>& parts, |
| 2985 | ::fedb::client::NsClient* client) { |
| 2986 | if (parts.size() < 3) { |
| 2987 | std::cout << "Bad format" << std::endl; |
| 2988 | return; |
| 2989 | } |
| 2990 | std::string name = parts[1]; |
| 2991 | int fd = open(parts[2].c_str(), O_RDONLY); |
| 2992 | if (fd < 0) { |
| 2993 | std::cout << "can not open file " << parts[2] << std::endl; |
| 2994 | return; |
| 2995 | } |
| 2996 | ::fedb::nameserver::TablePartition table_partition; |
| 2997 | google::protobuf::io::FileInputStream fileInput(fd); |
| 2998 | fileInput.SetCloseOnDelete(true); |
| 2999 | if (!google::protobuf::TextFormat::Parse(&fileInput, &table_partition)) { |
| 3000 | std::cout << "table partition file format error" << std::endl; |
| 3001 | return; |
| 3002 | } |
| 3003 | std::set<std::string> leader_set; |
| 3004 | std::set<std::string> follower_set; |
| 3005 | for (int idx = 0; idx < table_partition.partition_meta_size(); idx++) { |
| 3006 | std::string endpoint = table_partition.partition_meta(idx).endpoint(); |
| 3007 | if (table_partition.partition_meta(idx).is_leader()) { |
| 3008 | if (leader_set.find(endpoint) != leader_set.end()) { |
| 3009 | std::cout << "has same leader " << endpoint << std::endl; |
| 3010 | return; |
| 3011 | } |
| 3012 | leader_set.insert(endpoint); |
| 3013 | } else { |
| 3014 | if (follower_set.find(endpoint) != follower_set.end()) { |
| 3015 | std::cout << "has same follower" << endpoint << std::endl; |
| 3016 | return; |
| 3017 | } |
| 3018 | follower_set.insert(endpoint); |
| 3019 | } |
| 3020 | } |
| 3021 | if (leader_set.empty()) { |
| 3022 | std::cout << "has no leader" << std::endl; |
| 3023 | return; |
| 3024 | } |
| 3025 | |
| 3026 | std::string msg; |
| 3027 | if (!client->SetTablePartition(name, table_partition, msg)) { |
| 3028 | std::cout << "Fail to set table partition. error msg: " << msg |
| 3029 | << std::endl; |
| 3030 | return; |
| 3031 | } |
| 3032 | std::cout << "set table partition ok" << std::endl; |
| 3033 | } |
| 3034 | |
| 3035 | void HandleNsClientSQL(const std::string sql, |
| 3036 | ::fedb::client::NsClient* client) { |
no test coverage detected