diff --git a/CHANGELOG.md b/CHANGELOG.md index a3eb22b85b..11d2552431 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ - [#924](https://github.com/crypto-org-chain/cronos/pull/924) memiavl support `Export` API. - [#934](https://github.com/crypto-org-chain/cronos/pull/934) Add pebbledb backend. - [#950](https://github.com/crypto-org-chain/cronos/pull/950) Implement memiavl and integrate with state machine. +- [#985](https://github.com/crypto-org-chain/cronos/pull/985) Fix versiondb verify command on older versions *Feb 09, 2022* diff --git a/versiondb/client/convert_to_sst.go b/versiondb/client/convert_to_sst.go index 603344f038..9559fdf59d 100644 --- a/versiondb/client/convert_to_sst.go +++ b/versiondb/client/convert_to_sst.go @@ -90,6 +90,9 @@ func convertSingleStore(store string, changeSetDir, sstDir string, sstFileSize u if err != nil { return err } + if len(csFiles) == 0 { + return nil + } prefix := []byte(fmt.Sprintf(tsrocksdb.StorePrefixTpl, store)) isEmpty := true @@ -179,6 +182,10 @@ func scanChangeSetFiles(changeSetDir, store string) ([]FileWithVersion, error) { storeDir := filepath.Join(changeSetDir, store) entries, err := os.ReadDir(storeDir) if err != nil { + // assume the change set files are taken from older versions, don't include all stores. + if os.IsNotExist(err) { + return nil, nil + } return nil, err } fileNames := make([]string, len(entries)) diff --git a/versiondb/client/verify.go b/versiondb/client/verify.go index f663d329d3..194e78837d 100644 --- a/versiondb/client/verify.go +++ b/versiondb/client/verify.go @@ -105,6 +105,10 @@ func VerifyChangeSetCmd(defaultStores []string) *cobra.Command { if err != nil { return err } + if storeInfo == nil { + // the store don't exist before target version, don't affect the commit info and app hash. + return nil + } storeInfosLock.Lock() defer storeInfosLock.Unlock() @@ -186,19 +190,9 @@ func VerifyChangeSetCmd(defaultStores []string) *cobra.Command { } // verifyOneStore process a single store, can run in parallel with other stores. +// if the store don't exist before the `targetVersion`, returns nil without error. func verifyOneStore(tree *memiavl.Tree, store, changeSetDir, saveSnapshot string, targetVersion int64, buildHashIndex bool) (*storetypes.StoreInfo, error) { - // scan directory to find the change set files - storeDir := filepath.Join(changeSetDir, store) - entries, err := os.ReadDir(storeDir) - if err != nil { - return nil, err - } - fileNames := make([]string, len(entries)) - for i, entry := range entries { - fileNames[i] = filepath.Join(storeDir, entry.Name()) - } - - filesWithVersion, err := SortFilesByFirstVerson(fileNames) + filesWithVersion, err := scanChangeSetFiles(changeSetDir, store) if err != nil { return nil, err } @@ -208,6 +202,10 @@ func verifyOneStore(tree *memiavl.Tree, store, changeSetDir, saveSnapshot string } // set the initial version for the store initialVersion := filesWithVersion[0].Version + if targetVersion > 0 && initialVersion > uint64(targetVersion) { + return nil, nil + } + if err := tree.SetInitialVersion(int64(initialVersion)); err != nil { return nil, err }