Skip to content

Commit 1dd7a5e

Browse files
author
junchao
committed
merge master
1 parent 0beac2a commit 1dd7a5e

File tree

14 files changed

+1337
-0
lines changed

14 files changed

+1337
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
19+
package(default_visibility = ["//platform/consensus/ordering:__subpackages__"])
20+
21+
cc_library(
22+
name = "protocol_base",
23+
srcs = ["protocol_base.cpp"],
24+
hdrs = ["protocol_base.h"],
25+
deps = [
26+
"//common:comm",
27+
"//common/crypto:signature_verifier",
28+
],
29+
)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#include "platform/consensus/ordering/common/algorithm/protocol_base.h"
21+
22+
#include <glog/logging.h>
23+
24+
namespace resdb {
25+
namespace common {
26+
27+
ProtocolBase::ProtocolBase(int id, int f, int total_num,
28+
SingleCallFuncType single_call,
29+
BroadcastCallFuncType broadcast_call,
30+
CommitFuncType commit)
31+
: id_(id),
32+
f_(f),
33+
total_num_(total_num),
34+
single_call_(single_call),
35+
broadcast_call_(broadcast_call),
36+
commit_(commit) {
37+
stop_ = false;
38+
}
39+
40+
ProtocolBase::ProtocolBase(int id, int f, int total_num)
41+
: ProtocolBase(id, f, total_num, nullptr, nullptr, nullptr) {}
42+
43+
ProtocolBase::~ProtocolBase() { Stop(); }
44+
45+
void ProtocolBase::Stop() { stop_ = true; }
46+
47+
bool ProtocolBase::IsStop() { return stop_; }
48+
49+
int ProtocolBase::SendMessage(int msg_type,
50+
const google::protobuf::Message& msg,
51+
int node_id) {
52+
return single_call_(msg_type, msg, node_id);
53+
}
54+
55+
int ProtocolBase::Broadcast(int msg_type,
56+
const google::protobuf::Message& msg) {
57+
return broadcast_call_(msg_type, msg);
58+
}
59+
60+
int ProtocolBase::Commit(const google::protobuf::Message& msg) {
61+
return commit_(msg);
62+
}
63+
64+
} // namespace common
65+
} // namespace resdb
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#pragma once
21+
22+
#include <google/protobuf/message.h>
23+
24+
#include <functional>
25+
26+
#include "common/crypto/signature_verifier.h"
27+
28+
namespace resdb {
29+
namespace common {
30+
31+
class ProtocolBase {
32+
public:
33+
typedef std::function<int(int, const google::protobuf::Message& msg, int)>
34+
SingleCallFuncType;
35+
typedef std::function<int(int, const google::protobuf::Message& msg)>
36+
BroadcastCallFuncType;
37+
typedef std::function<int(const google::protobuf::Message& msg)>
38+
CommitFuncType;
39+
40+
ProtocolBase(int id, int f, int total_num, SingleCallFuncType single_call,
41+
BroadcastCallFuncType broadcast_call, CommitFuncType commit);
42+
43+
ProtocolBase(int id, int f, int total_num);
44+
45+
virtual ~ProtocolBase();
46+
47+
void Stop();
48+
49+
inline void SetSingleCallFunc(SingleCallFuncType single_call) {
50+
single_call_ = single_call;
51+
}
52+
53+
inline void SetBroadcastCallFunc(BroadcastCallFuncType broadcast_call) {
54+
broadcast_call_ = broadcast_call;
55+
}
56+
57+
inline void SetCommitFunc(CommitFuncType commit_func) {
58+
commit_ = commit_func;
59+
}
60+
61+
inline void SetSignatureVerifier(SignatureVerifier* verifier) {
62+
verifier_ = verifier;
63+
}
64+
65+
protected:
66+
int SendMessage(int msg_type, const google::protobuf::Message& msg,
67+
int node_id);
68+
int Broadcast(int msg_type, const google::protobuf::Message& msg);
69+
int Commit(const google::protobuf::Message& msg);
70+
71+
bool IsStop();
72+
73+
protected:
74+
int id_;
75+
int f_;
76+
int total_num_;
77+
std::function<int(int, const google::protobuf::Message& msg, int)>
78+
single_call_;
79+
std::function<int(int, const google::protobuf::Message& msg)> broadcast_call_;
80+
std::function<int(const google::protobuf::Message& msg)> commit_;
81+
std::atomic<bool> stop_;
82+
83+
SignatureVerifier* verifier_;
84+
};
85+
86+
} // namespace common
87+
} // namespace resdb
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
19+
package(default_visibility = ["//platform/consensus/ordering:__subpackages__"])
20+
21+
cc_library(
22+
name = "consensus",
23+
srcs = ["consensus.cpp"],
24+
hdrs = ["consensus.h"],
25+
deps = [
26+
":performance_manager",
27+
":response_manager",
28+
"//common/utils",
29+
"//executor/common:transaction_manager",
30+
"//platform/consensus/execution:transaction_executor",
31+
"//platform/consensus/ordering/common/algorithm:protocol_base",
32+
"//platform/networkstrate:consensus_manager",
33+
],
34+
)
35+
36+
cc_library(
37+
name = "performance_manager",
38+
srcs = ["performance_manager.cpp"],
39+
hdrs = ["performance_manager.h"],
40+
deps = [
41+
":transaction_utils",
42+
"//platform/networkstrate:replica_communicator",
43+
"//platform/networkstrate:server_comm",
44+
],
45+
)
46+
47+
cc_library(
48+
name = "response_manager",
49+
srcs = ["response_manager.cpp"],
50+
hdrs = ["response_manager.h"],
51+
deps = [
52+
":transaction_utils",
53+
"//platform/networkstrate:replica_communicator",
54+
"//platform/networkstrate:server_comm",
55+
],
56+
)
57+
58+
cc_library(
59+
name = "transaction_utils",
60+
srcs = ["transaction_utils.cpp"],
61+
hdrs = ["transaction_utils.h"],
62+
visibility = ["//visibility:public"],
63+
deps = [
64+
"//platform/proto:resdb_cc_proto",
65+
],
66+
)

0 commit comments

Comments
 (0)