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

Fix load version for export genesis #64

Merged
merged 9 commits into from
May 16, 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
16 changes: 12 additions & 4 deletions sc/memiavl/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ func OpenDB(logger logger.Logger, targetVersion int64, opts Options) (*DB, error
return nil, errorutils.Join(err, db.Close())
}
}
if db.streamHandler == nil {
fmt.Println("[Debug] DB steam handler is nil??")
}
return db, nil
}

Expand Down Expand Up @@ -613,10 +616,16 @@ func (db *DB) rewriteSnapshotBackground() error {
func (db *DB) Close() error {
db.mtx.Lock()
defer db.mtx.Unlock()
errs := []error{}

errs := []error{
db.streamHandler.Close(),
// Close stream handler
if db.streamHandler != nil {
err := db.streamHandler.Close()
errs = append(errs, err)
db.streamHandler = nil
}

// Close rewrite channel
if db.snapshotRewriteChan != nil {
db.snapshotRewriteCancelFunc()
<-db.snapshotRewriteChan
Expand All @@ -626,8 +635,7 @@ func (db *DB) Close() error {

errs = append(errs, db.MultiTree.Close())

db.streamHandler = nil

// Close file lock
if db.fileLock != nil {
errs = append(errs, db.fileLock.Unlock())
errs = append(errs, db.fileLock.Destroy())
Expand Down
35 changes: 18 additions & 17 deletions sc/store.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package sc

import (
"fmt"

"github.com/sei-protocol/sei-db/common/logger"
"github.com/sei-protocol/sei-db/common/utils"
"github.com/sei-protocol/sei-db/config"
Expand Down Expand Up @@ -39,15 +41,8 @@ func NewCommitStore(homeDir string, logger logger.Logger, config config.StateCom
return commitStore
}

func (cs *CommitStore) Initialize(initialStores []string) error {
options := cs.opts
options.InitialStores = initialStores
db, err := memiavl.OpenDB(cs.logger, 0, options)
if err != nil {
return err
}
cs.db = db
return nil
func (cs *CommitStore) Initialize(initialStores []string) {
cs.opts.InitialStores = initialStores
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there any instances where we initialize but don't call loadversion where we might need to explicitly openDB?

Copy link
Collaborator Author

@yzang2019 yzang2019 May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, just checked sei-cosmos code

}

func (cs *CommitStore) SetInitialVersion(initialVersion int64) error {
Expand All @@ -70,22 +65,28 @@ func (cs *CommitStore) Rollback(targetVersion int64) error {

// copyExisting is for creating new memiavl object given existing folder
func (cs *CommitStore) LoadVersion(targetVersion int64, copyExisting bool) (types.Committer, error) {
opts := cs.opts
opts.ReadOnly = copyExisting
cs.logger.Info(fmt.Sprintf("SeiDB load target memIAVL version %d, copyExisting = %v\n", targetVersion, copyExisting))
if copyExisting {
opts := cs.opts
opts.ReadOnly = copyExisting
opts.CreateIfMissing = false
}
db, err := memiavl.OpenDB(cs.logger, targetVersion, opts)
if err != nil {
return nil, err
}
if copyExisting {
db, err := memiavl.OpenDB(cs.logger, targetVersion, opts)
if err != nil {
return nil, err
}
return &CommitStore{
logger: cs.logger,
db: db,
opts: opts,
}, nil
}
if cs.db != nil {
cs.db.Close()
}
db, err := memiavl.OpenDB(cs.logger, targetVersion, cs.opts)
if err != nil {
return nil, err
}
cs.db = db
return cs, nil
}
Expand Down
2 changes: 1 addition & 1 deletion sc/types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type Committer interface {
Initialize(initialStores []string) error
Initialize(initialStores []string)

Commit() (int64, error)

Expand Down
Loading