@@ -52,6 +52,7 @@ var ChainCmd = &cli.Command{
52
52
ChainStateInspect ,
53
53
ChainStateCompute ,
54
54
ChainStateComputeRange ,
55
+ ChainPruneCmd ,
55
56
},
56
57
}
57
58
@@ -813,6 +814,105 @@ var ChainSetHeadCmd = &cli.Command{
813
814
},
814
815
}
815
816
817
+ var chainPruneHotGCCmd = & cli.Command {
818
+ Name : "hot" ,
819
+ Usage : "run online (badger vlog) garbage collection on hotstore" ,
820
+ Flags : []cli.Flag {
821
+ & cli.Float64Flag {Name : "threshold" , Value : 0.01 , Usage : "Threshold of vlog garbage for gc" },
822
+ & cli.BoolFlag {Name : "periodic" , Value : false , Usage : "Run periodic gc over multiple vlogs. Otherwise run gc once" },
823
+ },
824
+ Action : func (cctx * cli.Context ) error {
825
+ ctx := lotuscli .ReqContext (cctx )
826
+ lapi , closer , err := GetAPI (ctx )
827
+ if err != nil {
828
+ return err
829
+ }
830
+ defer closer ()
831
+
832
+ opts := api.HotGCOpts {}
833
+ opts .Periodic = cctx .Bool ("periodic" )
834
+ opts .Threshold = cctx .Float64 ("threshold" )
835
+
836
+ gcStart := time .Now ()
837
+ err = lapi .ChainHotGC (ctx , opts )
838
+ gcTime := time .Since (gcStart )
839
+ fmt .Printf ("Online GC took %v (periodic <%t> threshold <%f>)" , gcTime , opts .Periodic , opts .Threshold )
840
+ return err
841
+ },
842
+ }
843
+
844
+ var chainPruneHotMovingGCCmd = & cli.Command {
845
+ Name : "hot-moving" ,
846
+ Usage : "run moving gc on hotstore" ,
847
+ Action : func (cctx * cli.Context ) error {
848
+ ctx := lotuscli .ReqContext (cctx )
849
+ lapi , closer , err := GetAPI (ctx )
850
+ if err != nil {
851
+ return err
852
+ }
853
+ defer closer ()
854
+ opts := api.HotGCOpts {}
855
+ opts .Moving = true
856
+
857
+ gcStart := time .Now ()
858
+ err = lapi .ChainHotGC (ctx , opts )
859
+ gcTime := time .Since (gcStart )
860
+ fmt .Printf ("Moving GC took %v" , gcTime )
861
+ return err
862
+ },
863
+ }
864
+
865
+ var chainPruneColdCmd = & cli.Command {
866
+ Name : "compact-cold" ,
867
+ Usage : "force splitstore compaction on cold store state and run gc" ,
868
+ Flags : []cli.Flag {
869
+ & cli.BoolFlag {
870
+ Name : "online-gc" ,
871
+ Value : false ,
872
+ Usage : "use online gc for garbage collecting the coldstore" ,
873
+ },
874
+ & cli.BoolFlag {
875
+ Name : "moving-gc" ,
876
+ Value : false ,
877
+ Usage : "use moving gc for garbage collecting the coldstore" ,
878
+ },
879
+ & cli.IntFlag {
880
+ Name : "retention" ,
881
+ Value : - 1 ,
882
+ Usage : "specify state retention policy" ,
883
+ },
884
+ },
885
+ Action : func (cctx * cli.Context ) error {
886
+ ctx := lotuscli .ReqContext (cctx )
887
+ lapi , closer , err := GetAPI (ctx )
888
+ if err != nil {
889
+ return err
890
+ }
891
+ defer closer ()
892
+
893
+ opts := api.PruneOpts {}
894
+ if cctx .Bool ("online-gc" ) {
895
+ opts .MovingGC = false
896
+ }
897
+ if cctx .Bool ("moving-gc" ) {
898
+ opts .MovingGC = true
899
+ }
900
+ opts .RetainState = int64 (cctx .Int ("retention" ))
901
+
902
+ return lapi .ChainPrune (ctx , opts )
903
+ },
904
+ }
905
+
906
+ var ChainPruneCmd = & cli.Command {
907
+ Name : "prune" ,
908
+ Usage : "splitstore gc" ,
909
+ Subcommands : []* cli.Command {
910
+ chainPruneColdCmd ,
911
+ chainPruneHotGCCmd ,
912
+ chainPruneHotMovingGCCmd ,
913
+ },
914
+ }
915
+
816
916
func printTipSet (format string , ts * types.TipSet ) {
817
917
format = strings .ReplaceAll (format , "<height>" , fmt .Sprint (ts .Height ()))
818
918
format = strings .ReplaceAll (format , "<time>" , time .Unix (int64 (ts .MinTimestamp ()), 0 ).Format (time .Stamp ))
0 commit comments