egor-ryashin commented on a change in pull request #7038: Fix and document 
concurrency of EventReceiverFirehose and TimedShutoffFirehose; Refine 
concurrency specification of Firehose
URL: https://github.com/apache/incubator-druid/pull/7038#discussion_r255304496
 
 

 ##########
 File path: 
server/src/main/java/org/apache/druid/segment/realtime/firehose/EventReceiverFirehoseFactory.java
 ##########
 @@ -411,13 +506,31 @@ public Response shutdown(
       }
 
       try {
-        DateTime shutoffAt = shutoffTime == null ? DateTimes.nowUtc() : 
DateTimes.of(shutoffTime);
-        log.info("Setting Firehose shutoffTime to %s", shutoffTime);
-        exec.schedule(
-            this::close,
-            shutoffAt.getMillis() - System.currentTimeMillis(),
-            TimeUnit.MILLISECONDS
-        );
+        DateTime shutoffAt = shutoffTimeMillis == null ? DateTimes.nowUtc() : 
DateTimes.of(shutoffTimeMillis);
+        log.info("Setting Firehose shutoffTime to %s", shutoffTimeMillis);
+        long shutoffTimeoutMillis = Math.max(shutoffAt.getMillis() - 
System.currentTimeMillis(), 0);
+
+        requestedShutdownTimeNsHolder.set(System.nanoTime() + 
TimeUnit.MILLISECONDS.toNanos(shutoffTimeoutMillis));
+        Thread delayedCloseExecutor = this.delayedCloseExecutor;
+        // Need to interrupt delayedCloseExecutor because a newly specified 
shutdown time might be closer than idle
+        // timeout or previously specified shutdown. Interruption of 
delayedCloseExecutor lets it adjust the sleep time
+        // (see the logic of this thread in createDelayedCloseExecutor()).
+        boolean needToInterruptDelayedCloseExecutor = true;
+        if (delayedCloseExecutor == null) {
 
 Review comment:
   `shutdown` is a rare call, we can do everything under `synchronized` without 
double-check pattern.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to