43 request.set_min_seq(min_seq);
44 request.set_max_seq(max_seq);
46 std::vector<std::unique_ptr<NetChannel>> clients;
47 std::vector<std::thread> ths;
48 std::string final_str;
50 std::condition_variable resp_cv;
52 std::map<std::string, int> recv_count;
53 for (
const auto& replica : replicas_) {
54 std::unique_ptr<NetChannel> client =
57 clients.push_back(std::move(client));
59 ths.push_back(std::thread(
61 std::string response_str;
62 int ret = client->SendRequest(request, Request::TYPE_QUERY);
66 client->SetRecvTimeout(1000);
67 ret = client->RecvRawMessageStr(&response_str);
69 std::unique_lock<std::mutex> lck(mtx);
70 recv_count[response_str]++;
73 final_str = response_str;
85 std::unique_lock<std::mutex> lck(mtx);
86 resp_cv.wait_for(lck, std::chrono::seconds(recv_timeout_));
88 for (
auto& client : clients) {
94 for (
auto& th : ths) {
100 std::vector<std::pair<uint64_t, std::string>> txn_resp;
102 if (success && final_str.empty()) {
106 if (final_str.empty() || !resp.ParseFromString(final_str)) {
107 LOG(ERROR) <<
"parse fail len:" << final_str.size();
108 return absl::InternalError(
"recv data fail.");
110 for (
auto& transaction : resp.transactions()) {
111 txn_resp.push_back(std::make_pair(transaction.seq(), transaction.data()));
117 uint64_t min_seq, uint64_t max_seq,
const ReplicaInfo& replica) {
118 QueryRequest request;
119 request.set_min_seq(min_seq);
120 request.set_max_seq(max_seq);
122 std::unique_ptr<NetChannel> client =
125 std::string response_str;
126 int ret = client->SendRequest(request, Request::TYPE_QUERY);
128 return absl::InternalError(
"send data fail.");
130 client->SetRecvTimeout(1000);
131 ret = client->RecvRawMessageStr(&response_str);
133 return absl::InternalError(
"recv data fail.");
138 if (!resp.ParseFromString(response_str)) {
139 LOG(ERROR) <<
"parse fail len:" << response_str.size();
140 return absl::InternalError(
"recv data fail.");
143 std::vector<Request> txn_resp;
144 for (
auto& transaction : resp.transactions()) {
145 txn_resp.push_back(transaction);