You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by iv...@apache.org on 2018/08/13 08:39:43 UTC

[bookkeeper] branch master updated: Avoid releasing sent buffer to early in BookieClient mock

This is an automated email from the ASF dual-hosted git repository.

ivank pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 6b9cbf2  Avoid releasing sent buffer to early in BookieClient mock
6b9cbf2 is described below

commit 6b9cbf2052b27f331553f2738483ae21bf12b49c
Author: Ivan Kelly <iv...@apache.org>
AuthorDate: Mon Aug 13 10:39:36 2018 +0200

    Avoid releasing sent buffer to early in BookieClient mock
    
    If the buffer was sent to more than one bookie with the mock, it would
    be released after being sent to the first one. Each write should
    retain a refCount themselves, and then release when done.
    
    Author: Ivan Kelly <iv...@apache.org>
    
    Reviewers: Sijie Guo <si...@apache.org>
    
    This closes #1598 from ivankelly/double-rel-mock
---
 .../java/org/apache/bookkeeper/client/MockBookKeeperTestCase.java     | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/MockBookKeeperTestCase.java b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/MockBookKeeperTestCase.java
index 6e1557a..20a8bb8 100644
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/MockBookKeeperTestCase.java
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/client/MockBookKeeperTestCase.java
@@ -511,6 +511,7 @@ public abstract class MockBookKeeperTestCase {
             boolean isRecoveryAdd =
                 ((short) options & BookieProtocol.FLAG_RECOVERY_ADD) == BookieProtocol.FLAG_RECOVERY_ADD;
 
+            toSend.retain();
             executor.executeOrdered(ledgerId, () -> {
                 byte[] entry;
                 try {
@@ -518,6 +519,7 @@ public abstract class MockBookKeeperTestCase {
                 } catch (BKDigestMatchException e) {
                     callback.writeComplete(Code.DigestMatchException,
                             ledgerId, entryId, bookieSocketAddress, ctx);
+                    toSend.release();
                     return;
                 }
                 boolean fenced = fencedLedgers.contains(ledgerId);
@@ -528,6 +530,7 @@ public abstract class MockBookKeeperTestCase {
                     if (failedBookies.contains(bookieSocketAddress)) {
                         callback.writeComplete(NoBookieAvailableException,
                                 ledgerId, entryId, bookieSocketAddress, ctx);
+                        toSend.release();
                         return;
                     }
                     if (getMockLedgerContentsInBookie(ledgerId, bookieSocketAddress).isEmpty()) {
@@ -538,6 +541,7 @@ public abstract class MockBookKeeperTestCase {
                     callback.writeComplete(BKException.Code.OK,
                             ledgerId, entryId, bookieSocketAddress, ctx);
                 }
+                toSend.release();
             });
 
             return null;