Skip to content

Commit

Permalink
fix get txn bug
Browse files Browse the repository at this point in the history
  • Loading branch information
JunchaoChen committed Jan 15, 2024
1 parent 95443cd commit 9c6a829
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 42 deletions.
47 changes: 8 additions & 39 deletions interface/common/resdb_txn_accessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ ResDBTxnAccessor::GetTxn(uint64_t min_seq, uint64_t max_seq) {
ths.push_back(std::thread(
[&](NetChannel* client) {
std::string response_str;
int ret = client->SendRequest(request, Request::TYPE_QUERY);
if (ret) {
return;
int ret = -1;
for (int i = 0; i < 3 && ret < 0; ++i) {
ret = client->SendRequest(request, Request::TYPE_QUERY);
if (ret) {
return;
}
client->SetRecvTimeout(1000);
ret = client->RecvRawMessageStr(&response_str);
}
client->SetRecvTimeout(1000);
ret = client->RecvRawMessageStr(&response_str);
if (ret == 0) {
std::unique_lock<std::mutex> lck(mtx);
recv_count[response_str]++;
Expand Down Expand Up @@ -113,40 +116,6 @@ ResDBTxnAccessor::GetTxn(uint64_t min_seq, uint64_t max_seq) {
return txn_resp;
}

absl::StatusOr<std::vector<Request>> ResDBTxnAccessor::GetRequestFromReplica(
uint64_t min_seq, uint64_t max_seq, const ReplicaInfo& replica) {
QueryRequest request;
request.set_min_seq(min_seq);
request.set_max_seq(max_seq);

std::unique_ptr<NetChannel> client =
GetNetChannel(replica.ip(), replica.port());

std::string response_str;
int ret = client->SendRequest(request, Request::TYPE_QUERY);
if (ret) {
return absl::InternalError("send data fail.");
}
client->SetRecvTimeout(1000);
ret = client->RecvRawMessageStr(&response_str);
if (ret) {
return absl::InternalError("recv data fail.");
}

QueryResponse resp;

if (!resp.ParseFromString(response_str)) {
LOG(ERROR) << "parse fail len:" << response_str.size();
return absl::InternalError("recv data fail.");
}

std::vector<Request> txn_resp;
for (auto& transaction : resp.transactions()) {
txn_resp.push_back(transaction);
}
return txn_resp;
}

absl::StatusOr<uint64_t> ResDBTxnAccessor::GetBlockNumbers() {
QueryRequest request;
request.set_min_seq(0);
Expand Down
3 changes: 0 additions & 3 deletions interface/common/resdb_txn_accessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ class ResDBTxnAccessor {
virtual absl::StatusOr<std::vector<std::pair<uint64_t, std::string>>> GetTxn(
uint64_t min_seq, uint64_t max_seq);

virtual absl::StatusOr<std::vector<Request>> GetRequestFromReplica(
uint64_t min_seq, uint64_t max_seq, const ReplicaInfo& replica);

virtual absl::StatusOr<uint64_t> GetBlockNumbers();

protected:
Expand Down

0 comments on commit 9c6a829

Please sign in to comment.