Do not alter query timeout in ScanQueryEngine (#12271)

Add test to detect timeout mutability
This commit is contained in:
machine424 2022-05-19 18:24:42 +02:00 committed by GitHub
parent ec41dfb535
commit 90531fd53f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 10 deletions

View File

@ -408,7 +408,6 @@ public abstract class ResponseContext
/**
* Query fail time (current time + timeout).
* It is not updated continuously as {@link Keys#TIMEOUT_AT}.
*/
public static final Key QUERY_FAIL_DEADLINE_MILLIS = new LongKey(
"queryFailTime",
@ -417,8 +416,6 @@ public abstract class ResponseContext
/**
* This variable indicates when a running query should be expired,
* and is effective only when 'timeout' of queryContext has a positive value.
* Continuously updated by {@link org.apache.druid.query.scan.ScanQueryEngine}
* by reducing its value on the time of every scan iteration.
*/
public static final Key TIMEOUT_AT = new LongKey(
"timeoutAt",

View File

@ -80,7 +80,6 @@ public class ScanQueryEngine
}
final boolean hasTimeout = QueryContexts.hasTimeout(query);
final Long timeoutAt = responseContext.getTimeoutTime();
final long start = System.currentTimeMillis();
final StorageAdapter adapter = segment.asStorageAdapter();
if (adapter == null) {
@ -192,11 +191,6 @@ public class ScanQueryEngine
throw new UOE("resultFormat[%s] is not supported", resultFormat.toString());
}
responseContext.addRowScanCount(offset - lastOffset);
if (hasTimeout) {
responseContext.putTimeoutTime(
timeoutAt - (System.currentTimeMillis() - start)
);
}
return new ScanResultValue(segmentId.toString(), allColumns, events);
}

View File

@ -909,7 +909,8 @@ public class ScanQueryRunnerTest extends InitializedNullHandlingTest
.context(ImmutableMap.of(QueryContexts.TIMEOUT_KEY, 1))
.build();
ResponseContext responseContext = DefaultResponseContext.createEmpty();
responseContext.putTimeoutTime(System.currentTimeMillis());
final long timeoutAt = System.currentTimeMillis();
responseContext.putTimeoutTime(timeoutAt);
try {
runner.run(QueryPlus.wrap(query), responseContext).toList();
Assert.fail("didn't timeout");
@ -917,6 +918,7 @@ public class ScanQueryRunnerTest extends InitializedNullHandlingTest
catch (RuntimeException e) {
Assert.assertTrue(e instanceof QueryTimeoutException);
Assert.assertEquals("Query timeout", ((QueryTimeoutException) e).getErrorCode());
Assert.assertEquals(timeoutAt, responseContext.getTimeoutTime().longValue());
}
}