Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] A new graphman command to restart a subgraph #4742

Merged
merged 6 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great to print out a message to console.. saying something like "Waiting for x seconds"

Actually might be good to have a "Pausing "

and a "resuming too

Copy link
Contributor Author

@SozinM SozinM Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New logs format:

pausing QmTGXDUdbYNuThTAUbeSA15BcQCRxX6qR1PyPN23e3JXFJ[210]
Operation completed
Waiting 20s to make sure pausing was processed
resuming QmTGXDUdbYNuThTAUbeSA15BcQCRxX6qR1PyPN23e3JXFJ[210]
Operation completed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, I'll test it out

pause_or_resume(primary, sender, search, false)?;
Ok(())
}