diff options
author | Alex Auvolat <alex@adnab.me> | 2022-06-08 20:03:30 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-06-08 20:03:30 +0200 |
commit | 17e111139308ba995fb782cbd1af555920cbbb81 (patch) | |
tree | 2262f3b46bb84a21a5e7df59c19c2ca8fa444415 /src/garage | |
parent | 03e811bbbfca5a2467bb24ce1500c74661234947 (diff) | |
download | garage-17e111139308ba995fb782cbd1af555920cbbb81.tar.gz garage-17e111139308ba995fb782cbd1af555920cbbb81.zip |
First iteration of bucket object counters
Diffstat (limited to 'src/garage')
-rw-r--r-- | src/garage/Cargo.toml | 1 | ||||
-rw-r--r-- | src/garage/admin.rs | 21 | ||||
-rw-r--r-- | src/garage/cli/cmd.rs | 8 | ||||
-rw-r--r-- | src/garage/cli/structs.rs | 3 | ||||
-rw-r--r-- | src/garage/cli/util.rs | 26 | ||||
-rw-r--r-- | src/garage/repair/offline.rs | 5 |
6 files changed, 59 insertions, 5 deletions
diff --git a/src/garage/Cargo.toml b/src/garage/Cargo.toml index eb643160..640e6975 100644 --- a/src/garage/Cargo.toml +++ b/src/garage/Cargo.toml @@ -30,6 +30,7 @@ garage_util = { version = "0.7.0", path = "../util" } garage_web = { version = "0.7.0", path = "../web" } bytes = "1.0" +bytesize = "1.1" hex = "0.4" tracing = { version = "0.1.30", features = ["log-always"] } pretty_env_logger = "0.4" diff --git a/src/garage/admin.rs b/src/garage/admin.rs index afe7fe7a..31305b51 100644 --- a/src/garage/admin.rs +++ b/src/garage/admin.rs @@ -39,7 +39,11 @@ pub enum AdminRpc { // Replies Ok(String), BucketList(Vec<Bucket>), - BucketInfo(Bucket, HashMap<String, Key>), + BucketInfo { + bucket: Bucket, + relevant_keys: HashMap<String, Key>, + counters: HashMap<String, i64>, + }, KeyList(Vec<(String, String)>), KeyInfo(Key, HashMap<Uuid, Bucket>), } @@ -104,6 +108,15 @@ impl AdminRpcHandler { .get_existing_bucket(bucket_id) .await?; + let counters = self + .garage + .object_counter_table + .table + .get(&EmptyKey, &bucket_id) + .await? + .map(|x| x.filtered_values(&self.garage.system.ring.borrow())) + .unwrap_or_default(); + let mut relevant_keys = HashMap::new(); for (k, _) in bucket .state @@ -139,7 +152,11 @@ impl AdminRpcHandler { } } - Ok(AdminRpc::BucketInfo(bucket, relevant_keys)) + Ok(AdminRpc::BucketInfo { + bucket, + relevant_keys, + counters, + }) } #[allow(clippy::ptr_arg)] diff --git a/src/garage/cli/cmd.rs b/src/garage/cli/cmd.rs index b2dd8f14..3a0bd956 100644 --- a/src/garage/cli/cmd.rs +++ b/src/garage/cli/cmd.rs @@ -169,8 +169,12 @@ pub async fn cmd_admin( AdminRpc::BucketList(bl) => { print_bucket_list(bl); } - AdminRpc::BucketInfo(bucket, rk) => { - print_bucket_info(&bucket, &rk); + AdminRpc::BucketInfo { + bucket, + relevant_keys, + counters, + } => { + print_bucket_info(&bucket, &relevant_keys, &counters); } AdminRpc::KeyList(kl) => { print_key_list(kl); diff --git a/src/garage/cli/structs.rs b/src/garage/cli/structs.rs index 575ac857..cdaa09be 100644 --- a/src/garage/cli/structs.rs +++ b/src/garage/cli/structs.rs @@ -425,6 +425,9 @@ pub enum OfflineRepairWhat { /// Repair K2V item counters #[structopt(name = "k2v_item_counters")] K2VItemCounters, + /// Repair object counters + #[structopt(name = "object_counters")] + ObjectCounters, } #[derive(Serialize, Deserialize, StructOpt, Debug, Clone)] diff --git a/src/garage/cli/util.rs b/src/garage/cli/util.rs index 6d73be3a..23c669b9 100644 --- a/src/garage/cli/util.rs +++ b/src/garage/cli/util.rs @@ -7,6 +7,7 @@ use garage_util::formater::format_table; use garage_model::bucket_table::*; use garage_model::key_table::*; +use garage_model::s3::object_table::{BYTES, OBJECTS, UNFINISHED_UPLOADS}; pub fn print_bucket_list(bl: Vec<Bucket>) { println!("List of buckets:"); @@ -121,7 +122,11 @@ pub fn print_key_info(key: &Key, relevant_buckets: &HashMap<Uuid, Bucket>) { } } -pub fn print_bucket_info(bucket: &Bucket, relevant_keys: &HashMap<String, Key>) { +pub fn print_bucket_info( + bucket: &Bucket, + relevant_keys: &HashMap<String, Key>, + counters: &HashMap<String, i64>, +) { let key_name = |k| { relevant_keys .get(k) @@ -133,6 +138,25 @@ pub fn print_bucket_info(bucket: &Bucket, relevant_keys: &HashMap<String, Key>) match &bucket.state { Deletable::Deleted => println!("Bucket is deleted."), Deletable::Present(p) => { + let size = + bytesize::ByteSize::b(counters.get(BYTES).cloned().unwrap_or_default() as u64); + println!( + "Size: {} ({})", + size.to_string_as(true), + size.to_string_as(false) + ); + println!( + "Objects: {}", + counters.get(OBJECTS).cloned().unwrap_or_default() + ); + println!( + "Unfinished multipart uploads: {}", + counters + .get(UNFINISHED_UPLOADS) + .cloned() + .unwrap_or_default() + ); + println!("Website access: {}", p.website_config.get().is_some()); println!("\nGlobal aliases:"); diff --git a/src/garage/repair/offline.rs b/src/garage/repair/offline.rs index 853bfdf3..ef56cc5c 100644 --- a/src/garage/repair/offline.rs +++ b/src/garage/repair/offline.rs @@ -38,6 +38,11 @@ pub async fn offline_repair(config_file: PathBuf, opt: OfflineRepairOpt) -> Resu #[cfg(not(feature = "k2v"))] error!("K2V not enabled in this build."); } + OfflineRepairWhat::ObjectCounters => { + garage + .object_counter_table + .offline_recount_all(&garage.object_table)?; + } } info!("Repair operation finished, shutting down Garage internals..."); |