Skip to content

Commit

Permalink
factor out defer logic to avoid further bugs
Browse files Browse the repository at this point in the history
Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun committed Sep 27, 2022
1 parent 747086f commit f7f4634
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,15 @@ public void scheduleNow() {
@Override
public void run() {
phaser.register();
if (closed) {
try {
internalRun();
} finally {
phaser.arriveAndDeregister();
}
}

private void internalRun() {
if (closed) {
return;
}
// if not in flushing state, do flush, else return;
Expand All @@ -250,7 +257,6 @@ public void run() {
log.debug("Starting flush, queue size: {}", incomingList.size());
}
if (!swapList.isEmpty()) {
phaser.arriveAndDeregister();
throw new IllegalStateException("swapList should be empty since last flush. swapList.size: "
+ swapList.size());
}
Expand Down Expand Up @@ -303,7 +309,6 @@ public void run() {
connection.rollback();
}
} catch (Exception ex) {
phaser.arriveAndDeregister();
throw new RuntimeException(ex);
}
}
Expand All @@ -323,7 +328,6 @@ public void run() {
log.debug("Already in flushing state, will not flush, queue size: {}", incomingList.size());
}
}
phaser.arriveAndDeregister();
}

@Override
Expand Down

0 comments on commit f7f4634

Please sign in to comment.