-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: no command to fix corrupted data in versiondb (backport: #1685)
Closes: #1683 Solution: - add fix command to fix corrupted data in versiondb rename support SkipVersionZero support SkipVersionZero cleanup cleanup cleanup fix test cleanup destroy log store name fix data manually cli Update versiondb/client/fixdata.go Signed-off-by: yihuang <[email protected]> Update versiondb/client/fixdata.go Signed-off-by: yihuang <[email protected]> rnemae Update CHANGELOG.md Signed-off-by: yihuang <[email protected]> fix test don't return nil as empty slice add dryrun mode separete read from iteration add stores flag debug add timestamp api
- Loading branch information
Showing
9 changed files
with
324 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package client | ||
|
||
import ( | ||
"github.com/crypto-org-chain/cronos/versiondb/tsrocksdb" | ||
"github.com/linxGnu/grocksdb" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
FlagDryRun = "dry-run" | ||
FlagStore = "store" | ||
) | ||
|
||
func FixDataCmd(defaultStores []string) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "fixdata <dir>", | ||
Args: cobra.ExactArgs(1), | ||
Short: "Fix wrong data in versiondb, see: https://github.com/crypto-org-chain/cronos/issues/1683", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
dir := args[0] | ||
dryRun, err := cmd.Flags().GetBool(FlagDryRun) | ||
if err != nil { | ||
return err | ||
} | ||
stores, err := cmd.Flags().GetStringArray(FlagStore) | ||
if err != nil { | ||
return err | ||
} | ||
if len(stores) == 0 { | ||
stores = defaultStores | ||
} | ||
|
||
var ( | ||
db *grocksdb.DB | ||
cfHandle *grocksdb.ColumnFamilyHandle | ||
) | ||
|
||
if dryRun { | ||
db, cfHandle, err = tsrocksdb.OpenVersionDBForReadOnly(dir, false) | ||
} else { | ||
db, cfHandle, err = tsrocksdb.OpenVersionDB(dir) | ||
} | ||
if err != nil { | ||
return err | ||
} | ||
|
||
versionDB := tsrocksdb.NewStoreWithDB(db, cfHandle) | ||
if err := versionDB.FixData(stores, dryRun); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
cmd.Flags().Bool(FlagDryRun, false, "Dry run, do not write to the database, open the database in read-only mode.") | ||
cmd.Flags().StringArray(FlagStore, nil, "Store names to fix, if not specified, all stores will be fixed.") | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.