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

Conversation

hoank101
Copy link
Contributor

@hoank101 hoank101 commented Jun 9, 2024

Description

Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • Bug Fixes
    • Ensured proper resource management by adding automatic batch closure in key functions to prevent potential resource leaks.

@hoank101 hoank101 requested a review from a team as a code owner June 9, 2024 03:32
Copy link
Contributor

coderabbitai bot commented Jun 9, 2024

Walkthrough

Walkthrough

The recent changes focus on ensuring proper resource management in the store/v2/commitment/store.go and store/v2/migration/manager.go files. Specifically, defer batch.Close() statements were added to three functions in store.go to ensure batches are closed properly. Conversely, a batch.Close() call was removed from the writeChangeset method in manager.go.

Changes

File Change Summary
store/v2/commitment/store.go Added defer batch.Close() in LoadVersion, flushCommitInfo, and Prune to ensure proper batch closure.
store/v2/migration/manager.go Removed batch.Close() call in the writeChangeset method of the Manager struct.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@hoank101 hoank101 changed the title refactor: add miss defer refactor(store): add miss defer Jun 9, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (9)
store/v2/migration/manager.go (2)

Line range hint 98-98: Undefined function NewMigrationStream used.

Please ensure that the function NewMigrationStream is defined or imported correctly. If it's supposed to be part of another package, you might need to import that package or define the function.


Line range hint 118-118: Unused variable storeKey.

The variable storeKey is declared but not used within the function. Consider removing it or using it as intended to avoid cluttering the codebase with unused variables.

store/v2/commitment/store.go (7)

Line range hint 42-42: Undefined type Tree.

The type Tree is used but not defined or imported in this file. Ensure that you have the correct imports or definitions in place for Tree.


Line range hint 29-29: Undefined package store.

The package store is referenced but not imported. Ensure that the correct package is imported to resolve the store.Committer and other interfaces.

Also applies to: 31-31


Line range hint 46-46: Undefined type Tree in constructor.

The constructor NewCommitStore uses the type Tree which is not defined or imported. Please define or import it to ensure the constructor works as intended.


Line range hint 379-379: Undefined error ErrorExportDone.

The error ErrorExportDone is used but not defined or imported. Ensure that this error is correctly defined or imported from the appropriate package.


Line range hint 411-411: Undefined type Importer.

The type Importer is used but not defined or imported in this file. Ensure that you have the correct imports or definitions in place for Importer.


Line range hint 413-413: Unused variable storeKey.

The variable storeKey is declared but not used within the function. Consider removing it or using it as intended to avoid cluttering the codebase with unused variables.


Line range hint 8-8: Unused import math.

The math package is imported but not used in this file. Consider removing the import to clean up the code.

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ca14b28 and 037856e.

Files selected for processing (2)
  • store/v2/commitment/store.go (3 hunks)
  • store/v2/migration/manager.go (1 hunks)
Additional context used
Path-based instructions (2)
store/v2/migration/manager.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

store/v2/commitment/store.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

golangci-lint
store/v2/migration/manager.go

98-98: undefined: NewMigrationStream (typecheck)


118-118: storeKey declared and not used (typecheck)

store/v2/commitment/store.go

42-42: undefined: Tree (typecheck)


29-29: undefined: store (typecheck)


31-31: undefined: store (typecheck)


46-46: undefined: Tree (typecheck)


379-379: undefined: ErrorExportDone (typecheck)


411-411: undefined: Importer (typecheck)


413-413: storeKey declared and not used (typecheck)


8-8: "math" imported and not used (typecheck)

Copy link
Contributor

@alpe alpe left a comment

Choose a reason for hiding this comment

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

Nice work! 🏅

store/v2/commitment/store.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 037856e and e198b46.

Files selected for processing (1)
  • store/v2/commitment/store.go (3 hunks)
Additional context used
Path-based instructions (1)
store/v2/commitment/store.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

Additional comments not posted (3)
store/v2/commitment/store.go (3)

137-137: Ensure proper resource management by adding defer batch.Close().

This addition follows best practices for handling resources in Go, ensuring that the batch is closed properly, preventing potential resource leaks.


190-190: Proper use of defer to ensure resources are cleaned up.

Adding defer batch.Close() in flushCommitInfo method is a good practice to prevent resource leaks.


311-311: Correct application of defer for resource management.

The addition of defer batch.Close() in the Prune method ensures that resources are properly managed and potential leaks are prevented.

@tac0turtle tac0turtle added this pull request to the merge queue Jun 11, 2024
Merged via the queue into cosmos:main with commit 4fa658e Jun 11, 2024
65 of 67 checks passed
alpe added a commit that referenced this pull request Jun 12, 2024
* main:
  refactor(x/auth): Fix system test (#20531)
  feat(crypto): add blst (#20296)
  docs: Update high level overview and introduction (#20535)
  refactor(x/core): remove test (#20624)
  feat(x/mint)!: Replace InflationCalculationFn with MintFn + simple epoch minting (#20363)
  docs: remove duplicate words (#20622)
  feat: prep for errors v2 (#20539)
  chore: reduce default inflation (#20606)
  refactor(store): add miss defer (#20602)
  chore: use comet api pkg instead of comet alias (#20614)
  chore: write gentx info to cmd.ErrOrStderr (#20616)
  docs: ADR 073: update to accepted and add to README.md (#20619)
  chore(proto): change future extracted modules version from v1.0.0 to v0.2.0 (#20600)
  fix: remove some duplicate words (#20605)
  feat(stf): port simappv2 changes (#20587)
  chore: bring patch changelogs to main (#20599)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants