Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.pinot.core.common;

import org.apache.pinot.core.operator.ExecutionStatistics;
import org.apache.pinot.core.query.exception.EarlyTerminationException;


public interface Operator<T extends Block> {
Expand All @@ -28,7 +29,10 @@ public interface Operator<T extends Block> {
* <p>For filter operator and operators above projection phase (aggregation, selection, combine etc.), method should
* only be called once, and will return a non-null block.
* <p>For operators in projection phase (docIdSet, projection, transformExpression), method can be called multiple
* times, and will return non-empty block or null if no more documents available</p>
* times, and will return non-empty block or null if no more documents available
*
* @throws EarlyTerminationException if the operator is early-terminated (interrupted) before processing the next
* block of data. Operator can early terminated when the query times out, or is already satisfied.
*/
T nextBlock();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.pinot.core.common.Block;
import org.apache.pinot.core.common.Operator;
import org.apache.pinot.core.query.exception.EarlyTerminationException;
import org.apache.pinot.core.util.trace.TraceContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -34,7 +35,7 @@ public abstract class BaseOperator<T extends Block> implements Operator<T> {
@Override
public final T nextBlock() {
if (Thread.interrupted()) {
throw new RuntimeException("Thread has been interrupted");
throw new EarlyTerminationException();
}
if (TraceContext.traceEnabled()) {
long start = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.pinot.core.query.aggregation.groupby.AggregationGroupByResult;
import org.apache.pinot.core.query.aggregation.groupby.AggregationGroupByTrimmingService;
import org.apache.pinot.core.query.aggregation.groupby.GroupKeyGenerator;
import org.apache.pinot.core.query.exception.EarlyTerminationException;
import org.apache.pinot.core.util.trace.TraceRunnable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -176,6 +177,8 @@ public void runJob() {
});
}
}
} catch (EarlyTerminationException e) {
// Early-terminated because query times out or is already satisfied
} catch (Exception e) {
LOGGER.error("Exception processing CombineGroupBy for index {}, operator {}", index,
_operators.get(index).getClass().getName(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.pinot.core.operator.blocks.IntermediateResultsBlock;
import org.apache.pinot.core.query.aggregation.groupby.AggregationGroupByResult;
import org.apache.pinot.core.query.aggregation.groupby.GroupKeyGenerator;
import org.apache.pinot.core.query.exception.EarlyTerminationException;
import org.apache.pinot.core.util.GroupByUtils;
import org.apache.pinot.core.util.trace.TraceRunnable;
import org.apache.pinot.spi.utils.BytesUtils;
Expand Down Expand Up @@ -181,6 +182,8 @@ public void runJob() {
_indexedTable.upsert(key, record);
}
}
} catch (EarlyTerminationException e) {
// Early-terminated because query times out or is already satisfied
} catch (Exception e) {
LOGGER.error("Exception processing CombineGroupByOrderBy for index {}, operator {}", index,
_operators.get(index).getClass().getName(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.pinot.common.request.Selection;
import org.apache.pinot.core.common.Operator;
import org.apache.pinot.core.operator.blocks.IntermediateResultsBlock;
import org.apache.pinot.core.query.exception.EarlyTerminationException;
import org.apache.pinot.core.query.reduce.CombineService;
import org.apache.pinot.core.util.trace.TraceCallable;
import org.apache.pinot.core.util.trace.TraceRunnable;
Expand Down Expand Up @@ -117,6 +118,8 @@ public void runJob() {
}
}
blockingQueue.offer(mergedBlock);
} catch (EarlyTerminationException e) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add some unit tests/ integration tests for this?

// Early-terminated because query times out or is already satisfied
} catch (Exception e) {
LOGGER.error("Caught exception while executing query.", e);
blockingQueue.offer(new IntermediateResultsBlock(e));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.pinot.core.query.exception;

import org.apache.pinot.core.common.Operator;


/**
* The {@code EarlyTerminationException} can be thrown from {@link Operator#nextBlock()} when the operator is early
* terminated (interrupted).
*/
public class EarlyTerminationException extends RuntimeException {
public EarlyTerminationException() {
super();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.pinot.core.common.Operator;
import org.apache.pinot.core.operator.blocks.IntermediateResultsBlock;
import org.apache.pinot.core.plan.maker.InstancePlanMakerImplV2;
import org.apache.pinot.core.query.exception.EarlyTerminationException;
import org.apache.pinot.pql.parsers.Pql2Compiler;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
Expand Down Expand Up @@ -83,7 +84,11 @@ public void testCombineGroupByOrderByOperator() {
testCombineOperator(operators, combineGroupByOrderByOperator);
}

public void testCombineOperator(List<Operator> operators, BaseOperator combineOperator) {
/**
* NOTE: It is hard to test the logger behavior, but only one error message about the query timeout should be logged
* for each query.
*/
private void testCombineOperator(List<Operator> operators, BaseOperator combineOperator) {
IntermediateResultsBlock intermediateResultsBlock = (IntermediateResultsBlock) combineOperator.nextBlock();
List<ProcessingException> processingExceptions = intermediateResultsBlock.getProcessingExceptions();
assertNotNull(processingExceptions);
Expand Down Expand Up @@ -122,8 +127,8 @@ protected Block getNextBlock() {
try {
Thread.sleep(3_600_000L);
} catch (InterruptedException e) {
// Thread should be interrupted
throw new RuntimeException(e);
// Thread should be interrupted for early-termination
throw new EarlyTerminationException();
} finally {
// Wait for 100 milliseconds before marking the operation done
try {
Expand Down