Skip to content

Commit

Permalink
Issue 4200: fix flaky test DeferredSyncTest.testForceWillAdvanceLacOn…
Browse files Browse the repository at this point in the history
…lyUpToLastAcknoledgedWrite (#4234)

* Issue 4200: fix flaky test DeferredSyncTest.testForceWillAdvanceLacOnlyUpToLastAcknoledgedWrite

* add a comment
  • Loading branch information
tmzk1005 committed Mar 21, 2024
1 parent 47bf54d commit 37708ad
Showing 1 changed file with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,15 @@ protected void suspendBookieForceLedgerAcks(BookieId address) {
}

protected void resumeBookieWriteAcks(BookieId address) {
suspendedBookiesForForceLedgerAcks.remove(address);
List<Runnable> pendingResponses = deferredBookieForceLedgerResponses.remove(address);
List<Runnable> pendingResponses;

// why use the BookieId instance as the object monitor? there is a date race problem if not
// see https://github.com/apache/bookkeeper/issues/4200
synchronized (address) {
suspendedBookiesForForceLedgerAcks.remove(address);
pendingResponses = deferredBookieForceLedgerResponses.remove(address);
}

if (pendingResponses != null) {
pendingResponses.forEach(Runnable::run);
}
Expand Down Expand Up @@ -656,11 +663,17 @@ protected void setupBookieClientForceLedger() {
callback.forceLedgerComplete(BKException.Code.OK, ledgerId, bookieSocketAddress, ctx);
});
};
if (suspendedBookiesForForceLedgerAcks.contains(bookieSocketAddress)) {
List<Runnable> queue = deferredBookieForceLedgerResponses.computeIfAbsent(bookieSocketAddress,
(k) -> new CopyOnWriteArrayList<>());
queue.add(activity);
} else {
List<Runnable> queue = null;

synchronized (bookieSocketAddress) {
if (suspendedBookiesForForceLedgerAcks.contains(bookieSocketAddress)) {
queue = deferredBookieForceLedgerResponses.computeIfAbsent(bookieSocketAddress,
(k) -> new CopyOnWriteArrayList<>());
queue.add(activity);
}
}

if (queue == null) {
activity.run();
}
return null;
Expand Down

0 comments on commit 37708ad

Please sign in to comment.