Skip to content

Commit 2aa8d1c

Browse files
authored
Merge pull request #19 from socutes:openraft
openraft implementation is supported
2 parents b14e782 + ff4b888 commit 2aa8d1c

30 files changed

+649
-213
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ src/rlog/log/server.log
99
.idea/.gitignore
1010
.idea/modules.xml
1111
.idea/robustmq.iml
12-
.idea/vcs.xml
12+
.idea/vcs.xml
13+
logs

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ mobc = "0.8.4"
4949
openraft = { git = "https://github.com/databendlabs/openraft.git", features = [
5050
"serde",
5151
"type-alias",
52+
"loosen-follower-log-revert",
5253
] }
5354
byteorder = "1.5.0"
5455
tracing = "0.1.40"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2023 RobustMQ Team
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
cluster_name = "placement-test"
16+
addr = "127.0.0.1"
17+
node_id = 2
18+
grpc_port = 1228
19+
http_port = 8972
20+
nodes = { 2 = "127.0.0.1:1228", 3 = "127.0.0.1:1238", 4 = "127.0.0.1:1248" }
21+
data_path = "/tmp/placement-center-geek/geek-2"
22+
23+
[log]
24+
log_config = "./config/log4rs.yaml"
25+
log_path = "./logs/2"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2023 RobustMQ Team
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
cluster_name = "placement-test"
16+
addr = "127.0.0.1"
17+
node_id = 3
18+
grpc_port = 1238
19+
http_port = 8973
20+
nodes = { 2 = "127.0.0.1:1228", 3 = "127.0.0.1:1238", 4 = "127.0.0.1:1248" }
21+
data_path = "/tmp/placement-center-geek/geek-3"
22+
23+
[log]
24+
log_config = "./config/log4rs.yaml"
25+
log_path = "./logs/3"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2023 RobustMQ Team
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
cluster_name = "placement-test"
16+
addr = "127.0.0.1"
17+
node_id = 4
18+
grpc_port = 1248
19+
http_port = 8974
20+
nodes = { 2 = "127.0.0.1:1228", 3 = "127.0.0.1:1238", 4 = "127.0.0.1:1248" }
21+
data_path = "/tmp/placement-center-geek/geek-4"
22+
23+
[log]
24+
log_config = "./config/log4rs.yaml"
25+
log_path = "./logs/4"

config/log4rs.yaml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,31 @@ appenders:
4545
pattern: "{$path}/requests-log-{}.log"
4646
base: 0
4747
count: 50
48+
raft:
49+
kind: rolling_file
50+
path: "{$path}/raft.log"
51+
encoder:
52+
pattern: "{d(%Y-%m-%d %H:%M:%S)} {h({l})} {m}{n}"
53+
policy:
54+
trigger:
55+
kind: size
56+
limit: 1 gb
57+
roller:
58+
kind: fixed_window
59+
pattern: "{$path}/raft-{}.log"
60+
base: 0
61+
count: 50
4862

4963
root:
5064
level: info
5165
appenders:
5266
- stdout
53-
- server
67+
- server
68+
69+
loggers:
70+
openraft:
71+
level: info
72+
appenders:
73+
- stdout
74+
- raft
75+
additive: false

config/placement-center.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ node_id = 1
1818
grpc_port = 8871
1919
http_port = 8971
2020
nodes = { 1 = "127.0.0.1:1228" }
21-
data_path = "/tmp/placement-center"
21+
data_path = "/tmp/placement-center-geek/geek-local"
2222

2323
[log]
2424
log_config = "./config/log4rs.yaml"
25-
log_path = "./logs"
25+
log_path = "./logs"

logs/raft.log

Lines changed: 0 additions & 12 deletions
This file was deleted.

logs/server.log

Lines changed: 9 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,9 @@
1-
2024-08-20 14:07:28 INFO PlacementCenterConfig { node_id: 1, grpc_port: 1228, log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
2-
2024-08-20 14:07:28 INFO server log
3-
2024-08-20 14:07:28 INFO network log
4-
2024-08-20 14:07:28 INFO start server log
5-
2024-08-23 09:59:22 INFO PlacementCenterConfig { node_id: 1, grpc_port: 1228, http_port: 1227, log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
6-
2024-08-23 09:59:22 INFO server log
7-
2024-08-23 09:59:22 INFO network log
8-
2024-08-23 09:59:22 INFO start server log
9-
2024-08-23 09:59:29 INFO PlacementCenterConfig { node_id: 1, grpc_port: 1228, http_port: 1227, log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
10-
2024-08-23 09:59:29 INFO server log
11-
2024-08-23 09:59:29 INFO network log
12-
2024-08-23 09:59:29 INFO start server log
13-
2024-08-23 10:03:43 INFO PlacementCenterConfig { node_id: 1, grpc_port: 1228, http_port: 1227, log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
14-
2024-08-23 10:05:19 INFO PlacementCenterConfig { node_id: 1, grpc_port: 8871, http_port: 8971, log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
15-
2024-08-23 10:06:10 INFO PlacementCenterConfig { node_id: 1, grpc_port: 8871, http_port: 8971, log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
16-
2024-08-23 10:06:27 INFO PlacementCenterConfig { node_id: 1, grpc_port: 8871, http_port: 8971, log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
17-
2024-08-23 10:06:37 INFO PlacementCenterConfig { node_id: 1, grpc_port: 8871, http_port: 8971, log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
18-
2024-08-23 10:07:05 INFO PlacementCenterConfig { node_id: 1, grpc_port: 8871, http_port: 8971, log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
19-
2024-08-23 10:17:15 INFO PlacementCenterConfig { node_id: 1, grpc_port: 8871, http_port: 8971, log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
20-
2024-08-23 10:18:22 INFO PlacementCenterConfig { node_id: 1, grpc_port: 8871, http_port: 8971, log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
21-
2024-08-25 09:47:39 INFO PlacementCenterConfig { node_id: 1, grpc_port: 8871, http_port: 8971, log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
22-
2024-08-25 10:18:26 INFO PlacementCenterConfig { node_id: 1, grpc_port: 8871, http_port: 8971, log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
23-
2024-08-25 10:20:14 INFO PlacementCenterConfig { node_id: 1, grpc_port: 8871, http_port: 8971, log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
24-
2024-08-25 10:20:14 INFO Broker Grpc Server start. port:8871
25-
2024-08-25 10:50:42 INFO PlacementCenterConfig { node_id: 1, grpc_port: 8871, http_port: 8971, log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
26-
2024-08-25 10:50:42 INFO Broker Grpc Server start. port:8871
27-
2024-08-25 10:51:06 INFO When ctrl + c is received, the service starts to stop
28-
2024-08-25 10:51:06 INFO HTTP Server stopped successfully
29-
2024-08-25 10:51:06 INFO HTTP Server stopped successfully
30-
2024-08-25 10:51:18 INFO PlacementCenterConfig { node_id: 1, grpc_port: 8871, http_port: 8971, log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
31-
2024-08-25 10:51:18 INFO Broker Grpc Server start. port:8871
32-
2024-08-25 10:51:18 INFO Broker HTTP Server start. port:8971
33-
2024-08-25 10:52:30 INFO When ctrl + c is received, the service starts to stop
34-
2024-08-25 10:52:30 INFO HTTP Server stopped successfully
35-
2024-08-25 10:52:30 INFO HTTP Server stopped successfully
36-
2024-08-25 10:52:37 INFO PlacementCenterConfig { node_id: 1, grpc_port: 8871, http_port: 8971, log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
37-
2024-08-25 10:52:37 INFO Broker HTTP Server start. port:8971
38-
2024-08-25 10:52:37 INFO Broker Grpc Server start. port:8871
39-
2024-08-25 10:52:40 INFO When ctrl + c is received, the service starts to stop
40-
2024-08-25 10:52:40 INFO HTTP Server stopped successfully
41-
2024-08-25 10:52:40 INFO HTTP Server stopped successfully
42-
2024-08-25 10:56:25 INFO PlacementCenterConfig { node_id: 1, grpc_port: 8871, http_port: 8971, log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
43-
2024-08-25 10:56:25 INFO Broker HTTP Server start. port:8971
44-
2024-08-25 10:56:25 INFO Broker Grpc Server start. port:8871
45-
2024-08-25 10:56:27 INFO When ctrl + c is received, the service starts to stop
46-
2024-08-25 10:56:27 INFO HTTP Server stopped successfully
47-
2024-08-25 10:56:27 INFO HTTP Server stopped successfully
48-
2024-09-06 17:08:30 INFO PlacementCenterConfig { node_id: 1, grpc_port: 8871, http_port: 8971, data_path: "/tmp/placement-center", log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
49-
2024-09-06 17:08:30 INFO Broker HTTP Server start. port:8971
50-
2024-09-06 17:08:30 INFO Broker Grpc Server start. port:8871
51-
2024-09-06 17:08:33 INFO When ctrl + c is received, the service starts to stop
52-
2024-09-06 17:08:33 INFO HTTP Server stopped successfully
53-
2024-09-06 17:08:33 INFO HTTP Server stopped successfully
54-
2024-09-19 14:45:10 INFO PlacementCenterConfig { cluster_name: "placement-test", addr: "127.0.0.1", node_id: 1, grpc_port: 8871, nodes: {"1": String("127.0.0.1:1228")}, http_port: 8971, data_path: "/tmp/placement-center", log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
55-
2024-09-19 14:45:10 INFO Broker Grpc Server start. port:8871
56-
2024-09-19 14:45:10 INFO Broker HTTP Server start. port:8971
57-
2024-09-19 14:45:14 INFO When ctrl + c is received, the service starts to stop
58-
2024-09-19 14:45:14 INFO HTTP Server stopped successfully
59-
2024-09-19 14:45:14 INFO HTTP Server stopped successfully
60-
2024-09-19 15:11:27 INFO PlacementCenterConfig { cluster_name: "placement-test", addr: "127.0.0.1", node_id: 1, grpc_port: 8871, nodes: {"1": String("127.0.0.1:1228")}, http_port: 8971, data_path: "/tmp/placement-center", log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
61-
2024-09-19 15:11:27 INFO Broker HTTP Server start. port:8971
62-
2024-09-19 15:11:27 INFO Broker Grpc Server start. port:8871
63-
2024-09-19 15:11:29 INFO Node Raft Role changes from 【Follower】 to 【Leader】
64-
2024-09-19 15:11:29 INFO save hardState!!!,len:HardState { term: 1, vote: 1, commit: 0 }
65-
2024-09-19 15:11:29 INFO save light rd!!!,commit:1
66-
2024-09-19 15:11:34 INFO When ctrl + c is received, the service starts to stop
67-
2024-09-19 15:11:34 INFO HTTP Server stopped successfully
68-
2024-09-19 15:11:34 INFO HTTP Server stopped successfully
69-
2024-09-19 15:12:22 INFO PlacementCenterConfig { cluster_name: "placement-test", addr: "127.0.0.1", node_id: 1, grpc_port: 8871, nodes: {"1": String("127.0.0.1:1228")}, http_port: 8971, data_path: "/tmp/placement-center", log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
70-
2024-09-19 15:12:22 INFO Broker HTTP Server start. port:8971
71-
2024-09-19 15:12:22 INFO Broker Grpc Server start. port:8871
72-
2024-09-19 15:12:24 INFO Node Raft Role changes from 【Follower】 to 【Leader】
73-
2024-09-19 15:12:24 INFO save hardState!!!,len:HardState { term: 2, vote: 1, commit: 1 }
74-
2024-09-19 15:12:24 INFO save light rd!!!,commit:2
75-
2024-09-19 15:20:14 INFO When ctrl + c is received, the service starts to stop
76-
2024-09-19 15:20:14 INFO HTTP Server stopped successfully
77-
2024-09-19 15:20:14 INFO HTTP Server stopped successfully
78-
2024-09-19 15:20:22 INFO PlacementCenterConfig { cluster_name: "placement-test", addr: "127.0.0.1", node_id: 1, grpc_port: 8871, nodes: {"1": String("127.0.0.1:1228")}, http_port: 8971, data_path: "/tmp/placement-center", log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
79-
2024-09-19 15:20:22 INFO Broker HTTP Server start. port:8971
80-
2024-09-19 15:20:22 INFO Broker Grpc Server start. port:8871
81-
2024-09-19 15:20:24 INFO Node Raft Role changes from 【Follower】 to 【Leader】
82-
2024-09-19 15:20:24 INFO save hardState!!!,len:HardState { term: 3, vote: 1, commit: 2 }
83-
2024-09-19 15:20:24 INFO save light rd!!!,commit:3
84-
2024-09-19 15:20:49 INFO When ctrl + c is received, the service starts to stop
85-
2024-09-19 15:20:49 INFO HTTP Server stopped successfully
86-
2024-09-19 15:20:49 INFO HTTP Server stopped successfully
87-
2024-09-19 15:20:49 INFO Raft Node Process services stop.
88-
2024-09-19 15:20:57 INFO PlacementCenterConfig { cluster_name: "placement-test", addr: "127.0.0.1", node_id: 1, grpc_port: 8871, nodes: {"1": String("127.0.0.1:1228")}, http_port: 8971, data_path: "/tmp/placement-center", log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
89-
2024-09-19 15:20:57 INFO Broker HTTP Server start. port:8971
90-
2024-09-19 15:20:57 INFO Broker Grpc Server start. port:8871
91-
2024-09-19 15:20:58 INFO Node Raft Role changes from 【Follower】 to 【Leader】
92-
2024-09-19 15:20:58 INFO save hardState!!!,len:HardState { term: 4, vote: 1, commit: 3 }
93-
2024-09-19 15:20:58 INFO save light rd!!!,commit:4
94-
2024-09-19 15:21:01 INFO When ctrl + c is received, the service starts to stop
95-
2024-09-19 15:21:01 INFO HTTP Server stopped successfully
96-
2024-09-19 15:21:01 INFO HTTP Server stopped successfully
97-
2024-09-19 15:26:54 INFO PlacementCenterConfig { cluster_name: "placement-test", addr: "127.0.0.1", node_id: 1, grpc_port: 8871, nodes: {"1": String("127.0.0.1:1228")}, http_port: 8971, data_path: "/tmp/placement-center", log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
98-
2024-09-19 15:26:54 INFO Broker HTTP Server start. port:8971
99-
2024-09-19 15:26:54 INFO Broker Grpc Server start. port:8871
100-
2024-09-19 15:26:56 INFO Node Raft Role changes from 【Follower】 to 【Leader】
101-
2024-09-19 15:26:56 INFO save hardState!!!,len:HardState { term: 5, vote: 1, commit: 4 }
102-
2024-09-19 15:26:56 INFO save light rd!!!,commit:5
103-
2024-09-19 15:28:44 INFO When ctrl + c is received, the service starts to stop
104-
2024-09-19 15:28:44 INFO HTTP Server stopped successfully
105-
2024-09-19 15:28:44 INFO HTTP Server stopped successfully
106-
2024-10-01 11:12:15 INFO PlacementCenterConfig { cluster_name: "placement-test", addr: "127.0.0.1", node_id: 1, grpc_port: 8871, nodes: {"1": String("127.0.0.1:1228")}, http_port: 8971, data_path: "/tmp/placement-center", log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
107-
2024-10-01 11:12:15 INFO Broker Grpc Server start. port:8871
108-
2024-10-01 11:12:15 INFO Broker HTTP Server start. port:8971
109-
2024-10-01 11:12:17 INFO Node Raft Role changes from 【Follower】 to 【Leader】
110-
2024-10-01 11:12:17 INFO save hardState!!!,len:HardState { term: 1, vote: 1, commit: 0 }
111-
2024-10-01 11:12:17 INFO save light rd!!!,commit:1
112-
2024-10-01 11:13:07 INFO When ctrl + c is received, the service starts to stop
113-
2024-10-01 11:13:07 INFO HTTP Server stopped successfully
114-
2024-10-01 11:13:07 INFO HTTP Server stopped successfully
115-
2024-10-01 16:06:08 INFO PlacementCenterConfig { cluster_name: "placement-test", addr: "127.0.0.1", node_id: 1, grpc_port: 8871, nodes: {"1": String("127.0.0.1:1228")}, http_port: 8971, data_path: "/tmp/placement-center", log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
116-
2024-10-01 16:06:08 INFO Broker HTTP Server start. port:8971
117-
2024-10-01 16:06:08 INFO Broker Grpc Server start. port:8871
118-
2024-10-01 16:06:10 INFO Node Raft Role changes from 【Follower】 to 【Leader】
119-
2024-10-01 16:06:10 INFO save hardState!!!,len:HardState { term: 2, vote: 1, commit: 1 }
120-
2024-10-01 16:06:10 INFO save light rd!!!,commit:2
121-
2024-10-01 16:06:21 INFO When ctrl + c is received, the service starts to stop
122-
2024-10-01 16:06:21 INFO HTTP Server stopped successfully
123-
2024-10-01 16:06:21 INFO HTTP Server stopped successfully
1+
2024-10-04 08:58:06 INFO PlacementCenterConfig { cluster_name: "placement-test", addr: "127.0.0.1", node_id: 1, grpc_port: 8871, nodes: {"1": String("127.0.0.1:1228")}, http_port: 8971, data_path: "/tmp/placement-center-geek/geek-local", log: Log { log_config: "./config/log4rs.yaml", log_path: "./logs" } }
2+
2024-10-04 08:58:06 INFO Raft Nodes:{1: Node { node_id: 1, rpc_addr: "127.0.0.1:1228" }}
3+
2024-10-04 08:58:06 INFO Broker HTTP Server start. port:8971
4+
2024-10-04 08:58:06 INFO Broker Grpc Server start. port:8871
5+
2024-10-04 08:58:06 INFO Whether nodes should be initialized, flag=false
6+
2024-10-04 08:58:06 INFO Node {1: Node { node_id: 1, rpc_addr: "127.0.0.1:1228" }} was initialized successfully
7+
2024-10-04 08:58:29 INFO When ctrl + c is received, the service starts to stop
8+
2024-10-04 08:58:29 INFO HTTP Server stopped successfully
9+
2024-10-04 08:58:29 INFO HTTP Server stopped successfully

src/clients/src/placement/openraft/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,17 @@ impl Manager for OpenRaftServiceManager {
9090
type Error = RobustMQError;
9191

9292
async fn connect(&self) -> Result<Self::Connection, Self::Error> {
93-
match OpenRaftServiceClient::connect(format!("http://{}", self.addr.clone())).await {
93+
let mut addr = format!("http://{}", self.addr.clone());
94+
95+
match OpenRaftServiceClient::connect(addr.clone()).await {
9496
Ok(client) => {
9597
return Ok(client);
9698
}
9799
Err(err) => {
98100
return Err(RobustMQError::CommmonError(format!(
99101
"{},{}",
100102
err.to_string(),
101-
self.addr.clone()
103+
addr
102104
)))
103105
}
104106
};

0 commit comments

Comments
 (0)