Skip to content

Commit d2c7cd7

Browse files
committed
node, store: Warn if reassigning to a new node
1 parent f8d0143 commit d2c7cd7

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

node/src/manager/commands/assign.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,14 @@ pub fn reassign(
5858
};
5959
conn.send_store_event(sender, &StoreEvent::new(changes))?;
6060

61+
// It's easy to make a typo in the name of the node; if this operation
62+
// assigns to a node that wasn't used before, warn the user that they
63+
// might have mistyped the node name
64+
let mirror = catalog::Mirror::primary_only(primary);
65+
let count = mirror.assignments(&node)?.len();
66+
if count == 1 {
67+
println!("warning: this is the only deployment assigned to {node}");
68+
println!(" are you sure it is spelled correctly?");
69+
}
6170
Ok(())
6271
}

store/postgres/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ pub mod command_support {
7171
pub use crate::block_store::primary as block_store;
7272
pub use crate::catalog::{account_like, stats};
7373
pub use crate::copy::{copy_state, copy_table_state};
74-
pub use crate::primary::Connection;
7574
pub use crate::primary::{
7675
active_copies, deployment_schemas, ens_names, subgraph, subgraph_deployment_assignment,
7776
subgraph_version, Site,
7877
};
78+
pub use crate::primary::{Connection, Mirror};
7979
}
8080
pub mod index {
8181
pub use crate::relational::index::{CreateIndex, Method};

store/postgres/src/primary.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,6 +1570,15 @@ impl Mirror {
15701570
Mirror { pools }
15711571
}
15721572

1573+
/// Create a mirror that only uses the primary. Such a mirror will not
1574+
/// be able to do anything if the primary is down, and should only be
1575+
/// used for non-critical uses like command line tools
1576+
pub fn primary_only(primary: ConnectionPool) -> Mirror {
1577+
Mirror {
1578+
pools: vec![primary],
1579+
}
1580+
}
1581+
15731582
/// Execute the function `f` with connections from each of our pools in
15741583
/// order until for one of them we get any result other than
15751584
/// `Err(StoreError::DatabaseUnavailable)`. In other words, we try to

0 commit comments

Comments
 (0)