eolivelli commented on a change in pull request #664: Recycle PendingAddOps
URL: https://github.com/apache/bookkeeper/pull/664#discussion_r147174104
 
 

 ##########
 File path: 
bookkeeper-server/src/main/java/org/apache/bookkeeper/client/PendingAddOp.java
 ##########
 @@ -343,4 +384,55 @@ public boolean equals(Object o) {
        return (this == o);
     }
 
+    private final Handle<PendingAddOp> recyclerHandle;
+    private static final Recycler<PendingAddOp> RECYCLER = new 
Recycler<PendingAddOp>() {
+        protected PendingAddOp newObject(Recycler.Handle<PendingAddOp> handle) 
{
+            return new PendingAddOp(handle);
+        }
+    };
+
+    private PendingAddOp(Handle<PendingAddOp> recyclerHandle) {
+        this.recyclerHandle = recyclerHandle;
+    }
+
+    private void maybeRecycle() {
+        // The reference to PendingAddOp can be held in 3 places
+        // - LedgerHandle#pendingAddOp
+        //   This reference is released when the callback is run
+        // - The executor
+        //   Released after safeRun finishes
+        // - BookieClient
+        //   Holds a reference from the point the addEntry requests are
+        //   sent.
+        // The object can only be recycled after all references are
+        // released, otherwise we could end up recycling twice and all
+        // joy that goes along with that.
+        if (hasRun && callbackTriggered && pendingWriteRequests == 0) {
+            recycle();
+        }
+    }
+
+    private void recycle() {
 
 Review comment:
   don't we reset writeSet ?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to