diff --git a/CHANGELOG.md b/CHANGELOG.md index fa8028812a..becf69fdd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - [#986](https://github.com/crypto-org-chain/cronos/pull/986) Use go 1.20. - [#984](https://github.com/crypto-org-chain/cronos/pull/984) experimental integration of memiavl. +- [#985](https://github.com/crypto-org-chain/cronos/pull/985) Fix versiondb verify command on older versions *April 13, 2023* diff --git a/versiondb/client/convert_to_sst.go b/versiondb/client/convert_to_sst.go index 651517a20c..1f361f2375 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..f036b9f680 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,28 +190,22 @@ 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 } if len(filesWithVersion) == 0 { - return nil, fmt.Errorf("change set directory is empty") + return nil, nil } // 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 }