xiangfu0 commented on code in PR #20214:
URL: https://github.com/apache/pinot/pull/20214#discussion_r4619658260
##########
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:
**[P1] Interrupting tracker shutdown can abandon queued consumer offloads**
Restoring the interrupt here carries it into
`releaseAndRemoveAllSegments()`. That method clears the segment map, submits
the offloads, and waits on a fixed-size executor. If work is still pending, the
wait throws immediately and `shutdownNow()` discards queued offloads. A
consuming segment whose offload was queued can keep running after the table
manager is gone. The new tracker wait exposes this existing cancellation
behavior before any segment offload has started.
Please preserve queued offloads through interruption and restore the
caller’s interrupt after segment cleanup. [Segment shutdown
path](https://github.com/apache/pinot/blob/2dc49e3ad554283ed63f2d904b902b0ec2000ea1/pinot-core/src/main/java/org/apache/pinot/core/data/manager/BaseTableDataManager.java#L329-L353)
##########
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)) {
Review Comment:
**[P2] Timeout can still leave the provider open after polling stops**
If this wait expires or the caller is interrupted, shutdown falls through to
remove and close the provider while the poll can still be using it. Kafka can
reject that concurrent close, and the map entry is already gone, so nothing
closes the provider when the poll finally exits.
Consider retaining the scheduled future, cancelling it with interruption,
and queuing provider cleanup on the same single-thread executor before shutting
down the executor. The close then runs after the poll returns, and the table
shutdown thread can keep its bounded wait.
##########
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();
+ }
+ }
+ for (Map.Entry<Integer, StreamMetadataProvider> entry :
_streamConfigIndexToStreamMetadataProvider.entrySet()) {
+ if (_streamConfigIndexToStreamMetadataProvider.remove(entry.getKey(),
entry.getValue())) {
Review Comment:
**[P2] Normal table deletion leaks three Kafka offset gauges**
This removes providers from the map before `removeMetrics()` looks up
`supportsOffsetLag()`. That skips unregistering the per-partition lag,
upstream-offset, and consuming-offset gauges. The remaining lag callback can
report the full last upstream offset as lag once the consuming offset is
cleared. Please remove the gauges while registration state is still available,
or record which gauges were registered independently of provider lifetime.
I verified this locally on JDK 25 with `IngestionDelayTrackerTest`. All 11
existing tests passed. A temporary regression test registered partition 0’s
offset-lag gauge, shut down the tracker, and verified that the delay gauge was
removed. The offset-lag removal assertion failed on `2dc49e3ad5`. The same test
passed with the tracker from the preceding commit, `d3ce1a85`. [Gauge
cleanup](https://github.com/apache/pinot/blob/2dc49e3ad554283ed63f2d904b902b0ec2000ea1/pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/IngestionDelayTracker.java#L403-L418)
--
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]