This is an automated email from the ASF dual-hosted git repository.
xiangfu0 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new 3c7a9684c3c Keep waiting for segment offloads when the table shutdown
thread is interrupted (#20362)
3c7a9684c3c is described below
commit 3c7a9684c3cf4a1c22a7a5e8bb84afee3e880adb
Author: RAGHVENDRA KUMAR YADAV <[email protected]>
AuthorDate: Tue Nov 24 22:33:46 2026 -0800
Keep waiting for segment offloads when the table shutdown thread is
interrupted (#20362)
releaseAndRemoveAllSegments waits up to 10 minutes for the offloads. When
the
calling thread was interrupted, awaitTermination threw at once and
shutdownNow
dropped the queued offloads and interrupted the running ones, so a consuming
segment could keep running after its table data manager was gone.
Keep waiting within the same 10 minute limit and restore the interrupt once
the
offloads are done.
---
.../core/data/manager/BaseTableDataManager.java | 21 +++++++++++++----
.../data/manager/BaseTableDataManagerTest.java | 27 ++++++++++++++++++++++
2 files changed, 43 insertions(+), 5 deletions(-)
diff --git
a/pinot-core/src/main/java/org/apache/pinot/core/data/manager/BaseTableDataManager.java
b/pinot-core/src/main/java/org/apache/pinot/core/data/manager/BaseTableDataManager.java
index 2f4305810e6..8242cc127a3 100644
---
a/pinot-core/src/main/java/org/apache/pinot/core/data/manager/BaseTableDataManager.java
+++
b/pinot-core/src/main/java/org/apache/pinot/core/data/manager/BaseTableDataManager.java
@@ -342,13 +342,24 @@ public abstract class BaseTableDataManager implements
TableDataManager {
});
}
stopExecutorService.shutdown();
- try {
- // Wait at most 10 minutes before exiting this method.
- if (!stopExecutorService.awaitTermination(10, TimeUnit.MINUTES)) {
- stopExecutorService.shutdownNow();
+ // Wait at most 10 minutes before exiting this method. An interrupt must
not abandon the queued offloads, or a
+ // consuming segment could keep running after its table is gone, so keep
waiting and restore the interrupt once
+ // the offloads are done.
+ long deadlineNanos = System.nanoTime() + TimeUnit.MINUTES.toNanos(10);
+ boolean interrupted = false;
+ boolean terminated = false;
+ long remainingNanos;
+ while (!terminated && (remainingNanos = deadlineNanos -
System.nanoTime()) > 0) {
+ try {
+ terminated = stopExecutorService.awaitTermination(remainingNanos,
TimeUnit.NANOSECONDS);
+ } catch (InterruptedException e) {
+ interrupted = true;
}
- } catch (InterruptedException e) {
+ }
+ if (!terminated) {
stopExecutorService.shutdownNow();
+ }
+ if (interrupted) {
Thread.currentThread().interrupt();
}
}
diff --git
a/pinot-core/src/test/java/org/apache/pinot/core/data/manager/BaseTableDataManagerTest.java
b/pinot-core/src/test/java/org/apache/pinot/core/data/manager/BaseTableDataManagerTest.java
index e4b3d7f7c51..4c855d56c27 100644
---
a/pinot-core/src/test/java/org/apache/pinot/core/data/manager/BaseTableDataManagerTest.java
+++
b/pinot-core/src/test/java/org/apache/pinot/core/data/manager/BaseTableDataManagerTest.java
@@ -199,6 +199,33 @@ public class BaseTableDataManagerTest {
PinotCrypterFactory.init(new PinotConfiguration(properties));
}
+ @Test
+ public void testReleaseAndRemoveAllSegmentsFinishesOffloadsWhenInterrupted()
+ throws Exception {
+ BaseTableDataManager table = createTableManager();
+ int numSegments = 3;
+ CountDownLatch offloaded = new CountDownLatch(numSegments);
+ for (int i = 0; i < numSegments; i++) {
+ SegmentDataManager segmentDataManager = mock(SegmentDataManager.class);
+ doAnswer(invocation -> {
+ Thread.sleep(200);
+ offloaded.countDown();
+ return null;
+ }).when(segmentDataManager).offload();
+ table.registerSegment(SEGMENT_NAME + i, segmentDataManager);
+ }
+
+ Thread.currentThread().interrupt();
+ try {
+ table.releaseAndRemoveAllSegments();
+ assertTrue(Thread.currentThread().isInterrupted());
+ assertEquals(offloaded.getCount(), 0L);
+ assertEquals(table.getNumSegments(), 0);
+ } finally {
+ Thread.interrupted();
+ }
+ }
+
@Test
@SuppressWarnings("deprecation")
public void testOnlineSegmentLoadedDuringShutdownIsDestroyed()
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]