Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: rocksdb wal format sometimes not backward compatible #1379

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Improvements

* (test) [#1380](https://github.com/crypto-org-chain/cronos/pull/1380) Upgrade cosmovisor to 1.5.0 in integration test.
* (versiondb) [#1379](https://github.com/crypto-org-chain/cronos/pull/1379) Flush versiondb when graceful shutdown, make rocksdb upgrade smooth.

*April 8, 2024*

Expand Down
24 changes: 16 additions & 8 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ import (
// this line is used by starport scaffolding # stargate/app/moduleImport

memiavlstore "github.com/crypto-org-chain/cronos/store"
memiavlrootmulti "github.com/crypto-org-chain/cronos/store/rootmulti"
"github.com/crypto-org-chain/cronos/v2/x/cronos"
cronosclient "github.com/crypto-org-chain/cronos/v2/x/cronos/client"
cronoskeeper "github.com/crypto-org-chain/cronos/v2/x/cronos/keeper"
Expand Down Expand Up @@ -370,6 +369,8 @@ type App struct {

// module configurator
configurator module.Configurator

qms storetypes.MultiStore
}

// New returns a reference to an initialized chain.
Expand Down Expand Up @@ -860,10 +861,9 @@ func New(

// wire up the versiondb's `StreamingService` and `MultiStore`.
streamers := cast.ToStringSlice(appOpts.Get("store.streamers"))
var qms sdk.MultiStore
if slices.Contains(streamers, "versiondb") {
var err error
qms, err = app.setupVersionDB(homePath, keys, tkeys, memKeys)
app.qms, err = app.setupVersionDB(homePath, keys, tkeys, memKeys)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -900,8 +900,8 @@ func New(
tmos.Exit(err.Error())
}

if qms != nil {
v1 := qms.LatestVersion()
if app.qms != nil {
v1 := app.qms.LatestVersion()
v2 := app.LastBlockHeight()
if v1 > 0 && v1 < v2 {
// try to prevent gap being created in versiondb
Expand Down Expand Up @@ -1197,11 +1197,19 @@ func VerifyAddressFormat(bz []byte) error {

// Close will be called in graceful shutdown in start cmd
func (app *App) Close() error {
err := app.BaseApp.Close()
errs := []error{app.BaseApp.Close()}

// flush the versiondb
if closer, ok := app.qms.(io.Closer); ok {
errs = append(errs, closer.Close())
}

if cms, ok := app.CommitMultiStore().(*memiavlrootmulti.Store); ok {
return stderrors.Join(err, cms.Close())
// mainly to flush memiavl
if closer, ok := app.CommitMultiStore().(io.Closer); ok {
errs = append(errs, closer.Close())
}

err := stderrors.Join(errs...)
app.Logger().Info("Application gracefully shutdown", "error", err)
return err
}
5 changes: 5 additions & 0 deletions versiondb/multistore.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,8 @@
}
return version
}

// Close will flush the versiondb
func (s *MultiStore) Close() error {
return s.versionDB.Flush()

Check warning on line 151 in versiondb/multistore.go

View check run for this annotation

Codecov / codecov/patch

versiondb/multistore.go#L150-L151

Added lines #L150 - L151 were not covered by tests
}
10 changes: 10 additions & 0 deletions versiondb/tsrocksdb/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@
return s.SetLatestVersion(version)
}

func (s Store) Flush() error {
opts := grocksdb.NewDefaultFlushOptions()
defer opts.Destroy()

Check warning on line 210 in versiondb/tsrocksdb/store.go

View check run for this annotation

Codecov / codecov/patch

versiondb/tsrocksdb/store.go#L208-L210

Added lines #L208 - L210 were not covered by tests

return errors.Join(
s.db.Flush(opts),
s.db.FlushCF(s.cfHandle, opts),
)

Check warning on line 215 in versiondb/tsrocksdb/store.go

View check run for this annotation

Codecov / codecov/patch

versiondb/tsrocksdb/store.go#L212-L215

Added lines #L212 - L215 were not covered by tests
}

func newTSReadOptions(version *int64) *grocksdb.ReadOptions {
var ver uint64
if version == nil {
Expand Down
4 changes: 4 additions & 0 deletions versiondb/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ type VersionStore interface {

// Import the initial state of the store
Import(version int64, ch <-chan ImportEntry) error

// Flush wal logs, and make the changes persistent,
// mainly for rocksdb version upgrade, sometimes the wal format is not compatible.
Flush() error
}

type ImportEntry struct {
Expand Down
Loading