You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "netudima (via GitHub)" <gi...@apache.org> on 2025/07/20 13:39:23 UTC

[PR] [CASSANDRA-20753][4.0] Fix BufferPool leak in BufferPoolAllocator when a capacity needs to be extended [cassandra]

netudima opened a new pull request, #4262:
URL: https://github.com/apache/cassandra/pull/4262

   Before the fix during a capacity extension BufferPoolAllocator returned to BufferPool a sliced ByteBuffer wrapper object instead of the originally allocated one, so the ByteBuffer was not recycled by BufferPool 
   
   Adjust BufferPoolAllocatorTest to test the ByteBuf capacity extension with a real BufferPool behaviuor
   
   Patch by Dmitry Konstantinov; reviewed by TBD for CASSANDRA-20753


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] [CASSANDRA-20753][4.0] Fix BufferPool leak in BufferPoolAllocator when a capacity needs to be extended [cassandra]

Posted by "michaelsembwever (via GitHub)" <gi...@apache.org>.
michaelsembwever commented on code in PR #4262:
URL: https://github.com/apache/cassandra/pull/4262#discussion_r2281022650


##########
src/java/org/apache/cassandra/utils/memory/BufferPool.java:
##########
@@ -1613,4 +1613,30 @@ int unsafeNumChunks()
                  + (pool.chunks.chunk1 != null ? 1 : 0)
                  + (pool.chunks.chunk2 != null ? 1 : 0);
     }
+
+    /**
+     * @return the inner buffer if it has a BufferPool.Chunk attached
+     *  and originalBuffer in other cases
+     */
+    public ByteBuffer unwrapBufferPoolManagedBuffer(ByteBuffer originalBuffer)
+    {
+        int MAX_DEPTH = 32; // a protection against possible loops in attachments
+        int depth = 0;
+        ByteBuffer buffer = originalBuffer;
+        do
+        {
+            if (buffer == null || !isExactlyDirect(buffer))
+                return originalBuffer;
+            if (Chunk.getParentChunk(buffer) != null)
+                return buffer;
+
+            Object attachment = MemoryUtil.getAttachment(buffer);
+            if (!(attachment instanceof ByteBuffer))
+                return originalBuffer;

Review Comment:
   in the two places where we fallback to `return originalBuffer;` is there any difference if `originalBuffer` or the previous buffer value (not the current value of `buffer`) was returned ? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] [CASSANDRA-20753][4.0] Fix BufferPool leak in BufferPoolAllocator when a capacity needs to be extended [cassandra]

Posted by "michaelsembwever (via GitHub)" <gi...@apache.org>.
michaelsembwever commented on PR #4262:
URL: https://github.com/apache/cassandra/pull/4262#issuecomment-3194655964

   on the 5.0 patch can we run the multiplexer on the test please.
   ```
   .build/run-tests.sh -a test-t BufferPoolAllocatorTest -e REPEATED_TESTS_COUNT=1000
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] [CASSANDRA-20753][4.0] Fix BufferPool leak in BufferPoolAllocator when a capacity needs to be extended [cassandra]

Posted by "netudima (via GitHub)" <gi...@apache.org>.
netudima closed pull request #4262: [CASSANDRA-20753][4.0] Fix BufferPool leak in BufferPoolAllocator when a capacity needs to be extended
URL: https://github.com/apache/cassandra/pull/4262


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] [CASSANDRA-20753][4.0] Fix BufferPool leak in BufferPoolAllocator when a capacity needs to be extended [cassandra]

Posted by "netudima (via GitHub)" <gi...@apache.org>.
netudima commented on code in PR #4262:
URL: https://github.com/apache/cassandra/pull/4262#discussion_r2282272364


##########
src/java/org/apache/cassandra/utils/memory/BufferPool.java:
##########
@@ -1613,4 +1613,30 @@ int unsafeNumChunks()
                  + (pool.chunks.chunk1 != null ? 1 : 0)
                  + (pool.chunks.chunk2 != null ? 1 : 0);
     }
+
+    /**
+     * @return the inner buffer if it has a BufferPool.Chunk attached
+     *  and originalBuffer in other cases
+     */
+    public ByteBuffer unwrapBufferPoolManagedBuffer(ByteBuffer originalBuffer)
+    {
+        int MAX_DEPTH = 32; // a protection against possible loops in attachments
+        int depth = 0;
+        ByteBuffer buffer = originalBuffer;
+        do
+        {
+            if (buffer == null || !isExactlyDirect(buffer))
+                return originalBuffer;
+            if (Chunk.getParentChunk(buffer) != null)
+                return buffer;
+
+            Object attachment = MemoryUtil.getAttachment(buffer);
+            if (!(attachment instanceof ByteBuffer))
+                return originalBuffer;

Review Comment:
   I relied on a common sense logic here: if we get something non-expected as an input - do not modify it and return the original value (it is also a fallback to the original behaviour), it is just a safer approach by default, IMHO



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] [CASSANDRA-20753][4.0] Fix BufferPool leak in BufferPoolAllocator when a capacity needs to be extended [cassandra]

Posted by "netudima (via GitHub)" <gi...@apache.org>.
netudima commented on PR #4262:
URL: https://github.com/apache/cassandra/pull/4262#issuecomment-3196471153

   the repeated run is passed:
   ```
   failure rate: 0/1000
   Generating Test Summary for test files found under /Users/dmitry/IdeaProjects/cassandra-5.0/build/test/output
   [Test Summary] Run: 9, Failed: 0, Errors: 0, Skipped: 0
   ```
   used command:
   ```
   .build/run-tests.sh -a test-repeat -t BufferPoolAllocatorTest -e REPEATED_TESTS_COUNT=1000
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org