@@ -297,35 +297,13 @@ pub enum Command {
297
297
#[ clap( subcommand) ]
298
298
Index ( IndexCommand ) ,
299
299
300
- /// Prune a deployment
300
+ /// Prune subgraphs by removing old entity versions
301
301
///
302
302
/// Keep only entity versions that are needed to respond to queries at
303
303
/// block heights that are within `history` blocks of the subgraph head;
304
304
/// 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 ) ,
329
307
330
308
/// General database management
331
309
#[ clap( subcommand) ]
@@ -694,6 +672,67 @@ pub enum StatsCommand {
694
672
} ,
695
673
}
696
674
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
+
697
736
#[ derive( Clone , Debug , Subcommand ) ]
698
737
pub enum IndexCommand {
699
738
/// Creates a new database index.
@@ -1613,25 +1652,52 @@ async fn main() -> anyhow::Result<()> {
1613
1652
}
1614
1653
}
1615
1654
}
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
+ }
1635
1701
}
1636
1702
Drop {
1637
1703
deployment,
0 commit comments