From 8256c0594975687d2f65d92cf9054ba8be941fda Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 26 Jan 2024 17:33:05 +0800 Subject: [PATCH 1/4] Problem: versiondb lag behind when os reboot Closes: #1301 Solution: - do fsync when writing versiondb --- CHANGELOG.md | 1 + versiondb/tsrocksdb/store.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 640668047c..9bf61f44ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - [#1292](https://github.com/crypto-org-chain/cronos/pull/1292) memiavl cancel background snapshot rewriting when graceful shutdown. - [#1294](https://github.com/crypto-org-chain/cronos/pull/1294) Update ethermint to fix and improve of debug_traceCall and eth_feeHistory. - [#1302](https://github.com/crypto-org-chain/cronos/pull/1302) Fix concurrent map access in rootmulti store. +- [#]() Write versiondb with fsync *January 5, 2024* diff --git a/versiondb/tsrocksdb/store.go b/versiondb/tsrocksdb/store.go index ebecd19717..b927ea36b9 100644 --- a/versiondb/tsrocksdb/store.go +++ b/versiondb/tsrocksdb/store.go @@ -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 @@ -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) { From 772b8aab54a214193ce6ec78c9e0c5f7336d11c8 Mon Sep 17 00:00:00 2001 From: yihuang Date: Fri, 26 Jan 2024 17:36:55 +0800 Subject: [PATCH 2/4] Update CHANGELOG.md Signed-off-by: yihuang --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bf61f44ad..b879c001fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ - [#1292](https://github.com/crypto-org-chain/cronos/pull/1292) memiavl cancel background snapshot rewriting when graceful shutdown. - [#1294](https://github.com/crypto-org-chain/cronos/pull/1294) Update ethermint to fix and improve of debug_traceCall and eth_feeHistory. - [#1302](https://github.com/crypto-org-chain/cronos/pull/1302) Fix concurrent map access in rootmulti store. -- [#]() Write versiondb with fsync +- [#1304](https://github.com/crypto-org-chain/cronos/pull/1304) Write versiondb with fsync *January 5, 2024* From 8b40a2ced5f169f2bdf8eda05f6672d38d0126bb Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 26 Jan 2024 19:38:01 +0800 Subject: [PATCH 3/4] relax version checking --- app/app.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/app.go b/app/app.go index 18d7f49672..f89989d42b 100644 --- a/app/app.go +++ b/app/app.go @@ -900,8 +900,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)) } } } From 052ef9d028c476f26d7a71640df2f9db60db4656 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Fri, 26 Jan 2024 19:39:37 +0800 Subject: [PATCH 4/4] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b879c001fa..cac7deb733 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ - [#1292](https://github.com/crypto-org-chain/cronos/pull/1292) memiavl cancel background snapshot rewriting when graceful shutdown. - [#1294](https://github.com/crypto-org-chain/cronos/pull/1294) Update ethermint to fix and improve of debug_traceCall and eth_feeHistory. - [#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 +- [#1304](https://github.com/crypto-org-chain/cronos/pull/1304) Write versiondb with fsync, and relax the version requirement on startup. *January 5, 2024*