smengcl commented on code in PR #5900:
URL: https://github.com/apache/ozone/pull/5900#discussion_r1446991823
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerDoubleBuffer.java:
##########
@@ -649,29 +649,57 @@ void resume() {
isRunning.set(true);
}
+ CompletableFuture<Integer> awaitFlushAsync() {
+ return flushNotifier.await();
+ }
+
public void awaitFlush() throws InterruptedException {
- flushNotifier.await();
+ try {
+ awaitFlushAsync().get();
+ } catch (ExecutionException e) {
+ // the future will never be completed exceptionally.
+ throw new IllegalStateException(e);
+ }
}
static class FlushNotifier {
- private final Set<CountDownLatch> flushLatches =
- ConcurrentHashMap.newKeySet();
+ static class Entry {
+ private final CompletableFuture<Integer> future = new
CompletableFuture<>();
+ private int count;
- void await() throws InterruptedException {
+ private CompletableFuture<Integer> await() {
+ count++;
+ return future;
+ }
- // Wait until both the current and ready buffers are flushed.
- CountDownLatch latch = new CountDownLatch(2);
- flushLatches.add(latch);
- latch.await();
- flushLatches.remove(latch);
+ private int complete() {
+ Preconditions.checkState(future.complete(count));
Review Comment:
Thanks @szetszwo !
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]