Skip to content

Commit 1c7a1ac

Browse files
committed
[fix](fe) Honor query timeout while waiting for the first split
### What problem does this PR solve? Issue Number: N/A Related PR: #69683 Problem Summary: Enabling Batch Mode for a single selected partition makes MaxCompute read-session creation asynchronous. The first split is not available until buildBatchReadSession completes, but SplitAssignment.init used a fixed 30-second planning timeout. A valid 40-second session creation could therefore fail even when the connector read timeout is 120 seconds and the query timeout is 900 seconds. Use the effective query timeout as the first-split wait bound, and measure the deadline with monotonic time. Add tests for delayed production within the caller deadline and timeout before any split. ### Release note External scans no longer fail after a fixed 30-second first-split wait when the query timeout permits longer planning. ### Check List (For Author) - Test: run-fe-ut.sh ran SplitAssignmentTest (22 passed) and SplitProducerTest (18 passed) with JDK 17; FE Checkstyle passed. A temporary test-only Maven wrapper skipped regeneration inside Maven because the host Xcode license blocks system make; generated sources were built by the standard script using Homebrew gmake. - Behavior changed: Yes. The first-split planning wait follows the effective query timeout. - Does this need documentation: No.
1 parent fdce9a4 commit 1c7a1ac

4 files changed

Lines changed: 31 additions & 21 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/datasource/scan/FileQueryScanNode.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,9 @@ public void createScanRangeLocations() throws UserException {
418418
splitAssignment = new SplitAssignment(backendPolicy, this, this::splitToScanRange,
419419
locationProperties, pathPartitionKeys, admissionResult,
420420
sessionVariable.getSplitBatchSize(), sessionVariable.getSplitQueueCapacity());
421-
splitAssignment.init();
421+
// The first split can require a remote read session (for example, MaxCompute). Keep
422+
// the planning wait bounded by the query's effective timeout instead of a fixed 30 seconds.
423+
splitAssignment.init(ConnectContext.get().getExecTimeoutS() * 1000L);
422424
if (executor != null) {
423425
executor.getSummaryProfile().setGetSplitsFinishTime();
424426
}

‎fe/fe-core/src/main/java/org/apache/doris/datasource/split/SplitAssignment.java‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,23 +193,24 @@ public SplitAssignment(
193193
this.queueCapacity = queueCapacity;
194194
}
195195

196-
public void init() throws UserException {
196+
public void init(long timeoutMillis) throws UserException {
197+
Preconditions.checkArgument(timeoutMillis > 0, "First split timeout must be positive");
197198
splitGenerator.startSplit(backendPolicy.numBackends());
199+
long deadlineNanos = System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(timeoutMillis);
198200
synchronized (readinessLock) {
199-
final int waitIntervalTimeMillis = 100;
200-
final int initTimeoutMillis = 30000; // 30s
201-
int waitTotalTime = 0;
202201
while (sampleSplit == null && needMoreSplit()) {
202+
long remainingNanos = deadlineNanos - System.nanoTime();
203+
if (remainingNanos <= 0) {
204+
throw new UserException("Failed to get first split after waiting for "
205+
+ timeoutMillis + " ms.");
206+
}
203207
try {
204-
readinessLock.wait(waitIntervalTimeMillis);
208+
TimeUnit.NANOSECONDS.timedWait(readinessLock,
209+
Math.min(remainingNanos, TimeUnit.MILLISECONDS.toNanos(100)));
205210
} catch (InterruptedException e) {
211+
Thread.currentThread().interrupt();
206212
throw new UserException(e.getMessage(), e);
207213
}
208-
waitTotalTime += waitIntervalTimeMillis;
209-
if (waitTotalTime > initTimeoutMillis) {
210-
throw new UserException("Failed to get first split after waiting for "
211-
+ (waitTotalTime / 1000) + " seconds.");
212-
}
213214
}
214215
}
215216
if (exception != null) {

‎fe/fe-core/src/test/java/org/apache/doris/datasource/split/SplitAssignmentTest.java‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void firstConvertedSplitDoesNotWaitForAnotherBackendAssignment() throws Exceptio
103103
ExecutorService workers = Executors.newFixedThreadPool(3);
104104
try {
105105
Future<?> init = workers.submit(() -> {
106-
splitAssignment.init();
106+
splitAssignment.init(1000);
107107
return null;
108108
});
109109
Assertions.assertTrue(initStarted.await(5, TimeUnit.SECONDS));
@@ -178,7 +178,7 @@ void stopPreservesFailurePublishedBeforeCancellation() {
178178
// ==================== init() method tests ====================
179179

180180
@Test
181-
void testInitSuccess() throws Exception {
181+
void testInitAcceptsDelayedFirstSplitWithinCallerDeadline() throws Exception {
182182
Multimap<Backend, Split> batch = ArrayListMultimap.create();
183183
batch.put(mockBackend, mockSplit);
184184

@@ -200,7 +200,7 @@ void testInitSuccess() throws Exception {
200200
splitGeneratorThread.start();
201201

202202
// Test
203-
Assertions.assertDoesNotThrow(() -> splitAssignment.init());
203+
Assertions.assertDoesNotThrow(() -> splitAssignment.init(1000));
204204

205205
// Verify sample split is set
206206
Assertions.assertNotNull(splitAssignment.getSampleSplit());
@@ -214,7 +214,7 @@ void testInitInterrupted() throws Exception {
214214
try {
215215
Future<UserException> result = executor.submit(() -> {
216216
Thread.currentThread().interrupt();
217-
return Assertions.assertThrows(UserException.class, splitAssignment::init);
217+
return Assertions.assertThrows(UserException.class, () -> splitAssignment.init(1000));
218218
});
219219
Assertions.assertInstanceOf(InterruptedException.class, result.get(5, TimeUnit.SECONDS).getCause());
220220
Mockito.verify(mockSplitGenerator).startSplit(mockBackendPolicy.numBackends());
@@ -224,13 +224,20 @@ void testInitInterrupted() throws Exception {
224224
}
225225
}
226226

227+
@Test
228+
void testInitUsesCallerDeadlineBeforeFirstSplit() throws Exception {
229+
UserException error = Assertions.assertThrows(UserException.class, () -> splitAssignment.init(20));
230+
Assertions.assertTrue(error.getMessage().contains("20 ms"), error.getMessage());
231+
Mockito.verify(mockSplitGenerator).startSplit(mockBackendPolicy.numBackends());
232+
}
233+
227234
@Test
228235
void testInitWithPreExistingException() throws Exception {
229236
UserException preException = new UserException("Pre-existing error");
230237
splitAssignment.setException(preException);
231238

232239
// Test & Verify
233-
UserException exception = Assertions.assertThrows(UserException.class, () -> splitAssignment.init());
240+
UserException exception = Assertions.assertThrows(UserException.class, () -> splitAssignment.init(1000));
234241
Assertions.assertTrue(exception.getMessage().contains(" Pre-existing error"), exception.getMessage());
235242
}
236243

@@ -463,7 +470,7 @@ void testInitAndAddToQueueIntegration() throws Exception {
463470
splitsProvider.start();
464471

465472
// Test init - should succeed once splits are added
466-
Assertions.assertDoesNotThrow(() -> splitAssignment.init());
473+
Assertions.assertDoesNotThrow(() -> splitAssignment.init(1000));
467474

468475
// Verify
469476
Assertions.assertNotNull(splitAssignment.getSampleSplit());
@@ -481,7 +488,7 @@ void testInitWhenNeedMoreSplitReturnsFalse() throws Exception {
481488
splitAssignment.stop(); // This should make needMoreSplit() return false
482489

483490
// Init should complete immediately without waiting
484-
Assertions.assertDoesNotThrow(() -> splitAssignment.init());
491+
Assertions.assertDoesNotThrow(() -> splitAssignment.init(1000));
485492
}
486493

487494
@Test
@@ -490,6 +497,6 @@ void testInitWithScheduleFinished() throws Exception {
490497
splitAssignment.finishSchedule();
491498

492499
// Init should complete immediately without waiting
493-
Assertions.assertDoesNotThrow(() -> splitAssignment.init());
500+
Assertions.assertDoesNotThrow(() -> splitAssignment.init(1000));
494501
}
495502
}

‎fe/fe-core/src/test/java/org/apache/doris/datasource/split/SplitProducerTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ void twoScansInitializeOnOneWorkerBeforeAnyConsumerStarts() throws Exception {
253253
}).when(second.generator).startSplit(Mockito.anyInt());
254254
try {
255255
Future<?> initialized = planner.submit(() -> {
256-
first.assignment.init();
257-
second.assignment.init();
256+
first.assignment.init(1000);
257+
second.assignment.init(1000);
258258
return null;
259259
});
260260
initialized.get(5, TimeUnit.SECONDS);

0 commit comments

Comments
 (0)