From e09535454735250ee2f14e36515c44ae939087b2 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Mon, 11 Nov 2024 17:33:48 +0800 Subject: [PATCH] fix data manually --- app/versiondb.go | 4 ---- versiondb/client/cmd.go | 1 + versiondb/client/fixdata.go | 29 +++++++++++++++++++++++++++++ versiondb/tsrocksdb/store.go | 6 +++--- 4 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 versiondb/client/fixdata.go diff --git a/app/versiondb.go b/app/versiondb.go index 794ea71b60..381db1027b 100644 --- a/app/versiondb.go +++ b/app/versiondb.go @@ -36,10 +36,6 @@ func (app *App) setupVersionDB( } // see: https://github.com/crypto-org-chain/cronos/issues/1683 - if err := versionDB.FixData(exposeStoreKeys); err != nil { - return nil, err - } - versionDB.SetSkipVersionZero(true) service := versiondb.NewStreamingService(versionDB, exposeStoreKeys) diff --git a/versiondb/client/cmd.go b/versiondb/client/cmd.go index 4bf36343e8..5955037f71 100644 --- a/versiondb/client/cmd.go +++ b/versiondb/client/cmd.go @@ -28,6 +28,7 @@ func ChangeSetGroupCmd(opts Options) *cobra.Command { ChangeSetToVersionDBCmd(), RestoreAppDBCmd(opts), RestoreVersionDBCmd(), + FixDataCmd(opts.DefaultStores), ) return cmd } diff --git a/versiondb/client/fixdata.go b/versiondb/client/fixdata.go new file mode 100644 index 0000000000..c3d6f9c0ff --- /dev/null +++ b/versiondb/client/fixdata.go @@ -0,0 +1,29 @@ +package client + +import ( + "github.com/crypto-org-chain/cronos/versiondb/tsrocksdb" + "github.com/spf13/cobra" +) + +func FixDataCmd(stores []string) *cobra.Command { + cmd := &cobra.Command{ + Use: "fixdata", + 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] + versionDB, err := tsrocksdb.NewStore(dir) + if err != nil { + return err + } + + // see: https://github.com/crypto-org-chain/cronos/issues/1683 + if err := versionDB.FixData(stores); err != nil { + return err + } + + return nil + }, + } + return cmd +} diff --git a/versiondb/tsrocksdb/store.go b/versiondb/tsrocksdb/store.go index 17ca850372..5a00201bed 100644 --- a/versiondb/tsrocksdb/store.go +++ b/versiondb/tsrocksdb/store.go @@ -235,9 +235,9 @@ func (s Store) Flush() error { // FixData fixes wrong data written in versiondb due to rocksdb upgrade, the operation is idempotent. // see: https://github.com/crypto-org-chain/cronos/issues/1683 // call this before `SetSkipVersionZero(true)`. -func (s Store) FixData(storeKeys []types.StoreKey) error { - for _, storeKey := range storeKeys { - if err := s.fixDataStore(storeKey.Name()); err != nil { +func (s Store) FixData(storeNames []string) error { + for _, storeName := range storeNames { + if err := s.fixDataStore(storeName); err != nil { return err } }