Skip to content

Commit

Permalink
add get block numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
JunchaoChen committed Jan 15, 2024
1 parent 5601a1e commit 95443cd
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
3 changes: 1 addition & 2 deletions interface/common/resdb_state_accessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ std::unique_ptr<NetChannel> ResDBStateAccessor::GetNetChannel(
}

// Obtain ReplicaState of each replica.
absl::StatusOr<ReplicaState>
ResDBStateAccessor::GetReplicaState() {
absl::StatusOr<ReplicaState> ResDBStateAccessor::GetReplicaState() {
const auto& client_info = config_.GetReplicaInfos()[0];

Request request;
Expand Down
2 changes: 1 addition & 1 deletion interface/common/resdb_state_accessor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
namespace resdb {
namespace {

using ::resdb::testing::EqualsProto;
using ::google::protobuf::util::MessageDifferencer;
using ::resdb::testing::EqualsProto;
using ::testing::ElementsAre;
using ::testing::Invoke;
using ::testing::Test;
Expand Down
40 changes: 40 additions & 0 deletions interface/common/resdb_txn_accessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,44 @@ absl::StatusOr<std::vector<Request>> ResDBTxnAccessor::GetRequestFromReplica(
return txn_resp;
}

absl::StatusOr<uint64_t> ResDBTxnAccessor::GetBlockNumbers() {
QueryRequest request;
request.set_min_seq(0);
request.set_max_seq(0);

std::vector<std::unique_ptr<NetChannel>> clients;
std::vector<std::thread> ths;
std::string final_str;
std::mutex mtx;
std::condition_variable resp_cv;

std::unique_ptr<NetChannel> client =
GetNetChannel(replicas_[0].ip(), replicas_[0].port());

LOG(ERROR) << "ip:" << replicas_[0].ip() << " port:" << replicas_[0].port();

std::string response_str;
int ret = 0;
for (int i = 0; i < 5; ++i) {
ret = client->SendRequest(request, Request::TYPE_QUERY);
if (ret) {
continue;
}
client->SetRecvTimeout(100000);
ret = client->RecvRawMessageStr(&response_str);
LOG(ERROR) << "receive str:" << ret << " len:" << response_str.size();
if (ret != 0) {
continue;
}
break;
}

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

} // namespace resdb
2 changes: 2 additions & 0 deletions interface/common/resdb_txn_accessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class ResDBTxnAccessor {
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:
virtual std::unique_ptr<NetChannel> GetNetChannel(const std::string& ip,
int port);
Expand Down
6 changes: 3 additions & 3 deletions platform/networkstrate/consensus_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ int ConsensusManager::ProcessHeartBeat(std::unique_ptr<Context> context,
}

LOG(ERROR) << "receive public size:" << hb_info.public_keys().size()
<< " primary:" << hb_info.primary()
<< " version:" << hb_info.version()
<< " from region:" << request->region_info().region_id();
<< " primary:" << hb_info.primary()
<< " version:" << hb_info.version()
<< " from region:" << request->region_info().region_id();

if (request->region_info().region_id() ==
config_.GetConfigData().self_region_id()) {
Expand Down
1 change: 1 addition & 0 deletions platform/proto/resdb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ message QueryRequest {

message QueryResponse {
repeated Request transactions = 1;
uint64 max_seq = 2;
}

message CustomQueryResponse {
Expand Down

0 comments on commit 95443cd

Please sign in to comment.