Skip to content

Commit

Permalink
Restructure the module tree
Browse files Browse the repository at this point in the history
  • Loading branch information
akiradeveloper committed Oct 19, 2024
1 parent 777ba49 commit e67671f
Show file tree
Hide file tree
Showing 22 changed files with 32 additions and 26 deletions.
2 changes: 1 addition & 1 deletion sorock/benches/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn do_bench(n: usize, b: &mut test::Bencher) {

let mem = redb::backends::InMemoryBackend::new();
let db = redb::Database::builder().create_with_backend(mem).unwrap();
let db = sorock::backends::redb::Backend::new(db);
let db = sorock::backend::redb::Backend::new(db);
let (log, _) = db.get(0).unwrap();

let mut i = 0;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 5 additions & 11 deletions sorock/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#![deny(unused_must_use)]

/// Implementation of `RaftProcess`.
pub mod process;

pub mod client;
mod communicator;
mod error;
pub mod monitor_service;
mod node;
pub mod raft_service;
use error::Error;
pub mod backends;

pub mod backend;
/// Implementation of gRPC services.
pub mod service;

use anyhow::{bail, ensure, Context, Result};
use bytes::Bytes;
Expand All @@ -20,12 +20,6 @@ use process::RaftProcess;
use std::sync::Arc;
use std::time::Duration;
use tonic::transport::Uri;
pub mod reflection_service;

mod raft {
tonic::include_proto!("sorock");
pub type RaftClient = raft_client::RaftClient<tonic::transport::channel::Channel>;
}

/// Identifier of `RaftNode`.
#[derive(
Expand Down
2 changes: 1 addition & 1 deletion sorock/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;

use communicator::{Communicator, RaftConnection};
use service::raft::communicator::{Communicator, RaftConnection};
use std::collections::HashMap;

pub struct Inner {
Expand Down
5 changes: 5 additions & 0 deletions sorock/src/service/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use super::*;

pub mod monitor;
pub mod raft;
pub mod reflection;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
use super::*;

mod raft {
tonic::include_proto!("sorock");
pub type RaftClient = raft_client::RaftClient<tonic::transport::channel::Channel>;
}

use process::*;
use raft::raft_server::{Raft, RaftServer};

pub mod client;
pub(crate) mod communicator;
mod stream;

/// Create a Raft service backed by a `RaftNode`.
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions tests/env/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl Node {
let db = {
let mem = redb::backends::InMemoryBackend::new();
let db = redb::Database::builder().create_with_backend(mem).unwrap();
sorock::backends::redb::Backend::new(db)
sorock::backend::redb::Backend::new(db)
};

for shard_id in 0..n_shards {
Expand All @@ -41,11 +41,11 @@ impl Node {
node.attach_process(shard_id, process);
}

let raft_svc = sorock::raft_service::new(node.clone())
let raft_svc = sorock::service::raft::new(node.clone())
.send_compressed(CompressionEncoding::Zstd)
.accept_compressed(CompressionEncoding::Zstd);
let monitor_svc = sorock::monitor_service::new(node);
let reflection_svc = sorock::reflection_service::new();
let monitor_svc = sorock::service::monitor::new(node);
let reflection_svc = sorock::service::reflection::new();
let ping_svc = testapp::ping_app::new_service();

let socket = format!("127.0.0.1:{port}").parse().unwrap();
Expand Down
8 changes: 4 additions & 4 deletions tests/sorock-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{ensure, Result};
use env::Env;
use sorock::client::RaftClient;
use sorock::service::raft::client::*;

pub struct Builder {
with_logging: bool,
Expand Down Expand Up @@ -54,13 +54,13 @@ impl Cluster {

pub fn admin(&self, id: u8) -> RaftClient {
let conn = self.env.get_connection(id);
sorock::client::RaftClient::new(conn)
RaftClient::new(conn)
}

/// Request node `to` to add a node `id`.
pub async fn add_server(&self, shard_id: u32, to: u8, id: u8) -> Result<()> {
self.admin(to)
.add_server(sorock::client::AddServerRequest {
.add_server(AddServerRequest {
shard_id,
server_id: self.env.address(id).to_string(),
})
Expand All @@ -73,7 +73,7 @@ impl Cluster {
/// Request node `to` to remove a node `id`.
pub async fn remove_server(&self, shard_id: u32, to: u8, id: u8) -> Result<()> {
self.admin(to)
.remove_server(sorock::client::RemoveServerRequest {
.remove_server(RemoveServerRequest {
shard_id,
server_id: self.env.address(id).to_string(),
})
Expand Down
5 changes: 3 additions & 2 deletions tests/sorock-tests/tests/0_n1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::Result;
use serial_test::serial;
use sorock::service::raft::client::*;
use sorock_tests::*;

#[serial]
Expand Down Expand Up @@ -67,9 +68,9 @@ async fn n1_exec_once() -> Result<()> {
cluster.add_server(0, 0, 0).await?;

let chan = cluster.env().get_connection(0);
let cli = sorock::client::RaftClient::new(chan);
let cli = RaftClient::new(chan);

let req = sorock::client::WriteRequest {
let req = WriteRequest {
shard_id: 0,
message: testapp::AppWriteRequest::FetchAdd {
bytes: vec![1u8; 1].into(),
Expand Down
1 change: 0 additions & 1 deletion tests/sorock-tests/tests/3_n1_multi_raft.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::Result;
use rand::Rng;
use serial_test::serial;
use sorock::client::TimeoutNow;
use sorock_tests::*;
use std::sync::Arc;

Expand Down
2 changes: 1 addition & 1 deletion tests/sorock-tests/tests/4_n3_multi_raft.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
use rand::Rng;
use serial_test::serial;
use sorock::client::TimeoutNow;
use sorock::service::raft::client::*;
use sorock_tests::*;
use std::sync::Arc;

Expand Down
2 changes: 1 addition & 1 deletion tests/testapp/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use bytes::Bytes;
use sorock::client::*;
use sorock::service::raft::client::*;
use tonic::codegen::CompressionEncoding;
use tonic::transport::Channel;

Expand Down

0 comments on commit e67671f

Please sign in to comment.