Skip to content

Commit

Permalink
fix(store/v2): using defer to ensure close db handle (#20871)
Browse files Browse the repository at this point in the history
  • Loading branch information
yukionfire authored Jul 17, 2024
1 parent 49bc189 commit 7d2a6b9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions store/v2/commitment/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,19 @@ func (m *MetadataStore) GetCommitInfo(version uint64) (*proof.CommitInfo, error)
return cInfo, nil
}

func (m *MetadataStore) flushCommitInfo(version uint64, cInfo *proof.CommitInfo) error {
func (m *MetadataStore) flushCommitInfo(version uint64, cInfo *proof.CommitInfo) (err error) {
// do nothing if commit info is nil, as will be the case for an empty, initializing store
if cInfo == nil {
return nil
}

batch := m.kv.NewBatch()
defer func() {
cErr := batch.Close()
if err == nil {
err = cErr
}
}()
cInfoKey := []byte(fmt.Sprintf(commitInfoKeyFmt, version))
value, err := cInfo.Marshal()
if err != nil {
Expand All @@ -87,7 +93,7 @@ func (m *MetadataStore) flushCommitInfo(version uint64, cInfo *proof.CommitInfo)
if err := batch.WriteSync(); err != nil {
return err
}
return batch.Close()
return nil
}

func (m *MetadataStore) deleteCommitInfo(version uint64) error {
Expand Down

0 comments on commit 7d2a6b9

Please sign in to comment.