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

fix mpool leak in txn.WriteBatch #14220

Merged
merged 2 commits into from
Jan 16, 2024

Conversation

ouyuanning
Copy link
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #14080

What this PR does / why we need it:

fix mpool leak in txn.WriteBatch

@matrix-meow matrix-meow added the size/S Denotes a PR that changes [10,99] lines label Jan 16, 2024
@mergify mergify bot added the kind/bug Something isn't working label Jan 16, 2024
@matrix-meow
Copy link
Contributor

@ouyuanning Thanks for your contributions!

Review:

Title: fix mpool leak in txn.WriteBatch

Body: This pull request fixes a memory pool (mpool) leak in the txn.WriteBatch function.

Changes:

  1. In engine.go, the Clean method is called on the bat object using txn.proc.Mp() instead of e.mp in the Create and Delete functions.
  2. In txn_database.go, the Clean method is called on the bat object using db.txn.proc.Mp() instead of db.txn.engine.mp in the Delete, Truncate, Create, and AlterTable functions.
  3. In txn_table.go, the Clean method is called on the bat object using tbl.db.txn.proc.Mp() instead of tbl.db.txn.engine.mp in the UpdateConstraint, AlterTable, Write, and writeTnPartition functions.
  4. In types.go, the Clean method is called on the bat object using txn.proc.Mp() instead of txn.engine.mp in the RollbackLastStatement function.

Problem 1: Memory Pool Leak
In the engine.go file, the bat.Clean method is called using txn.proc.Mp() instead of e.mp in the Create and Delete functions. This can lead to a memory pool leak if the bat object is not properly cleaned up.

Solution 1: Use the Correct Memory Pool
To fix this issue, the bat.Clean method should be called using e.mp instead of txn.proc.Mp() in the Create and Delete functions.

Problem 2: Memory Pool Leak
In the txn_database.go file, the bat.Clean method is called using db.txn.proc.Mp() instead of db.txn.engine.mp in the Delete, Truncate, Create, and AlterTable functions. This can lead to a memory pool leak if the bat object is not properly cleaned up.

Solution 2: Use the Correct Memory Pool
To fix this issue, the bat.Clean method should be called using db.txn.engine.mp instead of db.txn.proc.Mp() in the Delete, Truncate, Create, and AlterTable functions.

Problem 3: Memory Pool Leak
In the txn_table.go file, the bat.Clean method is called using tbl.db.txn.proc.Mp() instead of tbl.db.txn.engine.mp in the UpdateConstraint, AlterTable, Write, and writeTnPartition functions. This can lead to a memory pool leak if the bat object is not properly cleaned up.

Solution 3: Use the Correct Memory Pool
To fix this issue, the bat.Clean method should be called using tbl.db.txn.engine.mp instead of tbl.db.txn.proc.Mp() in the UpdateConstraint, AlterTable, Write, and writeTnPartition functions.

Problem 4: Memory Pool Leak
In the types.go file, the bat.Clean method is called using txn.proc.Mp() instead of txn.engine.mp in the RollbackLastStatement function. This can lead to a memory pool leak if the bat object is not properly cleaned up.

Solution 4: Use the Correct Memory Pool
To fix this issue, the bat.Clean method should be called using txn.engine.mp instead of txn.proc.Mp() in the RollbackLastStatement function.

Optimization Suggestions:

  • It would be helpful to add comments explaining the purpose of the changes made in each function.
  • Consider using more descriptive variable names to improve code readability.
  • It may be beneficial to refactor the code to reduce code duplication and improve maintainability.

Overall, this pull request addresses a memory pool leak issue in the txn.WriteBatch function. The suggested changes involve using the correct memory pool and adding comments for clarity. Additionally, optimizing the code by refactoring and using descriptive variable names can improve the quality and readability of the codebase.

@mergify mergify bot merged commit 2b8dde0 into matrixorigin:main Jan 16, 2024
17 of 18 checks passed
ouyuanning added a commit to ouyuanning/matrixone that referenced this pull request Jan 17, 2024
fix mpool leak in txn.WriteBatch

Approved by: @nnsgmsone
mergify bot pushed a commit that referenced this pull request Jan 17, 2024
fix mpool leak in txn.WriteBatch

Approved by: @nnsgmsone, @sukki37
@ouyuanning ouyuanning deleted the fix-mpool-leak-14080 branch February 22, 2024 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working size/S Denotes a PR that changes [10,99] lines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants