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

fix: Pruning #161

Merged
merged 3 commits into from
Aug 7, 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
22 changes: 13 additions & 9 deletions client/pruning/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ func PruningCmd(appCreator servertypes.AppCreator) *cobra.Command {
Use: "prune",
Short: "Prune app history states by keeping the recent heights and deleting old heights",
Long: `Prune app history states by keeping the recent heights and deleting old heights.
The pruning option is provided via the '--pruning' flag or alternatively with '--pruning-keep-recent'
The pruning strategy is provided via the '--pruning' flag or alternatively with '--pruning-keep-recent'

For '--pruning' the options are as follows:

default: the last 362880 states are kept
nothing: all historic states will be saved, nothing will be deleted (i.e. archiving node)
everything: 2 latest states will be kept
custom: allow pruning options to be manually specified through 'pruning-keep-recent'.
custom: allow pruning options to be manually specified through the 'app.toml' config file or through CLI flags.
besides pruning options, database home directory and database backend type should also be specified via flags
'--home' and '--app-db-backend'.
valid app-db-backend type includes 'goleveldb', 'cleveldb', 'rocksdb', 'boltdb', and 'badgerdb'.
Expand Down Expand Up @@ -76,16 +76,20 @@ func PruningCmd(appCreator servertypes.AppCreator) *cobra.Command {
return fmt.Errorf("the database has no valid heights to prune, the latest height: %v", latestHeight)
}

var pruningHeights []int64
for height := int64(1); height < latestHeight; height++ {
if height < latestHeight-int64(pruningOptions.KeepRecent) {
pruningHeights = append(pruningHeights, height)
}
}
if len(pruningHeights) == 0 {
effectiveLastHeight := latestHeight - int64(pruningOptions.KeepRecent)

if effectiveLastHeight < 1 {
fmt.Printf("no heights to prune\n")
return nil
}

lenPH := effectiveLastHeight + 1
pruningHeights := make([]int64, lenPH)
for height := int64(1); height < lenPH; height++ {
pruningHeights[height] = height
}
pruningHeights = pruningHeights[1:]

fmt.Printf(
"pruning heights start from %v, end at %v\n",
pruningHeights[0],
Expand Down
2 changes: 1 addition & 1 deletion store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ func (rs *Store) PruneStores(clearStorePruningHeihgts bool, pruningHeights []int
pruningHeights = append(pruningHeights, rs.pruneHeights...)
}

if len(rs.pruneHeights) == 0 {
if len(pruningHeights) == 0 {
return
}

Expand Down
Loading