rohangarg commented on code in PR #13499:
URL: https://github.com/apache/druid/pull/13499#discussion_r1040068312
##########
server/src/main/java/org/apache/druid/server/coordination/ChangeRequestsSnapshot.java:
##########
@@ -43,6 +43,11 @@ public static <T> ChangeRequestsSnapshot<T> fail(String
resetCause)
return new ChangeRequestsSnapshot<>(true, resetCause, null, null);
}
+ public static <T> ChangeRequestsSnapshot<T> shutdown(String resetCause)
Review Comment:
this seems unused - did you decide to send ISE directly instead of this due
to some reason?
##########
server/src/test/java/org/apache/druid/server/coordination/ChangeRequestHistoryTest.java:
##########
@@ -171,4 +172,48 @@ public void testNonImmediateFuture() throws Exception
Assert.assertEquals(1, snapshot.getCounter().getCounter());
Assert.assertEquals(1, snapshot.getRequests().size());
}
+
+ @Test
+ public void testStop() throws ExecutionException, InterruptedException
+ {
+ final ChangeRequestHistory<DataSegmentChangeRequest> history = new
ChangeRequestHistory();
+
+ ListenableFuture<ChangeRequestsSnapshot<DataSegmentChangeRequest>> future
= history.getRequestsSince(
+ ChangeRequestHistory.Counter.ZERO
+ );
+ Assert.assertEquals(1, history.waitingFutures.size());
+
+ final AtomicBoolean callbackExcecuted = new AtomicBoolean(false);
+ Futures.addCallback(
+ future,
+ new FutureCallback<ChangeRequestsSnapshot<DataSegmentChangeRequest>>()
+ {
+ @Override
+ public void onSuccess(ChangeRequestsSnapshot result)
+ {
+ callbackExcecuted.set(true);
+ }
+
+ @Override
+ public void onFailure(Throwable t)
+ {
+ callbackExcecuted.set(true);
+ }
+ }
+ );
+
+ history.stop();
+ // any new change requests should be ignored, there should be no waiting
futures, and open futures should be resolved
+ history.addChangeRequest(new SegmentChangeRequestNoop());
+ Assert.assertEquals(0, history.waitingFutures.size());
+ Assert.assertTrue(callbackExcecuted.get());
+ Assert.assertTrue(future.isDone());
+ try {
Review Comment:
maybe can use `Assert.assertThrows`
##########
server/src/main/java/org/apache/druid/server/coordination/ChangeRequestHistory.java:
##########
@@ -74,11 +76,24 @@ public ChangeRequestHistory(int maxSize)
this.singleThreadedExecutor =
Execs.singleThreaded("SegmentChangeRequestHistory");
}
+ public void stop()
+ {
+ singleThreadedExecutor.shutdownNow();
+ final LinkedHashSet<CustomSettableFuture<?>> futures = new
LinkedHashSet<>(waitingFutures.keySet());
+ waitingFutures.clear();
+ for (CustomSettableFuture<?> theFuture : futures) {
+ theFuture.setException(new IllegalStateException("Server is shutting
down."));
+ }
+ }
+
/**
* Add batch of segment changes update.
*/
public synchronized void addChangeRequests(List<T> requests)
{
+ if (singleThreadedExecutor.isShutdown()) {
Review Comment:
should this also throw an exception - since otherwise the caller might never
know that the operation is illegal
--
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]