Skip to content

Commit

Permalink
Adddump_peers cli command
Browse files Browse the repository at this point in the history
  • Loading branch information
jopemachine committed Jan 22, 2024
1 parent 7f4934d commit 6245057
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ If peer specifies the configuration of the initial members, the cluster will ope
```rust
let raft_addr = "127.0.0.1:60062".to_owned();
let peer_addr = "127.0.0.1:60061".to_owned();
let join_ticket = await Raft::request_id(raft_addr, peer_addr, logger.clone());
let join_ticket = Raft::request_id(raft_addr, peer_addr, logger.clone()).await;

let raft = Raft::new_follower(
join_ticket.reserved_id,
Expand Down
6 changes: 2 additions & 4 deletions examples/memstore/static-members/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ struct Options {
fn validate_options(options: Options) -> Options {
if options.peer_addr.is_some() && options.restore_wal_from.is_some() {
panic!("Cannot restore WAL from follower node");
}
else if options.peer_addr.is_some() && options.restore_wal_snapshot_from.is_some() {
} else if options.peer_addr.is_some() && options.restore_wal_snapshot_from.is_some() {
panic!("Cannot restore WAL snapshot from follower node");
}
else {
} else {
options
}
}
Expand Down
1 change: 0 additions & 1 deletion raftify/src/cli/commands/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use std::{collections::HashMap, net::SocketAddr, sync::Arc};
use crate::{utils::to_confchange_v2, Config, HeedStorage, LogStore, Result};

/// Read all_entries and make the appropriate ConfChanges to make it peers compared to the peers given in json format.
#[allow(dead_code)]
pub fn dump_peers(path: &str, peers: HashMap<u64, SocketAddr>, logger: slog::Logger) -> Result<()> {
let config = Config {
log_dir: path.to_string(),
Expand Down
1 change: 0 additions & 1 deletion raftify/src/cli/commands/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::collections::HashMap;
use std::net::SocketAddr;
use std::str::FromStr;

#[allow(dead_code)]
pub fn parse_peers_json(
peers: &str,
) -> Result<HashMap<u64, SocketAddr>, Box<dyn std::error::Error>> {
Expand Down
33 changes: 29 additions & 4 deletions raftify/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ include!(concat!(env!("OUT_DIR"), "/built.rs"));
mod commands;

use clap::{App, Arg, SubCommand};
use commands::debug::{debug_entries, debug_node, debug_persisted};
use commands::{
debug::{debug_entries, debug_node, debug_persisted, debug_persitsted_all},
dump::dump_peers,
utils::parse_peers_json,
};
use std::fmt::Debug;

use crate::{
raft::{default_logger, formatter::set_custom_formatter},
AbstractLogEntry, AbstractStateMachine, CustomFormatter, Result,
};

use self::commands::debug::debug_persitsted_all;

pub async fn cli_handler<
LogEntry: AbstractLogEntry + Debug + Send + 'static,
FSM: AbstractStateMachine + Debug + Clone + Send + Sync + 'static,
Expand Down Expand Up @@ -64,8 +66,23 @@ pub async fn cli_handler<
.index(1),
),
),
)
.subcommand(
SubCommand::with_name("dump")
.arg(
Arg::with_name("path")
.help("The log directory path")
.required(true)
.index(1),
)
.arg(
Arg::with_name("peers")
.help("The peers to dump")
.required(true)
.index(2),
)
.about(""),
);
// .subcommand(SubCommand::with_name("health").about("Check health"))

let matches = match custom_args {
Some(args) => app.get_matches_from(args),
Expand Down Expand Up @@ -101,5 +118,13 @@ pub async fn cli_handler<
}
};

if let Some(("dump", dump_matches)) = matches.subcommand() {
if let Some(path) = dump_matches.value_of("path") {
if let Some(peers) = dump_matches.value_of("peers") {
dump_peers(path, parse_peers_json(peers).unwrap(), logger.clone())?;
}
}
};

Ok(())
}

0 comments on commit 6245057

Please sign in to comment.