smengcl commented on code in PR #6413:
URL: https://github.com/apache/ozone/pull/6413#discussion_r1560113190


##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BufferPool.java:
##########
@@ -79,76 +83,88 @@ ChunkBuffer getCurrentBuffer() {
    * less than the capacity to be allocated, just allocate a buffer of size
    * chunk size.
    */
-  public ChunkBuffer allocateBuffer(int increment) {
+  public synchronized ChunkBuffer allocateBuffer(int increment) {
     final int nextBufferIndex = currentBufferIndex + 1;
 
     Preconditions.assertTrue(nextBufferIndex < capacity, () ->
         "next index: " + nextBufferIndex + " >= capacity: " + capacity);
 
     currentBufferIndex = nextBufferIndex;
 
+    LOG.warn("!! allocateBuffer(increment = {}): " +
+            "capacity = {}, currentBufferIndex = {}, nextBufferIndex = {}, 
bufferList.size() = {}",
+        increment,
+        capacity, currentBufferIndex, nextBufferIndex, bufferList.size());
+
     if (currentBufferIndex < bufferList.size()) {
       return getBuffer(currentBufferIndex);
     } else {
       final ChunkBuffer newBuffer = ChunkBuffer.allocate(bufferSize, 
increment);
+      LOG.warn("!! allocateBuffer(): ChunkBuffer allocated: {}", newBuffer);
       bufferList.add(newBuffer);
       return newBuffer;
     }
   }
 
-  void releaseBuffer(ChunkBuffer chunkBuffer) {
+  synchronized void releaseBuffer(ChunkBuffer chunkBuffer) {
+    LOG.warn("!! releaseBuffer(chunkBuffer = {}):" +
+            "currentBufferIndex = {}, bufferList.indexOf(chunkBuffer) = {}",
+        chunkBuffer,
+        currentBufferIndex, bufferList.indexOf(chunkBuffer));
+
     Preconditions.assertTrue(!bufferList.isEmpty(), "empty buffer list");
-    Preconditions.assertSame(bufferList.get(0), chunkBuffer,
-        "only the first buffer can be released");
+//    Preconditions.assertSame(bufferList.get(0), chunkBuffer,
+//        "only the first buffer can be released");
     Preconditions.assertTrue(currentBufferIndex >= 0,
         () -> "current buffer: " + currentBufferIndex);
 
     // always remove from head of the list and append at last
-    final ChunkBuffer buffer = bufferList.remove(0);
-    buffer.clear();
-    bufferList.add(buffer);
-    currentBufferIndex--;
+    final boolean res = bufferList.remove(chunkBuffer);

Review Comment:
   This is it. `ByteBuffer`'s `equals()` doesn't check object ID but rather 
params only:
   
   <img width="604" alt="image" 
src="https://github.com/apache/ozone/assets/50227127/acea9e9a-f334-4a6a-b803-5a68624bc19e";>
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to