diff options
author | Alex Auvolat <lx@deuxfleurs.fr> | 2025-01-31 17:19:26 +0100 |
---|---|---|
committer | Alex Auvolat <lx@deuxfleurs.fr> | 2025-02-03 18:54:51 +0100 |
commit | b1629dd355806f40669d5d00db4e8e8f86a3fae2 (patch) | |
tree | 7b44e9d93946bf36a53596e4e8b269cfee95ae31 /src/garage/cli_v2/block.rs | |
parent | d405a9f839779b1454e47e4b53a418603061c5e9 (diff) | |
download | garage-b1629dd355806f40669d5d00db4e8e8f86a3fae2.tar.gz garage-b1629dd355806f40669d5d00db4e8e8f86a3fae2.zip |
cli_v2: implement RetryBlockResync and PurgeBlocks
Diffstat (limited to 'src/garage/cli_v2/block.rs')
-rw-r--r-- | src/garage/cli_v2/block.rs | 52 |
1 files changed, 44 insertions, 8 deletions
diff --git a/src/garage/cli_v2/block.rs b/src/garage/cli_v2/block.rs index ff3c79e9..7d4595eb 100644 --- a/src/garage/cli_v2/block.rs +++ b/src/garage/cli_v2/block.rs @@ -13,14 +13,8 @@ impl Cli { match cmd { BlockOperation::ListErrors => self.cmd_list_block_errors().await, BlockOperation::Info { hash } => self.cmd_get_block_info(hash).await, - - bo => cli_v1::cmd_admin( - &self.admin_rpc_endpoint, - self.rpc_host, - AdminRpc::BlockOperation(bo), - ) - .await - .ok_or_message("cli_v1"), + BlockOperation::RetryNow { all, blocks } => self.cmd_block_retry_now(all, blocks).await, + BlockOperation::Purge { yes, blocks } => self.cmd_block_purge(yes, blocks).await, } } @@ -106,4 +100,46 @@ impl Cli { Ok(()) } + + pub async fn cmd_block_retry_now(&self, all: bool, blocks: Vec<String>) -> Result<(), Error> { + let req = match (all, blocks.len()) { + (true, 0) => LocalRetryBlockResyncRequest::All { all: true }, + (false, n) if n > 0 => LocalRetryBlockResyncRequest::Blocks { + block_hashes: blocks, + }, + _ => { + return Err(Error::Message( + "Please specify block hashes or --all (not both)".into(), + )) + } + }; + + let res = self.local_api_request(req).await?; + + println!( + "{} blocks returned in queue for a retry now (check logs to see results)", + res.count + ); + + Ok(()) + } + + pub async fn cmd_block_purge(&self, yes: bool, blocks: Vec<String>) -> Result<(), Error> { + if !yes { + return Err(Error::Message( + "Pass the --yes flag to confirm block purge operation.".into(), + )); + } + + let res = self + .local_api_request(LocalPurgeBlocksRequest(blocks)) + .await?; + + println!( + "Purged {} blocks: deleted {} versions, {} objects, {} multipart uploads", + res.blocks_purged, res.versions_deleted, res.objects_deleted, res.uploads_deleted, + ); + + Ok(()) + } } |