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): add miss defer #20602

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions store/v2/commitment/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func (c *CommitStore) LoadVersion(targetVersion uint64) error {
}
if targetVersion < latestVersion {
batch := c.db.NewBatch()
defer batch.Close() // Ensure the batch is closed on function exit
hoank101 marked this conversation as resolved.
Show resolved Hide resolved
for version := latestVersion; version > targetVersion; version-- {
cInfoKey := []byte(fmt.Sprintf(commitInfoKeyFmt, version))
if err := batch.Delete(cInfoKey); err != nil {
Expand Down Expand Up @@ -186,6 +187,7 @@ func (c *CommitStore) flushCommitInfo(version uint64, cInfo *proof.CommitInfo) e
}

batch := c.db.NewBatch()
defer batch.Close() // Ensure the batch is closed on function exit.
cInfoKey := []byte(fmt.Sprintf(commitInfoKeyFmt, version))
value, err := cInfo.Marshal()
if err != nil {
Expand Down Expand Up @@ -306,6 +308,7 @@ func (c *CommitStore) Get(storeKey []byte, version uint64, key []byte) ([]byte,
func (c *CommitStore) Prune(version uint64) (ferr error) {
// prune the metadata
batch := c.db.NewBatch()
defer batch.Close() // Ensure the batch is closed on function exit.
for v := version; v > 0; v-- {
cInfoKey := []byte(fmt.Sprintf(commitInfoKeyFmt, v))
if exist, _ := c.db.Has(cInfoKey); !exist {
Expand Down
1 change: 0 additions & 1 deletion store/v2/migration/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ func (m *Manager) writeChangeset() error {
if err != nil {
return err
}
batch.Close()
}

return nil
Expand Down
Loading