fix(store/v2): using defer to ensure close db handle (#20871)

This commit is contained in:
yukionfire 2024-07-17 23:11:37 +08:00 committed by GitHub
parent 49bc189df1
commit 7d2a6b99e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 {
@ -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 {