Skip to content

Commit 4a15ec4

Browse files
committed
store: Track pruning progress in the database
Also adds graphman commands to view the progress
1 parent ddf9042 commit 4a15ec4

File tree

10 files changed

+903
-74
lines changed

10 files changed

+903
-74
lines changed

graph/src/components/store/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,9 @@ pub struct PruneRequest {
10031003
pub earliest_block: BlockNumber,
10041004
/// The last block that contains final entities not subject to a reorg
10051005
pub final_block: BlockNumber,
1006+
/// The first block for which the deployment contained entities when the
1007+
/// request was made
1008+
pub first_block: BlockNumber,
10061009
/// The latest block, i.e., the subgraph head
10071010
pub latest_block: BlockNumber,
10081011
/// Use the rebuild strategy when removing more than this fraction of
@@ -1066,6 +1069,7 @@ impl PruneRequest {
10661069
earliest_block,
10671070
final_block,
10681071
latest_block,
1072+
first_block,
10691073
rebuild_threshold,
10701074
delete_threshold,
10711075
})

node/src/bin/manager.rs

Lines changed: 110 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -297,35 +297,13 @@ pub enum Command {
297297
#[clap(subcommand)]
298298
Index(IndexCommand),
299299

300-
/// Prune a deployment
300+
/// Prune subgraphs by removing old entity versions
301301
///
302302
/// Keep only entity versions that are needed to respond to queries at
303303
/// block heights that are within `history` blocks of the subgraph head;
304304
/// all other entity versions are removed.
305-
///
306-
/// Unless `--once` is given, this setting is permanent and the subgraph
307-
/// will periodically be pruned to remove history as the subgraph head
308-
/// moves forward.
309-
Prune {
310-
/// The deployment to prune (see `help info`)
311-
deployment: DeploymentSearch,
312-
/// Prune by rebuilding tables when removing more than this fraction
313-
/// of history. Defaults to GRAPH_STORE_HISTORY_REBUILD_THRESHOLD
314-
#[clap(long, short)]
315-
rebuild_threshold: Option<f64>,
316-
/// Prune by deleting when removing more than this fraction of
317-
/// history but less than rebuild_threshold. Defaults to
318-
/// GRAPH_STORE_HISTORY_DELETE_THRESHOLD
319-
#[clap(long, short)]
320-
delete_threshold: Option<f64>,
321-
/// How much history to keep in blocks. Defaults to
322-
/// GRAPH_MIN_HISTORY_BLOCKS
323-
#[clap(long, short = 'y')]
324-
history: Option<usize>,
325-
/// Prune only this once
326-
#[clap(long, short)]
327-
once: bool,
328-
},
305+
#[clap(subcommand)]
306+
Prune(PruneCommand),
329307

330308
/// General database management
331309
#[clap(subcommand)]
@@ -694,6 +672,67 @@ pub enum StatsCommand {
694672
},
695673
}
696674

675+
#[derive(Clone, Debug, Subcommand)]
676+
pub enum PruneCommand {
677+
/// Prune a deployment in the foreground
678+
///
679+
/// Unless `--once` is given, this setting is permanent and the subgraph
680+
/// will periodically be pruned to remove history as the subgraph head
681+
/// moves forward.
682+
Run {
683+
/// The deployment to prune (see `help info`)
684+
deployment: DeploymentSearch,
685+
/// Prune by rebuilding tables when removing more than this fraction
686+
/// of history. Defaults to GRAPH_STORE_HISTORY_REBUILD_THRESHOLD
687+
#[clap(long, short)]
688+
rebuild_threshold: Option<f64>,
689+
/// Prune by deleting when removing more than this fraction of
690+
/// history but less than rebuild_threshold. Defaults to
691+
/// GRAPH_STORE_HISTORY_DELETE_THRESHOLD
692+
#[clap(long, short)]
693+
delete_threshold: Option<f64>,
694+
/// How much history to keep in blocks. Defaults to
695+
/// GRAPH_MIN_HISTORY_BLOCKS
696+
#[clap(long, short = 'y')]
697+
history: Option<usize>,
698+
/// Prune only this once
699+
#[clap(long, short)]
700+
once: bool,
701+
},
702+
/// Prune a deployment in the background
703+
///
704+
/// Set the amount of history the subgraph should retain. The actual
705+
/// data removal happens in the background and can be monitored with
706+
/// `prune status`. It can take several minutes of the first pruning to
707+
/// start, during which time `prune status` will not return any
708+
/// information
709+
Set {
710+
/// The deployment to prune (see `help info`)
711+
deployment: DeploymentSearch,
712+
/// Prune by rebuilding tables when removing more than this fraction
713+
/// of history. Defaults to GRAPH_STORE_HISTORY_REBUILD_THRESHOLD
714+
#[clap(long, short)]
715+
rebuild_threshold: Option<f64>,
716+
/// Prune by deleting when removing more than this fraction of
717+
/// history but less than rebuild_threshold. Defaults to
718+
/// GRAPH_STORE_HISTORY_DELETE_THRESHOLD
719+
#[clap(long, short)]
720+
delete_threshold: Option<f64>,
721+
/// How much history to keep in blocks. Defaults to
722+
/// GRAPH_MIN_HISTORY_BLOCKS
723+
#[clap(long, short = 'y')]
724+
history: Option<usize>,
725+
},
726+
/// Show the status of a pruning operation
727+
Status {
728+
/// The number of the pruning run
729+
#[clap(long, short)]
730+
run: Option<usize>,
731+
/// The deployment to check (see `help info`)
732+
deployment: DeploymentSearch,
733+
},
734+
}
735+
697736
#[derive(Clone, Debug, Subcommand)]
698737
pub enum IndexCommand {
699738
/// Creates a new database index.
@@ -1613,25 +1652,52 @@ async fn main() -> anyhow::Result<()> {
16131652
}
16141653
}
16151654
}
1616-
Prune {
1617-
deployment,
1618-
history,
1619-
rebuild_threshold,
1620-
delete_threshold,
1621-
once,
1622-
} => {
1623-
let (store, primary_pool) = ctx.store_and_primary();
1624-
let history = history.unwrap_or(ENV_VARS.min_history_blocks.try_into()?);
1625-
commands::prune::run(
1626-
store,
1627-
primary_pool,
1628-
deployment,
1629-
history,
1630-
rebuild_threshold,
1631-
delete_threshold,
1632-
once,
1633-
)
1634-
.await
1655+
Prune(cmd) => {
1656+
use PruneCommand::*;
1657+
match cmd {
1658+
Run {
1659+
deployment,
1660+
history,
1661+
rebuild_threshold,
1662+
delete_threshold,
1663+
once,
1664+
} => {
1665+
let (store, primary_pool) = ctx.store_and_primary();
1666+
let history = history.unwrap_or(ENV_VARS.min_history_blocks.try_into()?);
1667+
commands::prune::run(
1668+
store,
1669+
primary_pool,
1670+
deployment,
1671+
history,
1672+
rebuild_threshold,
1673+
delete_threshold,
1674+
once,
1675+
)
1676+
.await
1677+
}
1678+
Set {
1679+
deployment,
1680+
rebuild_threshold,
1681+
delete_threshold,
1682+
history,
1683+
} => {
1684+
let (store, primary_pool) = ctx.store_and_primary();
1685+
let history = history.unwrap_or(ENV_VARS.min_history_blocks.try_into()?);
1686+
commands::prune::set(
1687+
store,
1688+
primary_pool,
1689+
deployment,
1690+
history,
1691+
rebuild_threshold,
1692+
delete_threshold,
1693+
)
1694+
.await
1695+
}
1696+
Status { run, deployment } => {
1697+
let (store, primary_pool) = ctx.store_and_primary();
1698+
commands::prune::status(store, primary_pool, deployment, run).await
1699+
}
1700+
}
16351701
}
16361702
Drop {
16371703
deployment,

0 commit comments

Comments
 (0)