-
Notifications
You must be signed in to change notification settings - Fork 241
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 (#1685)
* Problem: no command to fix corrupted data in versiondb Closes: #1683 Solution: - add fix command to fix corrupted data in versiondb * rename * support SkipVersionZero * support SkipVersionZero * cleanup * cleanup * cleanup * destroy * fix data manually * Update CHANGELOG.md Signed-off-by: yihuang <[email protected]> * Update versiondb/tsrocksdb/store.go Co-authored-by: mmsqe <[email protected]> Signed-off-by: yihuang <[email protected]> * cli * cleanup * Update versiondb/client/fixdata.go Signed-off-by: yihuang <[email protected]> * rename * fix test * check nil * don't return nil as empty slice * add dryrun mode * cleanup * separete read from iteration * store name flag * validate timestamp * skip non-zero version * update gomod2nix * fix build * flush after fix * fix * revert --------- Signed-off-by: yihuang <[email protected]> Co-authored-by: mmsqe <[email protected]>
- Loading branch information
Showing
9 changed files
with
321 additions
and
21 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
Large diffs are not rendered by default.
Oops, something went wrong.
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-name" | ||
) | ||
|
||
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, []string{}, "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.