-
Notifications
You must be signed in to change notification settings - Fork 52
[sled-agent] Destroy orphaned datasets (PR 3/2) #8323
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1490ee9
add orphan destruction behind chicken switch
jgallagher 8958344
clean up in-memory test ZFS `get_dataset_properties`
jgallagher 80bec32
add sled-agent endpoints to control destroying orphaned datasets
jgallagher fce9033
add omdb command to read/write new chicken switch
jgallagher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,13 @@ | |
//! omdb commands that query or update specific Sleds | ||
|
||
use crate::Omdb; | ||
use crate::check_allow_destructive::DestructiveOperationToken; | ||
use crate::helpers::CONNECTION_OPTIONS_HEADING; | ||
use anyhow::Context; | ||
use anyhow::bail; | ||
use clap::Args; | ||
use clap::Subcommand; | ||
use sled_agent_client::types::ChickenSwitchDestroyOrphanedDatasets; | ||
|
||
/// Arguments to the "omdb sled-agent" subcommand | ||
#[derive(Debug, Args)] | ||
|
@@ -37,6 +39,11 @@ enum SledAgentCommands { | |
/// print information about the local bootstore node | ||
#[clap(subcommand)] | ||
Bootstore(BootstoreCommands), | ||
|
||
/// control "chicken switches" (potentially-destructive sled-agent behavior | ||
/// that can be toggled on or off via `omdb`) | ||
#[clap(subcommand)] | ||
ChickenSwitch(ChickenSwitchCommands), | ||
} | ||
|
||
#[derive(Debug, Subcommand)] | ||
|
@@ -46,32 +53,38 @@ enum ZoneCommands { | |
} | ||
|
||
#[derive(Debug, Subcommand)] | ||
enum ZpoolCommands { | ||
/// Print list of all zpools managed by the sled agent | ||
List, | ||
enum BootstoreCommands { | ||
/// Show the internal state of the local bootstore node | ||
Status, | ||
} | ||
|
||
#[derive(Debug, Subcommand)] | ||
enum DatasetCommands { | ||
/// Print list of all datasets the sled agent is configured to manage | ||
/// | ||
/// Note that the set of actual datasets on the sled may be distinct, | ||
/// use the `omdb db inventory collections show` command to see the latest | ||
/// set of datasets collected from sleds. | ||
List, | ||
enum ChickenSwitchCommands { | ||
/// interact with the "destroy orphaned datasets" chicken switch | ||
DestroyOrphans(DestroyOrphansArgs), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't get over the name of this variant. |
||
} | ||
|
||
#[derive(Debug, Args)] | ||
struct DestroyOrphansArgs { | ||
#[command(subcommand)] | ||
command: DestroyOrphansCommands, | ||
} | ||
|
||
#[derive(Debug, Subcommand)] | ||
enum BootstoreCommands { | ||
/// Show the internal state of the local bootstore node | ||
Status, | ||
enum DestroyOrphansCommands { | ||
/// Get the current chicken switch setting | ||
Get, | ||
/// Enable the current chicken switch setting | ||
Enable, | ||
/// Disable the current chicken switch setting | ||
Disable, | ||
} | ||
|
||
impl SledAgentArgs { | ||
/// Run a `omdb sled-agent` subcommand. | ||
pub(crate) async fn run_cmd( | ||
&self, | ||
_omdb: &Omdb, | ||
omdb: &Omdb, | ||
log: &slog::Logger, | ||
) -> Result<(), anyhow::Error> { | ||
// This is a little goofy. The sled URL is required, but can come | ||
|
@@ -92,6 +105,29 @@ impl SledAgentArgs { | |
SledAgentCommands::Bootstore(BootstoreCommands::Status) => { | ||
cmd_bootstore_status(&client).await | ||
} | ||
SledAgentCommands::ChickenSwitch( | ||
ChickenSwitchCommands::DestroyOrphans(DestroyOrphansArgs { | ||
command: DestroyOrphansCommands::Get, | ||
}), | ||
) => cmd_chicken_switch_destroy_orphans_get(&client).await, | ||
SledAgentCommands::ChickenSwitch( | ||
ChickenSwitchCommands::DestroyOrphans(DestroyOrphansArgs { | ||
command: DestroyOrphansCommands::Enable, | ||
}), | ||
) => { | ||
let token = omdb.check_allow_destructive()?; | ||
cmd_chicken_switch_destroy_orphans_set(&client, true, token) | ||
.await | ||
} | ||
SledAgentCommands::ChickenSwitch( | ||
ChickenSwitchCommands::DestroyOrphans(DestroyOrphansArgs { | ||
command: DestroyOrphansCommands::Disable, | ||
}), | ||
) => { | ||
let token = omdb.check_allow_destructive()?; | ||
cmd_chicken_switch_destroy_orphans_set(&client, false, token) | ||
.await | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -157,3 +193,33 @@ async fn cmd_bootstore_status( | |
|
||
Ok(()) | ||
} | ||
|
||
/// Runs `omdb sled-agent chicken-switch destroy-orphans get` | ||
async fn cmd_chicken_switch_destroy_orphans_get( | ||
client: &sled_agent_client::Client, | ||
) -> Result<(), anyhow::Error> { | ||
let ChickenSwitchDestroyOrphanedDatasets { destroy_orphans } = client | ||
.chicken_switch_destroy_orphaned_datasets_get() | ||
.await | ||
.context("get chicken switch value")? | ||
.into_inner(); | ||
let status = if destroy_orphans { "enabled" } else { "disabled" }; | ||
println!("destroy orphaned datasets {status}"); | ||
Ok(()) | ||
} | ||
|
||
/// Runs `omdb sled-agent chicken-switch destroy-orphans {enable,disable}` | ||
async fn cmd_chicken_switch_destroy_orphans_set( | ||
client: &sled_agent_client::Client, | ||
destroy_orphans: bool, | ||
_token: DestructiveOperationToken, | ||
) -> Result<(), anyhow::Error> { | ||
let options = ChickenSwitchDestroyOrphanedDatasets { destroy_orphans }; | ||
client | ||
.chicken_switch_destroy_orphaned_datasets_put(&options) | ||
.await | ||
.context("put chicken switch value")?; | ||
let status = if destroy_orphans { "enabled" } else { "disabled" }; | ||
println!("destroy orphaned datasets {status}"); | ||
Ok(()) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐔