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

 ##########
 File path: 
bookkeeper-server/src/main/java/org/apache/bookkeeper/client/PendingAddOp.java
 ##########
 @@ -183,31 +211,42 @@ void unsetSuccessAndSendWriteRequest(int bookieIndex) {
         sendWriteRequest(bookieIndex);
     }
 
-    void initiate(ByteBuf toSend, int entryLength) {
+    /**
+     * Initiate the add operation
+     */
+    public void safeRun() {
+        hasRun = true;
         if (callbackTriggered) {
-            // this should only be true if the request was failed due to 
another request ahead in the pending queue,
+            // this should only be true if the request was failed due
+            // to another request ahead in the pending queue,
             // so we can just ignore this request
+            maybeRecycle();
             return;
         }
 
         if (timeoutSec > -1) {
-            this.timeout = lh.bk.getBookieClient().scheduleTimeout(this, 
timeoutSec, TimeUnit.SECONDS);
+            this.timeout = lh.bk.getBookieClient().scheduleTimeout(
+                    this, timeoutSec, TimeUnit.SECONDS);
         }
+
         this.requestTimeNanos = MathUtils.nowInNano();
-        this.toSend = toSend;
-        // Retain the buffer until all writes are complete
-        this.toSend.retain();
-        this.entryLength = entryLength;
+        checkNotNull(lh);
+        checkNotNull(lh.macManager);
+
+        this.toSend = lh.macManager.computeDigestAndPackageForSending(
+                entryId, lh.lastAddConfirmed, currentLedgerLength,
+                payload);
 
         // Iterate over set and trigger the sendWriteRequests
-        for (int i = 0; i < writeSet.length; i++) {
+        for (int i = 0; i < writeQuorumSize; i++) {
             sendWriteRequest(writeSet[i]);
         }
     }
 
     @Override
     public void writeComplete(int rc, long ledgerId, long entryId, 
BookieSocketAddress addr, Object ctx) {
         int bookieIndex = (Integer) ctx;
+        --pendingWriteRequests;
 
 Review comment:
   @ivankelly we can do such things without "synchronized" because we are now 
using OrderedSafeExecution in a way that there is no concurrent operation ?

----------------------------------------------------------------
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