Skip to content

Commit

Permalink
Fix Bug (#142)
Browse files Browse the repository at this point in the history
* fix viewchange bug

* format code

* rm unused log

* rm unused log

* fix ut
  • Loading branch information
cjcchen authored May 3, 2024
1 parent 36f38bc commit 9123cf9
Show file tree
Hide file tree
Showing 48 changed files with 613 additions and 467 deletions.
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ http_archive(
http_archive(
name = "pybind11_bazel",
strip_prefix = "pybind11_bazel-2.11.1.bzl.1",
urls = ["https://github.com/pybind/pybind11_bazel/archive/refs/tags/v2.11.1.bzl.1.zip"]
urls = ["https://github.com/pybind/pybind11_bazel/archive/refs/tags/v2.11.1.bzl.1.zip"],
)

http_archive(
Expand Down Expand Up @@ -244,4 +244,4 @@ http_archive(
sha256 = "babcdfd2c744905a73d20de211b51367bda0d5200f11d654c4314b909d8c963c",
strip_prefix = "asio-asio-1-26-0",
url = "https://github.com/chriskohlhoff/asio/archive/refs/tags/asio-1-26-0.zip",
)
)
7 changes: 4 additions & 3 deletions api/BUILD
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package(default_visibility = ["//visibility:public"])

cc_binary(
name = "pybind_kv.so",
srcs = ["pybind_kv_service.cpp"],
linkshared =1,
linkshared = 1,
linkstatic = 1,
deps = [
"@//common/proto:signature_info_cc_proto",
"@//interface/kv:kv_client",
"@//platform/config:resdb_config_utils",
"@pybind11//:pybind11",
"@pybind11",
],
)

py_library(
name = "pybind_kv_so",
data = [":pybind_kv.so"],
imports = ["."],
)

47 changes: 22 additions & 25 deletions api/pybind_kv_service.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include <fcntl.h>
#include <getopt.h>
#include <pybind11/pybind11.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <pybind11/pybind11.h>

#include <fstream>

#include "common/proto/signature_info.pb.h"
#include "interface/kv/kv_client.h"
#include "platform/config/resdb_config_utils.h"
Expand All @@ -16,35 +17,31 @@ using resdb::KVClient;
using resdb::ReplicaInfo;
using resdb::ResDBConfig;




std::string get(std::string key, std::string config_path) {
ResDBConfig config = GenerateResDBConfig(config_path);
config.SetClientTimeoutMs(100000);
KVClient client(config);
auto result_ptr = client.Get(key);
if (result_ptr) {
return *result_ptr;
} else {
return "";
}
ResDBConfig config = GenerateResDBConfig(config_path);
config.SetClientTimeoutMs(100000);
KVClient client(config);
auto result_ptr = client.Get(key);
if (result_ptr) {
return *result_ptr;
} else {
return "";
}
}

bool set(std::string key, std::string value, std::string config_path) {
ResDBConfig config = GenerateResDBConfig(config_path);
config.SetClientTimeoutMs(100000);
KVClient client(config);
int result = client.Set(key, value);
if (result == 0) {
return true;
} else {
return false;
}
ResDBConfig config = GenerateResDBConfig(config_path);
config.SetClientTimeoutMs(100000);
KVClient client(config);
int result = client.Set(key, value);
if (result == 0) {
return true;
} else {
return false;
}
}

PYBIND11_MODULE(pybind_kv, m) {
m.def("get", &get, "A function that gets a value from the key-value store");
m.def("set", &set, "A function that sets a value in the key-value store");
m.def("get", &get, "A function that gets a value from the key-value store");
m.def("set", &set, "A function that sets a value in the key-value store");
}

1 change: 0 additions & 1 deletion benchmark/protocols/poe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ cc_binary(
"//service/utils:server_factory",
],
)

2 changes: 1 addition & 1 deletion benchmark/protocols/poe/kv_server_performance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ int main(int argc, char** argv) {
request.SerializeToString(&request_data);
return request_data;
});

auto server =
std::make_unique<ServiceNetwork>(*config, std::move(performance_consens));
server->Run();
Expand Down
6 changes: 3 additions & 3 deletions common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ cc_library(
)

cc_library(
name= "beast",
name = "beast",
deps = [
"@boost//:beast"
]
"@boost//:beast",
],
)

cc_library(
Expand Down
18 changes: 8 additions & 10 deletions interface/common/resdb_txn_accessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,12 @@ ResDBTxnAccessor::GetTxn(uint64_t min_seq, uint64_t max_seq) {
ths.push_back(std::thread(
[&](NetChannel* client) {
std::string response_str;
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);
int ret = client->SendRequest(request, Request::TYPE_QUERY);
if (ret) {
return;
}
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 @@ -160,11 +157,12 @@ absl::StatusOr<uint64_t> ResDBTxnAccessor::GetBlockNumbers() {
std::string final_str;
std::mutex mtx;
std::condition_variable resp_cv;
bool success = false;

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

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

std::string response_str;
int ret = 0;
Expand All @@ -175,7 +173,7 @@ absl::StatusOr<uint64_t> ResDBTxnAccessor::GetBlockNumbers() {
}
client->SetRecvTimeout(100000);
ret = client->RecvRawMessageStr(&response_str);
LOG(ERROR) << "receive str:" << ret << " len:" << response_str.size();
LOG(INFO) << "receive str:" << ret << " len:" << response_str.size();
if (ret != 0) {
continue;
}
Expand Down
6 changes: 4 additions & 2 deletions interface/common/resdb_txn_accessor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ TEST(ResDBTxnAccessorTest, GetTransactionsFail) {
auto client = std::make_unique<MockNetChannel>(ip, port);
EXPECT_CALL(*client,
SendRequest(EqualsProto(request), Request::TYPE_QUERY, _))
.Times(AtLeast(1)).WillRepeatedly(Return(0));
.Times(AtLeast(1))
.WillRepeatedly(Return(0));
EXPECT_CALL(*client, RecvRawMessageStr)
.Times(AtLeast(1)).WillRepeatedly(Invoke([&](std::string* resp) { return -1; }));
.Times(AtLeast(1))
.WillRepeatedly(Invoke([&](std::string* resp) { return -1; }));
return client;
}));
absl::StatusOr<std::vector<std::pair<uint64_t, std::string>>> resp =
Expand Down
1 change: 0 additions & 1 deletion platform/consensus/ordering/common/algorithm/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ cc_library(
"//common/crypto:signature_verifier",
],
)

45 changes: 19 additions & 26 deletions platform/consensus/ordering/common/algorithm/protocol_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,42 @@
namespace resdb {
namespace common {

ProtocolBase::ProtocolBase(
int id,
int f,
int total_num,
SingleCallFuncType single_call,
BroadcastCallFuncType broadcast_call,
CommitFuncType commit) :
id_(id),
ProtocolBase::ProtocolBase(int id, int f, int total_num,
SingleCallFuncType single_call,
BroadcastCallFuncType broadcast_call,
CommitFuncType commit)
: id_(id),
f_(f),
total_num_(total_num),
single_call_(single_call),
broadcast_call_(broadcast_call),
single_call_(single_call),
broadcast_call_(broadcast_call),
commit_(commit) {
stop_ = false;
stop_ = false;
}

ProtocolBase::ProtocolBase( int id, int f, int total_num) : ProtocolBase(id, f, total_num, nullptr, nullptr, nullptr){
ProtocolBase::ProtocolBase(int id, int f, int total_num)
: ProtocolBase(id, f, total_num, nullptr, nullptr, nullptr) {}

}
ProtocolBase::~ProtocolBase() { Stop(); }

ProtocolBase::~ProtocolBase() {
Stop();
}
void ProtocolBase::Stop() { stop_ = true; }

void ProtocolBase::Stop(){
stop_ = true;
}
bool ProtocolBase::IsStop() { return stop_; }

bool ProtocolBase::IsStop(){
return stop_;
}

int ProtocolBase::SendMessage(int msg_type, const google::protobuf::Message& msg, int node_id) {
int ProtocolBase::SendMessage(int msg_type,
const google::protobuf::Message& msg,
int node_id) {
return single_call_(msg_type, msg, node_id);
}

int ProtocolBase::Broadcast(int msg_type, const google::protobuf::Message& msg) {
int ProtocolBase::Broadcast(int msg_type,
const google::protobuf::Message& msg) {
return broadcast_call_(msg_type, msg);
}

int ProtocolBase::Commit(const google::protobuf::Message& msg) {
return commit_(msg);
}

} // namespace protocol
} // namespace common
} // namespace resdb
64 changes: 34 additions & 30 deletions platform/consensus/ordering/common/algorithm/protocol_base.h
Original file line number Diff line number Diff line change
@@ -1,64 +1,68 @@
#pragma once

#include <functional>
#include <google/protobuf/message.h>

#include <functional>

#include "common/crypto/signature_verifier.h"

namespace resdb {
namespace common {

class ProtocolBase {
public:
typedef std::function<int(int, const google::protobuf::Message& msg, int)> SingleCallFuncType;
typedef std::function<int(int, const google::protobuf::Message& msg)> BroadcastCallFuncType;
typedef std::function<int(const google::protobuf::Message& msg)> CommitFuncType;
typedef std::function<int(int, const google::protobuf::Message& msg, int)>
SingleCallFuncType;
typedef std::function<int(int, const google::protobuf::Message& msg)>
BroadcastCallFuncType;
typedef std::function<int(const google::protobuf::Message& msg)>
CommitFuncType;

ProtocolBase(
int id,
int f,
int total_num,
SingleCallFuncType single_call,
BroadcastCallFuncType broadcast_call,
CommitFuncType commit
);

ProtocolBase( int id, int f, int total_num);
ProtocolBase(int id, int f, int total_num, SingleCallFuncType single_call,
BroadcastCallFuncType broadcast_call, CommitFuncType commit);

ProtocolBase(int id, int f, int total_num);

virtual ~ProtocolBase();

void Stop();

inline
void SetSingleCallFunc(SingleCallFuncType single_call) { single_call_ = single_call; }

inline
void SetBroadcastCallFunc(BroadcastCallFuncType broadcast_call) { broadcast_call_ = broadcast_call; }
inline void SetSingleCallFunc(SingleCallFuncType single_call) {
single_call_ = single_call;
}

inline void SetBroadcastCallFunc(BroadcastCallFuncType broadcast_call) {
broadcast_call_ = broadcast_call;
}

inline
void SetCommitFunc(CommitFuncType commit_func) { commit_ = commit_func; }
inline void SetCommitFunc(CommitFuncType commit_func) {
commit_ = commit_func;
}

inline
void SetSignatureVerifier(SignatureVerifier* verifier) { verifier_ = verifier;}
inline void SetSignatureVerifier(SignatureVerifier* verifier) {
verifier_ = verifier;
}

protected:
int SendMessage(int msg_type, const google::protobuf::Message& msg, int node_id);
int Broadcast(int msg_type, const google::protobuf::Message& msg);
int Commit(const google::protobuf::Message& msg);
protected:
int SendMessage(int msg_type, const google::protobuf::Message& msg,
int node_id);
int Broadcast(int msg_type, const google::protobuf::Message& msg);
int Commit(const google::protobuf::Message& msg);

bool IsStop();
bool IsStop();

protected:
int id_;
int f_;
int total_num_;
std::function<int(int, const google::protobuf::Message& msg, int)> single_call_;
std::function<int(int, const google::protobuf::Message& msg, int)>
single_call_;
std::function<int(int, const google::protobuf::Message& msg)> broadcast_call_;
std::function<int(const google::protobuf::Message& msg)> commit_;
std::atomic<bool> stop_;

SignatureVerifier* verifier_;
};

} // namespace protocol
} // namespace common
} // namespace resdb
1 change: 0 additions & 1 deletion platform/consensus/ordering/common/framework/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ cc_library(
],
)


cc_library(
name = "response_manager",
srcs = ["response_manager.cpp"],
Expand Down
Loading

0 comments on commit 9123cf9

Please sign in to comment.