| 3041 | } |
| 3042 | |
| 3043 | void HandleNSClientGetTablePartition(const std::vector<std::string>& parts, |
| 3044 | ::fedb::client::NsClient* client) { |
| 3045 | if (parts.size() < 3) { |
| 3046 | std::cout << "Bad format" << std::endl; |
| 3047 | return; |
| 3048 | } |
| 3049 | std::string name = parts[1]; |
| 3050 | uint32_t pid = 0; |
| 3051 | try { |
| 3052 | pid = boost::lexical_cast<uint32_t>(parts[2]); |
| 3053 | } catch (std::exception const& e) { |
| 3054 | std::cout << "Invalid args. pid should be uint32_t" << std::endl; |
| 3055 | return; |
| 3056 | } |
| 3057 | ::fedb::nameserver::TablePartition table_partition; |
| 3058 | std::string msg; |
| 3059 | if (!client->GetTablePartition(name, pid, table_partition, msg)) { |
| 3060 | std::cout << "Fail to get table partition. error msg: " << msg |
| 3061 | << std::endl; |
| 3062 | return; |
| 3063 | } |
| 3064 | std::string value; |
| 3065 | google::protobuf::TextFormat::PrintToString(table_partition, &value); |
| 3066 | std::string file_name = name + "_" + parts[2] + ".txt"; |
| 3067 | FILE* fd_write = fopen(file_name.c_str(), "w"); |
| 3068 | if (fd_write == NULL) { |
| 3069 | PDLOG(WARNING, "fail to open file %s", file_name.c_str()); |
| 3070 | std::cout << "fail to open file" << file_name << std::endl; |
| 3071 | return; |
| 3072 | } |
| 3073 | bool io_error = false; |
| 3074 | if (fputs(value.c_str(), fd_write) == EOF) { |
| 3075 | std::cout << "write error" << std::endl; |
| 3076 | io_error = true; |
| 3077 | } |
| 3078 | if (!io_error && |
| 3079 | ((fflush(fd_write) == EOF) || fsync(fileno(fd_write)) == -1)) { |
| 3080 | std::cout << "flush error" << std::endl; |
| 3081 | io_error = true; |
| 3082 | } |
| 3083 | fclose(fd_write); |
| 3084 | if (!io_error) { |
| 3085 | std::cout << "get table partition ok" << std::endl; |
| 3086 | } |
| 3087 | } |
| 3088 | |
| 3089 | void HandleNSClientUpdateTableAlive(const std::vector<std::string>& parts, |
| 3090 | ::fedb::client::NsClient* client) { |
no test coverage detected