Skip to content

Commit

Permalink
Problem: versiondb lag behind when os reboot (crypto-org-chain#1304)
Browse files Browse the repository at this point in the history
* Problem: versiondb lag behind when os reboot

Closes: crypto-org-chain#1301

Solution:
- do fsync when writing versiondb

* Update CHANGELOG.md

Signed-off-by: yihuang <huang@crypto.com>

* relax version checking

* changelog

---------

Signed-off-by: yihuang <huang@crypto.com>
  • Loading branch information
yihuang authored and mmsqe committed Jan 30, 2024
1 parent effc7ba commit e78a7de
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- [#1241](https://github.com/crypto-org-chain/cronos/pull/1241) Improve parallelization of memiavl restoration.
- [#1302](https://github.com/crypto-org-chain/cronos/pull/1302) Fix concurrent map access in rootmulti store.
- [#1304](https://github.com/crypto-org-chain/cronos/pull/1304) Write versiondb with fsync, and relax the version requirement on startup.

### State Machine Breaking

Expand Down
5 changes: 3 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,9 @@ func New(
if qms != nil {
v1 := qms.LatestVersion()
v2 := app.LastBlockHeight()
if v1 > 0 && v1 != v2 {
tmos.Exit(fmt.Sprintf("versiondb lastest version %d don't match iavl latest version %d", v1, v2))
if v1 > 0 && v1 < v2 {
// try to prevent gap being created in versiondb
tmos.Exit(fmt.Sprintf("versiondb version %d lag behind iavl version %d", v1, v2))
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions versiondb/tsrocksdb/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ var (

_ versiondb.VersionStore = Store{}

defaultWriteOpts = grocksdb.NewDefaultWriteOptions()
defaultReadOpts = grocksdb.NewDefaultReadOptions()
defaultWriteOpts = grocksdb.NewDefaultWriteOptions()
defaultSyncWriteOpts = grocksdb.NewDefaultWriteOptions()
defaultReadOpts = grocksdb.NewDefaultReadOptions()
)

func init() {
defaultSyncWriteOpts.SetSync(true)
}

type Store struct {
db *grocksdb.DB
cfHandle *grocksdb.ColumnFamilyHandle
Expand Down Expand Up @@ -77,7 +82,7 @@ func (s Store) PutAtVersion(version int64, changeSet []types.StoreKVPair) error
}
}

return s.db.Write(defaultWriteOpts, batch)
return s.db.Write(defaultSyncWriteOpts, batch)
}

func (s Store) GetAtVersionSlice(storeKey string, key []byte, version *int64) (*grocksdb.Slice, error) {
Expand Down

0 comments on commit e78a7de

Please sign in to comment.