diff options
Diffstat (limited to 'src/garage')
-rw-r--r-- | src/garage/admin.rs | 23 | ||||
-rw-r--r-- | src/garage/cli/cmd.rs | 4 | ||||
-rw-r--r-- | src/garage/cli/structs.rs | 21 | ||||
-rw-r--r-- | src/garage/cli/util.rs | 24 |
4 files changed, 72 insertions, 0 deletions
diff --git a/src/garage/admin.rs b/src/garage/admin.rs index 8a984cfb..f307bea1 100644 --- a/src/garage/admin.rs +++ b/src/garage/admin.rs @@ -5,6 +5,7 @@ use std::sync::Arc; use async_trait::async_trait; use serde::{Deserialize, Serialize}; +use garage_util::background::*; use garage_util::crdt::*; use garage_util::data::*; use garage_util::error::Error as GarageError; @@ -36,6 +37,7 @@ pub enum AdminRpc { LaunchRepair(RepairOpt), Migrate(MigrateOpt), Stats(StatsOpt), + Worker(WorkerOpt), // Replies Ok(String), @@ -47,6 +49,7 @@ pub enum AdminRpc { }, KeyList(Vec<(String, String)>), KeyInfo(Key, HashMap<Uuid, Bucket>), + WorkerList(HashMap<usize, garage_util::background::WorkerInfo>), } impl Rpc for AdminRpc { @@ -822,6 +825,25 @@ impl AdminRpcHandler { Ok(()) } + + // ---- + + async fn handle_worker_cmd(&self, opt: WorkerOpt) -> Result<AdminRpc, Error> { + match opt.cmd { + WorkerCmd::List { busy } => { + let workers = self.garage.background.get_worker_info(); + let workers = if busy { + workers + .into_iter() + .filter(|(_, w)| w.status == WorkerStatus::Busy) + .collect() + } else { + workers + }; + Ok(AdminRpc::WorkerList(workers)) + } + } + } } #[async_trait] @@ -837,6 +859,7 @@ impl EndpointHandler<AdminRpc> for AdminRpcHandler { AdminRpc::Migrate(opt) => self.handle_migrate(opt.clone()).await, AdminRpc::LaunchRepair(opt) => self.handle_launch_repair(opt.clone()).await, AdminRpc::Stats(opt) => self.handle_stats(opt.clone()).await, + AdminRpc::Worker(opt) => self.handle_worker_cmd(opt.clone()).await, m => Err(GarageError::unexpected_rpc_message(m).into()), } } diff --git a/src/garage/cli/cmd.rs b/src/garage/cli/cmd.rs index 3a0bd956..38a58b76 100644 --- a/src/garage/cli/cmd.rs +++ b/src/garage/cli/cmd.rs @@ -39,6 +39,7 @@ pub async fn cli_command_dispatch( cmd_admin(admin_rpc_endpoint, rpc_host, AdminRpc::LaunchRepair(ro)).await } Command::Stats(so) => cmd_admin(admin_rpc_endpoint, rpc_host, AdminRpc::Stats(so)).await, + Command::Worker(wo) => cmd_admin(admin_rpc_endpoint, rpc_host, AdminRpc::Worker(wo)).await, _ => unreachable!(), } } @@ -182,6 +183,9 @@ pub async fn cmd_admin( AdminRpc::KeyInfo(key, rb) => { print_key_info(&key, &rb); } + AdminRpc::WorkerList(wi) => { + print_worker_info(wi); + } r => { error!("Unexpected response: {:?}", r); } diff --git a/src/garage/cli/structs.rs b/src/garage/cli/structs.rs index 4f2efe19..f6b2d197 100644 --- a/src/garage/cli/structs.rs +++ b/src/garage/cli/structs.rs @@ -45,6 +45,10 @@ pub enum Command { /// Gather node statistics #[structopt(name = "stats")] Stats(StatsOpt), + + /// Manage background workers + #[structopt(name = "worker")] + Worker(WorkerOpt), } #[derive(StructOpt, Debug)] @@ -460,3 +464,20 @@ pub struct StatsOpt { #[structopt(short = "d", long = "detailed")] pub detailed: bool, } + +#[derive(Serialize, Deserialize, StructOpt, Debug, Clone)] +pub struct WorkerOpt { + #[structopt(subcommand)] + pub cmd: WorkerCmd, +} + +#[derive(Serialize, Deserialize, StructOpt, Debug, Eq, PartialEq, Clone)] +pub enum WorkerCmd { + /// List all workers on Garage node + #[structopt(name = "list")] + List { + /// Show only busy workers + #[structopt(short = "b", long = "busy")] + busy: bool, + }, +} diff --git a/src/garage/cli/util.rs b/src/garage/cli/util.rs index 329e8a3e..81361864 100644 --- a/src/garage/cli/util.rs +++ b/src/garage/cli/util.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; +use garage_util::background::*; use garage_util::crdt::*; use garage_util::data::Uuid; use garage_util::error::*; @@ -235,3 +236,26 @@ pub fn find_matching_node( Ok(candidates[0]) } } + +pub fn print_worker_info(wi: HashMap<usize, WorkerInfo>) { + let mut wi = wi.into_iter().collect::<Vec<_>>(); + wi.sort_by_key(|(tid, info)| { + ( + match info.status { + WorkerStatus::Busy => 0, + WorkerStatus::Idle => 1, + WorkerStatus::Done => 2, + }, + *tid, + ) + }); + + let mut table = vec![]; + for (tid, info) in wi.iter() { + table.push(format!("{}\t{:?}\t{}", tid, info.status, info.name)); + if let Some(i) = &info.info { + table.push(format!("\t\t{}", i)); + } + } + format_table(table); +} |