-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Updated CompositeByteBuf to be responsible for retaining its ByteBufs #1825
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
base: main
Are you sure you want to change the base?
Conversation
* Updated NettyByteBuf so that it does its own reference counting as the internals of Netty can also retain and release the netty ByteBuf implementation. * Updated CommandMessage as CompositeByteBuf handles the releasing of its ByteBufs * Migrated CompositeByteBufSpecification to JUnit 5 and added extra test cases with mixed ByteBuf types not just NIO ones. * Added recording to CommandHelperSpecification as this caught the initial use of Netty doing its own accounting on its ByteBuf implementations. JAVA-5982
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates CompositeByteBuf to take responsibility for managing the reference counting lifecycle of its constituent ByteBuf components, rather than relying on external callers to handle this.
- Updated
NettyByteBufto maintain its own reference count separate from the underlying Netty buffer - Modified
CompositeByteBufto retain/release component buffers during its own lifecycle management - Migrated test suite from Groovy/Spock to JUnit 5 with enhanced coverage for mixed buffer types
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| CompositeByteBufTest.java | New JUnit 5 test suite with parameterized tests for ByteBufNIO, NettyByteBuf, and mixed buffer scenarios |
| CompositeByteBufSpecification.groovy | Removed legacy Groovy/Spock test file being replaced by JUnit 5 version |
| CommandHelperSpecification.groovy | Added recording configuration to enable proper implementation logging |
| NettyByteBuf.java | Implemented independent reference counting with AtomicInteger to track buffer lifecycle |
| CompositeByteBuf.java | Updated to retain/release component buffers and duplicate them properly in copy constructor |
| CommandMessage.java | Simplified buffer management by removing manual release of byte buffers |
Comments suppressed due to low confidence (2)
driver-core/src/test/unit/com/mongodb/internal/connection/CompositeByteBufTest.java:1
- The comment in line 246 says 'accross' but should be 'across'.
/*
driver-core/src/test/unit/com/mongodb/internal/connection/CompositeByteBufTest.java:1
- The comment in line 280 says 'accross' but should be 'across'.
/*
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
driver-core/src/main/com/mongodb/internal/connection/CompositeByteBuf.java
Outdated
Show resolved
Hide resolved
…ByteBuf.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Assigned |
|
I am still reviewing the PR. Despite the changes in the PR being deceivingly small, they should not be taken lightly. The way reference counting is done in our codebase is notoriously bad, and caused many difficulties maintaining the codebase in the past. The main reason is, of course, the lack of the language mechanisms in Java that would have allowed us to implement reference-counting in a robust way (Rust with its ownership, ownership transfer and borrowing allows for robust reference counting). |
JAVA-5982