raghavyadav01 commented on code in PR #20214:
URL: https://github.com/apache/pinot/pull/20214#discussion_r4671920387


##########
pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/IngestionDelayTracker.java:
##########
@@ -642,19 +658,36 @@ public long getLatestPartitionOffset(int partitionId) {
     return ((LongMsgOffset) latestOffset).getOffset();
   }
 
-  /// We use this method to clean up when a table is being removed. No updates 
are expected at this time as all
-  /// RealtimeSegmentManagers should be down now.
+  private static void closeStreamMetadataProvider(StreamMetadataProvider 
streamMetadataProvider) {
+    try {
+      streamMetadataProvider.close();
+    } catch (Exception e) {
+      LOGGER.error("Failed to close streamMetadataProvider", e);
+    }
+  }
+
+  /// We use this method to clean up when a table is being removed. It does 
not throw, so the caller can go on to stop
+  /// the table's consumers.
   public void shutdown() {
+    _shuttingDown = true;
     // Now that segments can't report metric, destroy metric for this table
     _metricsRemovalScheduler.shutdown(); // ScheduledExecutor is installed in 
constructor so must always be cancelled
     if (_ingestionDelayTrackingScheduler != null) {
-      _ingestionDelayTrackingScheduler.shutdown();
-    }
-    for (StreamMetadataProvider streamMetadataProvider : 
_streamConfigIndexToStreamMetadataProvider.values()) {
+      // Stop the tracking task before closing the stream metadata providers 
it fetches through: a stream consumer
+      // such as Kafka's is not safe for concurrent use, so closing it under 
an in-flight fetch throws.
+      _ingestionDelayTrackingScheduler.shutdownNow();
       try {
-        streamMetadataProvider.close();
-      } catch (IOException e) {
-        LOGGER.error("Failed to close streamMetadataProvider", e);
+        if 
(!_ingestionDelayTrackingScheduler.awaitTermination(TRACKING_SHUTDOWN_TIMEOUT_MS,
 TimeUnit.MILLISECONDS)) {
+          LOGGER.warn("Ingestion delay tracking task for table: {} did not 
stop within {}ms", _tableNameWithType,
+              TRACKING_SHUTDOWN_TIMEOUT_MS);
+        }
+      } catch (InterruptedException e) {
+        Thread.currentThread().interrupt();

Review Comment:
   Fair point, but I'd rather not change the shared offload wait in this PR. If 
the shutdown thread is interrupted, `releaseAndRemoveAllSegments()` already 
calls `shutdownNow()` and drops the queued offloads, whether the interrupt 
lands before or during the tracker wait. The tracker only restores the flag, as 
any caller should. Happy to do the drain-on-interrupt fix as a separate PR so 
it covers all table types.



-- 
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]

Reply via email to