Cargo fmt pass over a codebase

This commit is contained in:
Stas Kelvich
2021-04-06 14:42:13 +03:00
parent 494b95886b
commit c0fcbbbe0c
23 changed files with 2501 additions and 2260 deletions

View File

@@ -1,13 +1,12 @@
use anyhow::Result;
use clap::{App, AppSettings};
use anyhow::{Result};
mod subcommand;
pub mod pg;
pub mod storage;
pub mod snapshot;
pub mod storage;
mod subcommand;
fn main() -> Result<()> {
let cli_commands = subcommand::ClapCommands {
commands: vec![
Box::new(pg::PgCmd {
@@ -22,7 +21,6 @@ fn main() -> Result<()> {
],
};
let matches = App::new("zenith")
.about("Zenith CLI")
.version("1.0")
@@ -30,7 +28,6 @@ fn main() -> Result<()> {
.subcommands(cli_commands.generate())
.get_matches();
if let Some(subcommand) = matches.subcommand_name() {
println!("'git {}' was used", subcommand);
}

View File

@@ -1,10 +1,8 @@
use anyhow::Result;
use clap::{App, AppSettings, Arg};
use anyhow::{Result};
use crate::subcommand;
pub struct PgCmd<'a> {
pub clap_cmd: clap::App<'a, 'a>,
}
@@ -13,81 +11,95 @@ impl subcommand::SubCommand for PgCmd<'_> {
fn gen_clap_command(&self) -> clap::App {
let c = self.clap_cmd.clone();
c.about("Operations with zenith compute nodes")
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(
App::new("list")
.about("List existing compute nodes")
)
.subcommand(
App::new("create")
.about("Create (init) new data directory using given storage and start postgres")
.arg(Arg::with_name("name")
.short("n")
.long("name")
.takes_value(true)
.help("Name of the compute node"))
.arg(Arg::with_name("storage")
.short("s")
.long("storage")
.takes_value(true)
.help("Name of the storage node to use"))
//TODO should it be just name of uploaded snapshot or some path?
.arg(Arg::with_name("snapshot")
.long("snapshot")
.takes_value(true)
.help("Name of the snapshot to use"))
.arg(Arg::with_name("nostart")
.long("no-start")
.takes_value(false)
.help("Don't start postgres on the created node"))
)
.subcommand(
App::new("destroy")
.about("Stop postgres and destroy node's data directory")
.arg(Arg::with_name("name")
.short("n")
.long("name")
.takes_value(true)
.help("Name of the compute node"))
)
.subcommand(
App::new("start")
.about("Start postgres on the given node")
.arg(Arg::with_name("name")
.short("n")
.long("name")
.takes_value(true)
.help("Name of the compute node"))
.arg(Arg::with_name("replica")
.long("replica")
.takes_value(false)
.help("Start the compute node as replica"))
)
.subcommand(
App::new("stop")
.about("Stop postgres on the given node")
.arg(Arg::with_name("name")
.short("n")
.long("name")
.takes_value(true)
.help("Name of the compute node"))
)
.subcommand(
App::new("show")
.about("Show info about the given node")
.arg(Arg::with_name("name")
.short("n")
.long("name")
.takes_value(true)
.help("Name of the compute node"))
)
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(App::new("list").about("List existing compute nodes"))
.subcommand(
App::new("create")
.about(
"Create (init) new data directory using given storage and start postgres",
)
.arg(
Arg::with_name("name")
.short("n")
.long("name")
.takes_value(true)
.help("Name of the compute node"),
)
.arg(
Arg::with_name("storage")
.short("s")
.long("storage")
.takes_value(true)
.help("Name of the storage node to use"),
)
//TODO should it be just name of uploaded snapshot or some path?
.arg(
Arg::with_name("snapshot")
.long("snapshot")
.takes_value(true)
.help("Name of the snapshot to use"),
)
.arg(
Arg::with_name("nostart")
.long("no-start")
.takes_value(false)
.help("Don't start postgres on the created node"),
),
)
.subcommand(
App::new("destroy")
.about("Stop postgres and destroy node's data directory")
.arg(
Arg::with_name("name")
.short("n")
.long("name")
.takes_value(true)
.help("Name of the compute node"),
),
)
.subcommand(
App::new("start")
.about("Start postgres on the given node")
.arg(
Arg::with_name("name")
.short("n")
.long("name")
.takes_value(true)
.help("Name of the compute node"),
)
.arg(
Arg::with_name("replica")
.long("replica")
.takes_value(false)
.help("Start the compute node as replica"),
),
)
.subcommand(
App::new("stop")
.about("Stop postgres on the given node")
.arg(
Arg::with_name("name")
.short("n")
.long("name")
.takes_value(true)
.help("Name of the compute node"),
),
)
.subcommand(
App::new("show")
.about("Show info about the given node")
.arg(
Arg::with_name("name")
.short("n")
.long("name")
.takes_value(true)
.help("Name of the compute node"),
),
)
}
fn run(&self, args: clap::ArgMatches) -> Result<()> {
println!("Run PgCmd with args {:?}", args);
Ok(())
}
}
}

View File

@@ -1,5 +1,5 @@
use anyhow::Result;
use clap::{App, AppSettings, Arg};
use anyhow::{Result};
use crate::subcommand;
@@ -11,31 +11,17 @@ impl subcommand::SubCommand for SnapshotCmd<'_> {
fn gen_clap_command(&self) -> clap::App {
let c = self.clap_cmd.clone();
c.about("Operations with zenith snapshots")
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(
App::new("list")
)
.subcommand(
App::new("create")
.arg(Arg::with_name("pgdata").required(true)),
)
.subcommand(
App::new("destroy")
)
.subcommand(
App::new("start")
)
.subcommand(
App::new("stop")
)
.subcommand(
App::new("show")
)
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(App::new("list"))
.subcommand(App::new("create").arg(Arg::with_name("pgdata").required(true)))
.subcommand(App::new("destroy"))
.subcommand(App::new("start"))
.subcommand(App::new("stop"))
.subcommand(App::new("show"))
}
fn run(&self, args: clap::ArgMatches) -> Result<()> {
println!("Run SnapshotCmd with args {:?}", args);
Ok(())
}
}
}

View File

@@ -1,5 +1,5 @@
use anyhow::Result;
use clap::{App, AppSettings};
use anyhow::{Result};
use crate::subcommand;
@@ -11,24 +11,15 @@ impl subcommand::SubCommand for StorageCmd<'_> {
fn gen_clap_command(&self) -> clap::App {
let c = self.clap_cmd.clone();
c.about("Operations with zenith storage nodes")
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(
App::new("list")
)
.subcommand(
App::new("attach")
)
.subcommand(
App::new("detach")
)
.subcommand(
App::new("show")
)
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(App::new("list"))
.subcommand(App::new("attach"))
.subcommand(App::new("detach"))
.subcommand(App::new("show"))
}
fn run(&self, args: clap::ArgMatches) -> Result<()> {
println!("Run StorageCmd with args {:?}", args);
Ok(())
}
}
}

View File

@@ -3,19 +3,19 @@
//
use log::*;
use std::{fs::File, str::FromStr, fs::OpenOptions};
use std::fs;
use std::io;
use std::path::PathBuf;
use std::thread;
use std::fs;
use std::{fs::File, fs::OpenOptions, str::FromStr};
use clap::{App, Arg};
use daemonize::Daemonize;
use slog;
use slog_stdlog;
use slog_scope;
use slog::Drain;
use slog_scope;
use slog_stdlog;
use pageserver::page_service;
use pageserver::restore_s3;
@@ -129,8 +129,16 @@ fn start_pageserver(conf: PageServerConf) -> Result<(), io::Error> {
// There should'n be any logging to stdin/stdout. Redirect it to the main log so
// that we will see any accidental manual fpritf's or backtraces.
let stdout = OpenOptions::new().create(true).append(true).open(conf.data_dir.join("pageserver.log")).unwrap();
let stderr = OpenOptions::new().create(true).append(true).open(conf.data_dir.join("pageserver.log")).unwrap();
let stdout = OpenOptions::new()
.create(true)
.append(true)
.open(conf.data_dir.join("pageserver.log"))
.unwrap();
let stderr = OpenOptions::new()
.create(true)
.append(true)
.open(conf.data_dir.join("pageserver.log"))
.unwrap();
let daemonize = Daemonize::new()
.pid_file(conf.data_dir.join("pageserver.pid"))
@@ -157,13 +165,13 @@ fn start_pageserver(conf: PageServerConf) -> Result<(), io::Error> {
// Create directory for wal-redo datadirs
match fs::create_dir(conf.data_dir.join("wal-redo")) {
Ok(_) => {},
Ok(_) => {}
Err(e) => match e.kind() {
io::ErrorKind::AlreadyExists => {}
_ => {
panic!("Failed to create wal-redo data directory: {}", e);
}
}
},
}
// Launch the WAL receiver thread if pageserver was started with --wal-producer