forked from kent/consciousness
cli: add 'node restore' command for undeleting nodes
Restores a deleted node to its last non-deleted content with proper version continuity (version number continues from absolute latest, content from last live version). Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
290505fc51
commit
6a5b840db3
3 changed files with 23 additions and 1 deletions
|
|
@ -32,6 +32,17 @@ pub async fn cmd_node_rename(old_key: &str, new_key: &str) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn cmd_node_restore(key: &[String]) -> Result<()> {
|
||||||
|
if key.is_empty() {
|
||||||
|
bail!("node-restore requires a key");
|
||||||
|
}
|
||||||
|
super::check_dry_run();
|
||||||
|
let key = key.join(" ");
|
||||||
|
let result = memory::memory_restore(None, &key).await?;
|
||||||
|
println!("{}", result);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn cmd_render(key: &[String]) -> Result<()> {
|
pub async fn cmd_render(key: &[String]) -> Result<()> {
|
||||||
if key.is_empty() {
|
if key.is_empty() {
|
||||||
bail!("render requires a key");
|
bail!("render requires a key");
|
||||||
|
|
|
||||||
|
|
@ -298,6 +298,7 @@ memory_tool!(memory_search, ref, keys: [Vec<String>], max_hops: [Option<u32>], e
|
||||||
memory_tool!(memory_link_set, mut, source: [str], target: [str], strength: [f32]);
|
memory_tool!(memory_link_set, mut, source: [str], target: [str], strength: [f32]);
|
||||||
memory_tool!(memory_link_add, mut, source: [str], target: [str]);
|
memory_tool!(memory_link_add, mut, source: [str], target: [str]);
|
||||||
memory_tool!(memory_delete, mut, key: [str]);
|
memory_tool!(memory_delete, mut, key: [str]);
|
||||||
|
memory_tool!(memory_restore, mut, key: [str]);
|
||||||
memory_tool!(memory_history, ref, key: [str], full: [Option<bool>]);
|
memory_tool!(memory_history, ref, key: [str], full: [Option<bool>]);
|
||||||
memory_tool!(memory_weight_set, mut, key: [str], weight: [f32]);
|
memory_tool!(memory_weight_set, mut, key: [str], weight: [f32]);
|
||||||
memory_tool!(memory_rename, mut, old_key: [str], new_key: [str]);
|
memory_tool!(memory_rename, mut, old_key: [str], new_key: [str]);
|
||||||
|
|
|
||||||
10
src/main.rs
10
src/main.rs
|
|
@ -175,6 +175,11 @@ enum NodeCmd {
|
||||||
/// Node key
|
/// Node key
|
||||||
key: Vec<String>,
|
key: Vec<String>,
|
||||||
},
|
},
|
||||||
|
/// Restore a deleted node to its last live state
|
||||||
|
Restore {
|
||||||
|
/// Node key
|
||||||
|
key: Vec<String>,
|
||||||
|
},
|
||||||
/// Rename a node key
|
/// Rename a node key
|
||||||
Rename {
|
Rename {
|
||||||
/// Old key
|
/// Old key
|
||||||
|
|
@ -309,6 +314,9 @@ enum AdminCmd {
|
||||||
Topology,
|
Topology,
|
||||||
/// Run consistency checks and repair
|
/// Run consistency checks and repair
|
||||||
Fsck,
|
Fsck,
|
||||||
|
/// Rebuild index from capnp logs (use after fsck finds issues)
|
||||||
|
#[command(name = "repair-index")]
|
||||||
|
RepairIndex,
|
||||||
/// Find and merge duplicate nodes (same key, multiple UUIDs)
|
/// Find and merge duplicate nodes (same key, multiple UUIDs)
|
||||||
Dedup {
|
Dedup {
|
||||||
/// Apply the merge (default: dry run)
|
/// Apply the merge (default: dry run)
|
||||||
|
|
@ -398,6 +406,7 @@ impl Run for NodeCmd {
|
||||||
async fn run(self) -> anyhow::Result<()> {
|
async fn run(self) -> anyhow::Result<()> {
|
||||||
match self {
|
match self {
|
||||||
Self::Delete { key } => cli::node::cmd_node_delete(&key).await,
|
Self::Delete { key } => cli::node::cmd_node_delete(&key).await,
|
||||||
|
Self::Restore { key } => cli::node::cmd_node_restore(&key).await,
|
||||||
Self::Rename { old_key, new_key } => cli::node::cmd_node_rename(&old_key, &new_key).await,
|
Self::Rename { old_key, new_key } => cli::node::cmd_node_rename(&old_key, &new_key).await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -445,6 +454,7 @@ impl Run for AdminCmd {
|
||||||
Self::Health => cli::admin::cmd_health().await,
|
Self::Health => cli::admin::cmd_health().await,
|
||||||
Self::Topology => cli::admin::cmd_topology().await,
|
Self::Topology => cli::admin::cmd_topology().await,
|
||||||
Self::Fsck => cli::admin::cmd_fsck().await,
|
Self::Fsck => cli::admin::cmd_fsck().await,
|
||||||
|
Self::RepairIndex => cli::admin::cmd_repair_index().await,
|
||||||
Self::Dedup { apply } => cli::admin::cmd_dedup(apply).await,
|
Self::Dedup { apply } => cli::admin::cmd_dedup(apply).await,
|
||||||
Self::DailyCheck => cli::admin::cmd_daily_check().await,
|
Self::DailyCheck => cli::admin::cmd_daily_check().await,
|
||||||
Self::LoadContext { stats } => cli::node::cmd_load_context(stats).await,
|
Self::LoadContext { stats } => cli::node::cmd_load_context(stats).await,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue