Skip to content

Commit

Permalink
node, store: Warn if reassigning to a new node
Browse files Browse the repository at this point in the history
  • Loading branch information
lutter committed Mar 6, 2023
1 parent f8d0143 commit d2c7cd7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
9 changes: 9 additions & 0 deletions node/src/manager/commands/assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,14 @@ pub fn reassign(
};
conn.send_store_event(sender, &StoreEvent::new(changes))?;

// It's easy to make a typo in the name of the node; if this operation
// assigns to a node that wasn't used before, warn the user that they
// might have mistyped the node name
let mirror = catalog::Mirror::primary_only(primary);
let count = mirror.assignments(&node)?.len();
if count == 1 {
println!("warning: this is the only deployment assigned to {node}");
println!(" are you sure it is spelled correctly?");
}
Ok(())
}
2 changes: 1 addition & 1 deletion store/postgres/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ pub mod command_support {
pub use crate::block_store::primary as block_store;
pub use crate::catalog::{account_like, stats};
pub use crate::copy::{copy_state, copy_table_state};
pub use crate::primary::Connection;
pub use crate::primary::{
active_copies, deployment_schemas, ens_names, subgraph, subgraph_deployment_assignment,
subgraph_version, Site,
};
pub use crate::primary::{Connection, Mirror};
}
pub mod index {
pub use crate::relational::index::{CreateIndex, Method};
Expand Down
9 changes: 9 additions & 0 deletions store/postgres/src/primary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,15 @@ impl Mirror {
Mirror { pools }
}

/// Create a mirror that only uses the primary. Such a mirror will not
/// be able to do anything if the primary is down, and should only be
/// used for non-critical uses like command line tools
pub fn primary_only(primary: ConnectionPool) -> Mirror {
Mirror {
pools: vec![primary],
}
}

/// Execute the function `f` with connections from each of our pools in
/// order until for one of them we get any result other than
/// `Err(StoreError::DatabaseUnavailable)`. In other words, we try to
Expand Down

0 comments on commit d2c7cd7

Please sign in to comment.