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

refactor(store): keep batch.Close error handle logic consistance #21812

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,9 @@ func (rs *Store) flushMetadata(db corestore.KVStoreWithBatch, version int64, cIn
rs.logger.Debug("flushing metadata", "height", version)
batch := db.NewBatch()
defer func() {
_ = batch.Close()
if err := batch.Close(); err != nil {
rs.logger.Error("call flushMetadata error on batch close", "err", err)
}
}()

if cInfo != nil {
Expand Down
5 changes: 3 additions & 2 deletions store/v2/commitment/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ func (m *MetadataStore) deleteRemovedStoreKeys(version uint64, removeStore func(

batch := m.kv.NewBatch()
defer func() {
if berr := batch.Close(); berr != nil {
err = berr
cErr := batch.Close()
Copy link
Member

Choose a reason for hiding this comment

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

these are functionally identical, why the change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If batch.Write() returns error and batch.Close() returns error too, the error returned by batch.Write would be covered.

This change just keeps consistant with others: The error returned by batch.Close should be returned when original err is nil

Copy link
Member

Choose a reason for hiding this comment

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

We should errors.Join them then to not lose any error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@julienrbrt Hi sir, I have changed to use errors.Join now, thanks for your review

if err == nil {
err = cErr
}
}()
for _, storeKey := range removedStoreKeys {
Expand Down
Loading