Skip to content

Commit

Permalink
Avoid releasing sent buffer to early in BookieClient mock
Browse files Browse the repository at this point in the history
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 <ivank@apache.org>

Reviewers: Sijie Guo <sijie@apache.org>

This closes #1598 from ivankelly/double-rel-mock
  • Loading branch information
ivankelly committed Aug 13, 2018
1 parent 269f609 commit 6b9cbf2
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -511,13 +511,15 @@ protected void setupBookieClientAddEntry() {
boolean isRecoveryAdd =
((short) options & BookieProtocol.FLAG_RECOVERY_ADD) == BookieProtocol.FLAG_RECOVERY_ADD;

toSend.retain();
executor.executeOrdered(ledgerId, () -> {
byte[] entry;
try {
entry = extractEntryPayload(ledgerId, entryId, toSend);
} catch (BKDigestMatchException e) {
callback.writeComplete(Code.DigestMatchException,
ledgerId, entryId, bookieSocketAddress, ctx);
toSend.release();
return;
}
boolean fenced = fencedLedgers.contains(ledgerId);
Expand All @@ -528,6 +530,7 @@ protected void setupBookieClientAddEntry() {
if (failedBookies.contains(bookieSocketAddress)) {
callback.writeComplete(NoBookieAvailableException,
ledgerId, entryId, bookieSocketAddress, ctx);
toSend.release();
return;
}
if (getMockLedgerContentsInBookie(ledgerId, bookieSocketAddress).isEmpty()) {
Expand All @@ -538,6 +541,7 @@ protected void setupBookieClientAddEntry() {
callback.writeComplete(BKException.Code.OK,
ledgerId, entryId, bookieSocketAddress, ctx);
}
toSend.release();
});

return null;
Expand Down

0 comments on commit 6b9cbf2

Please sign in to comment.