Skip to content

Commit 3f5cf59

Browse files
Huge design change (#471)
1 parent 601c199 commit 3f5cf59

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+2036
-1764
lines changed

Rakefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
task :doc do
2+
sh "cargo doc"
3+
sh "python3 -m http.server --directory target/doc 3000"
4+
end

book/src/client-interaction.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ You can send a R/W command to the cluster with this API.
1313

1414
```proto
1515
message WriteRequest {
16-
uint32 shard_id = 1;
16+
uint32 shard_index = 1;
1717
bytes message = 2;
1818
string request_id = 3;
1919
}
@@ -41,7 +41,7 @@ processed locally.
4141

4242
```proto
4343
message ReadRequest {
44-
uint32 shard_id = 1;
44+
uint32 shard_index = 1;
4545
bytes message = 2;
4646
bool read_locally = 3;
4747
}

book/src/cluster-management.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ From the admin client, the following API can add or remove a Raft process in the
1313

1414
```proto
1515
message AddServerRequest {
16-
uint32 shard_id = 1;
16+
uint32 shard_index = 1;
1717
string server_id = 2;
1818
}
1919
2020
message RemoveServerRequest {
21-
uint32 shard_id = 1;
21+
uint32 shard_index = 1;
2222
string server_id = 2;
2323
}
2424
```

book/src/leadership.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ any remaining Raft process to forcibly start a new election (by promoting to a c
3838

3939
```proto
4040
message TimeoutNow {
41-
uint32 shard_id = 1;
41+
uint32 shard_index = 1;
4242
}
4343
```

sorock-check/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ https://github.com/user-attachments/assets/9aff6794-778b-48fa-bfbd-838e63b3e5c8
66

77
## Usage
88

9-
`sorock-check connect $URL $SHARD_ID`. (e.g. `sorock-check connect http://node5:50051 34`)
9+
`sorock-check connect $URL $shard_index`. (e.g. `sorock-check connect http://node5:50051 34`)
1010

1111
Once connected to any node in a cluster,
1212
the program will automatically connect to all nodes in the cluster.

sorock-check/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ mod proto {
3030
#[derive(Parser)]
3131
enum Sub {
3232
#[clap(about = "Start monitoring a cluster by connecting to a node.")]
33-
Monitor { addr: Uri, shard_id: u32 },
33+
Monitor { addr: Uri, shard_index: u32 },
3434
#[clap(about = "Embedded test. 0 -> Static data, 1 -> Mock servers")]
3535
TestMonitor { number: u8 },
3636
}
@@ -46,8 +46,8 @@ async fn main() -> Result<()> {
4646
let args = Args::parse();
4747

4848
let model = match args.sub {
49-
Sub::Monitor { addr, shard_id } => {
50-
let node = real::connect_real_node(addr, shard_id);
49+
Sub::Monitor { addr, shard_index } => {
50+
let node = real::connect_real_node(addr, shard_index);
5151
model::Model::new(node).await
5252
}
5353
Sub::TestMonitor { number: 0 } => model::Model::test(),

sorock-check/src/real.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,26 @@ use futures::StreamExt;
44
use std::{pin::Pin, time::Duration};
55
use tonic::transport::Uri;
66

7-
pub fn connect_real_node(uri: Uri, shard_id: u32) -> impl model::stream::Node {
7+
pub fn connect_real_node(uri: Uri, shard_index: u32) -> impl model::stream::Node {
88
let chan = Endpoint::from(uri).connect_lazy();
99
let client = proto::raft_client::RaftClient::new(chan);
10-
RealNode { client, shard_id }
10+
RealNode {
11+
client,
12+
shard_index,
13+
}
1114
}
1215

1316
struct RealNode {
1417
client: proto::raft_client::RaftClient<Channel>,
15-
shard_id: u32,
18+
shard_index: u32,
1619
}
1720

1821
#[async_trait::async_trait]
1922
impl model::stream::Node for RealNode {
2023
async fn watch_membership(&self) -> Pin<Box<dyn Stream<Item = proto::Membership> + Send>> {
21-
let shard = proto::Shard { id: self.shard_id };
24+
let shard = proto::Shard {
25+
id: self.shard_index,
26+
};
2227
let mut client = self.client.clone();
2328
let st = async_stream::stream! {
2429
loop {
@@ -42,7 +47,9 @@ impl model::stream::Node for RealNode {
4247
&self,
4348
_: Uri,
4449
) -> Pin<Box<dyn Stream<Item = proto::LogMetrics> + Send>> {
45-
let shard = proto::Shard { id: self.shard_id };
50+
let shard = proto::Shard {
51+
id: self.shard_index,
52+
};
4653
let mut client = self.client.clone();
4754
let st = async_stream::stream! {
4855
match client.watch_log_metrics(shard).await {

sorock/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ rand.workspace = true
2828
redb.workspace = true
2929
serde.workspace = true
3030
serde_bytes.workspace = true
31-
shrinkwraprs = "0.3"
3231
spin.workspace = true
3332
thiserror.workspace = true
3433
tokio = { workspace = true, features = ["rt"] }

sorock/proto/sorock.proto

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ package sorock;
1010
// Client may send a write requests twice but they are executed only once as long as
1111
// they have the same `request_id`.
1212
message WriteRequest {
13-
uint32 shard_id = 1;
13+
uint32 shard_index = 1;
1414
bytes message = 2;
1515
string request_id = 3;
1616
}
1717

1818
// Read-only request to the `RaftApp`.
1919
// This type of request is processed in optimized path.
2020
message ReadRequest {
21-
uint32 shard_id = 1;
21+
uint32 shard_index = 1;
2222
bytes message = 2;
2323
bool read_locally = 3;
2424
}
@@ -34,12 +34,12 @@ message Clock {
3434
}
3535

3636
message KernRequest {
37-
uint32 shard_id = 1;
37+
uint32 shard_index = 1;
3838
bytes message = 2;
3939
}
4040

4141
message ReplicationStreamHeader {
42-
uint32 shard_id = 1;
42+
uint32 shard_index = 1;
4343
string sender_id = 2;
4444
Clock prev_clock = 3;
4545
}
@@ -60,7 +60,7 @@ message ReplicationStreamResponse {
6060
}
6161

6262
message GetSnapshotRequest {
63-
uint32 shard_id = 1;
63+
uint32 shard_index = 1;
6464
uint64 index = 2;
6565
}
6666

@@ -69,7 +69,7 @@ message SnapshotChunk {
6969
}
7070

7171
message VoteRequest {
72-
uint32 shard_id = 1;
72+
uint32 shard_index = 1;
7373
uint64 vote_term = 2;
7474
string candidate_id = 3;
7575
Clock candidate_clock = 4;
@@ -92,13 +92,13 @@ message Heartbeat {
9292

9393
// Request to add a Raft process with `server_id` to a shard.
9494
message AddServerRequest {
95-
uint32 shard_id = 1;
95+
uint32 shard_index = 1;
9696
string server_id = 2;
9797
}
9898

9999
// Request to remove a Raft process with `server_id` from a shard.
100100
message RemoveServerRequest {
101-
uint32 shard_id = 1;
101+
uint32 shard_index = 1;
102102
string server_id = 2;
103103
}
104104

@@ -114,7 +114,7 @@ message Membership {
114114
// to become a leader disregarding the election timeout.
115115
// You can use this request to rebalance the leaders in the cluster.
116116
message TimeoutNow {
117-
uint32 shard_id = 1;
117+
uint32 shard_index = 1;
118118
}
119119

120120
message LogMetrics {

sorock/src/backend/redb/ballot.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use redb::ReadableDatabase;
55
mod value {
66
use super::*;
77

8-
#[derive(serde::Deserialize, serde::Serialize)]
8+
#[derive(Deserialize, Serialize)]
99
struct OnDiskStruct {
1010
term: u64,
11-
voted_for: Option<sorock::NodeId>,
11+
voted_for: Option<sorock::NodeAddress>,
1212
}
1313

1414
pub fn ser(x: Ballot) -> Vec<u8> {
@@ -39,8 +39,8 @@ pub struct BallotStore {
3939
}
4040

4141
impl BallotStore {
42-
pub fn new(db: Arc<Database>, shard_id: u32) -> Result<Self> {
43-
let space = format!("ballot-{shard_id}");
42+
pub fn new(db: Arc<Database>, shard_index: u32) -> Result<Self> {
43+
let space = format!("ballot-{shard_index}");
4444

4545
// Insert the initial value if not exists.
4646
let tx = db.begin_write()?;

0 commit comments

Comments
 (0)