From 037856ebceca196b5251c175a8cb37bba8d4805a Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Sun, 9 Jun 2024 10:30:27 +0700 Subject: [PATCH 1/2] refactor: add miss defer --- store/v2/commitment/store.go | 3 +++ store/v2/migration/manager.go | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/store/v2/commitment/store.go b/store/v2/commitment/store.go index b67a1149c311..df76f67dac9a 100644 --- a/store/v2/commitment/store.go +++ b/store/v2/commitment/store.go @@ -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 for version := latestVersion; version > targetVersion; version-- { cInfoKey := []byte(fmt.Sprintf(commitInfoKeyFmt, version)) if err := batch.Delete(cInfoKey); err != nil { @@ -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 { @@ -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 { diff --git a/store/v2/migration/manager.go b/store/v2/migration/manager.go index 3dc3ef80e5da..bd636dc3c600 100644 --- a/store/v2/migration/manager.go +++ b/store/v2/migration/manager.go @@ -197,7 +197,6 @@ func (m *Manager) writeChangeset() error { if err != nil { return err } - batch.Close() } return nil From 7c3d613134e084c49e70683bf0f0dc9623ee243c Mon Sep 17 00:00:00 2001 From: Khanh Hoa Date: Mon, 10 Jun 2024 15:48:03 +0700 Subject: [PATCH 2/2] remove code comments --- store/v2/commitment/store.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/store/v2/commitment/store.go b/store/v2/commitment/store.go index df76f67dac9a..4a93dc823d54 100644 --- a/store/v2/commitment/store.go +++ b/store/v2/commitment/store.go @@ -134,7 +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 + defer batch.Close() for version := latestVersion; version > targetVersion; version-- { cInfoKey := []byte(fmt.Sprintf(commitInfoKeyFmt, version)) if err := batch.Delete(cInfoKey); err != nil { @@ -187,7 +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. + defer batch.Close() cInfoKey := []byte(fmt.Sprintf(commitInfoKeyFmt, version)) value, err := cInfo.Marshal() if err != nil { @@ -308,7 +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. + defer batch.Close() for v := version; v > 0; v-- { cInfoKey := []byte(fmt.Sprintf(commitInfoKeyFmt, v)) if exist, _ := c.db.Has(cInfoKey); !exist {