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 apache#1598 from ivankelly/double-rel-mock
  • Loading branch information
ivankelly authored and eolivelli committed Sep 5, 2018
1 parent 4c7083c commit 0040bbd
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 0040bbd

Please sign in to comment.