Skip to content

Commit

Permalink
[Feature] A new graphman command to restart a subgraph (#4742)
Browse files Browse the repository at this point in the history
node : Add new graphman command to restart a subgraph
  • Loading branch information
Misha authored Jul 12, 2023
1 parent 80aa2b0 commit 40aba26
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- `graphman` now has two new commands `pause` and `resume` that can be used to pause and resume a deployment
- A new table `subgraph_features` is added which tracks information like spec_version, api_version, network, features, datasources etc
- The schema for the `subgraphFeatures` endpoint now includes data from the `subgraph_features` table
- `graphman` now has new command `restart` that can be used to sequentially pause and resume a deployment

<!--
Note: the changes in this PR were technically released in v0.31.0, but the feature also requires changes to graph-cli, which at the time of writing has NOT been released. This feature will make it into the release notes of graph-node only once graph-cli has been updated.
Expand Down
17 changes: 17 additions & 0 deletions node/src/bin/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,19 @@ pub enum Command {
/// The deployment (see `help info`)
deployment: DeploymentSearch,
},
/// Pause and resume a deployment
Restart {
/// The deployment (see `help info`)
deployment: DeploymentSearch,
/// Sleep for this many seconds after pausing subgraphs
#[clap(
long,
short,
default_value = "20",
parse(try_from_str = parse_duration_in_secs)
)]
sleep: Duration,
},
/// Rewind a subgraph to a specific block
Rewind {
/// Force rewinding even if the block hash is not found in the local
Expand Down Expand Up @@ -1120,6 +1133,10 @@ async fn main() -> anyhow::Result<()> {
let sender = ctx.notification_sender();
commands::assign::pause_or_resume(ctx.primary_pool(), &sender, &deployment, false)
}
Restart { deployment, sleep } => {
let sender = ctx.notification_sender();
commands::assign::restart(ctx.primary_pool(), &sender, &deployment, sleep)
}
Rewind {
force,
sleep,
Expand Down
18 changes: 18 additions & 0 deletions node/src/manager/commands/assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use graph::prelude::{anyhow::anyhow, Error, NodeId, StoreEvent};
use graph_store_postgres::{
command_support::catalog, connection_pool::ConnectionPool, NotificationSender,
};
use std::thread;
use std::time::Duration;

use crate::manager::deployment::DeploymentSearch;

Expand Down Expand Up @@ -109,3 +111,19 @@ pub fn pause_or_resume(

Ok(())
}

pub fn restart(
primary: ConnectionPool,
sender: &NotificationSender,
search: &DeploymentSearch,
sleep: Duration,
) -> Result<(), Error> {
pause_or_resume(primary.clone(), sender, search, true)?;
println!(
"Waiting {}s to make sure pausing was processed",
sleep.as_secs()
);
thread::sleep(sleep);
pause_or_resume(primary, sender, search, false)?;
Ok(())
}

0 comments on commit 40aba26

Please sign in to comment.