Skip to content

Commit 16d4ddf

Browse files
TerryhungTerry
andauthored
feat: add new command: prune (#1198)
* Add new command: prune * Change ther permission for lily api --------- Co-authored-by: Terry <[email protected]>
1 parent 6522e0e commit 16d4ddf

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

commands/chain.go

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ var ChainCmd = &cli.Command{
5252
ChainStateInspect,
5353
ChainStateCompute,
5454
ChainStateComputeRange,
55+
ChainPruneCmd,
5556
},
5657
}
5758

@@ -813,6 +814,105 @@ var ChainSetHeadCmd = &cli.Command{
813814
},
814815
}
815816

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+
816916
func printTipSet(format string, ts *types.TipSet) {
817917
format = strings.ReplaceAll(format, "<height>", fmt.Sprint(ts.Height()))
818918
format = strings.ReplaceAll(format, "<time>", time.Unix(int64(ts.MinTimestamp()), 0).Format(time.Stamp))

lens/lily/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ type LilyAPI interface {
5252
ChainGetParentMessages(context.Context, cid.Cid) ([]api.Message, error) //perm:read
5353
ChainSetHead(context.Context, types.TipSetKey) error //perm:read
5454
ChainGetGenesis(context.Context) (*types.TipSet, error) //perm:read
55+
ChainPrune(ctx context.Context, opts api.PruneOpts) error //perm:read
56+
ChainHotGC(ctx context.Context, opts api.HotGCOpts) error //perm:read
5557

5658
// trigger graceful shutdown
5759
Shutdown(context.Context) error

lens/lily/struct.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ type LilyAPIStruct struct {
6161
ChainGetTipSetAfterHeight func(context.Context, abi.ChainEpoch, types.TipSetKey) (*types.TipSet, error) `perm:"read"`
6262
ChainSetHead func(context.Context, types.TipSetKey) error `perm:"read"`
6363
ChainGetGenesis func(context.Context) (*types.TipSet, error) `perm:"read"`
64+
ChainPrune func(ctx context.Context, opts api.PruneOpts) error `perm:"read"`
65+
ChainHotGC func(ctx context.Context, opts api.HotGCOpts) error `perm:"read"`
6466

6567
LogList func(context.Context) ([]string, error) `perm:"read"`
6668
LogSetLevel func(context.Context, string, string) error `perm:"read"`
@@ -139,6 +141,14 @@ func (s *LilyAPIStruct) ChainSetHead(ctx context.Context, key types.TipSetKey) e
139141
return s.Internal.ChainSetHead(ctx, key)
140142
}
141143

144+
func (s *LilyAPIStruct) ChainPrune(ctx context.Context, opts api.PruneOpts) error {
145+
return s.Internal.ChainPrune(ctx, opts)
146+
}
147+
148+
func (s *LilyAPIStruct) ChainHotGC(ctx context.Context, opts api.HotGCOpts) error {
149+
return s.Internal.ChainHotGC(ctx, opts)
150+
}
151+
142152
func (s *LilyAPIStruct) ChainGetGenesis(ctx context.Context) (*types.TipSet, error) {
143153
return s.Internal.ChainGetGenesis(ctx)
144154
}

0 commit comments

Comments
 (0)