Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terminate the query after plan generation if timeout #9386

Merged
merged 4 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -18,6 +18,7 @@
*/
package org.apache.pinot.core.plan;

import java.util.concurrent.TimeoutException;
import org.apache.pinot.common.utils.DataTable;
import org.apache.pinot.core.operator.InstanceResponseOperator;
import org.apache.pinot.core.operator.blocks.InstanceResponseBlock;
Expand Down Expand Up @@ -45,11 +46,15 @@ public PlanNode getPlanNode() {
}

@Override
public DataTable execute() {
public DataTable execute()
throws TimeoutException {
long startTime = System.currentTimeMillis();
InstanceResponseOperator instanceResponseOperator = _instanceResponsePlanNode.run();
long endTime1 = System.currentTimeMillis();
LOGGER.debug("InstanceResponsePlanNode.run() took: {}ms", endTime1 - startTime);
if (endTime1 > _instanceResponsePlanNode._queryContext.getEndTimeMs()) {
throw new TimeoutException("Timeout after plan generation");
}
InstanceResponseBlock instanceResponseBlock = instanceResponseOperator.nextBlock();
long endTime2 = System.currentTimeMillis();
LOGGER.debug("InstanceResponseOperator.nextBlock() took: {}ms", endTime2 - endTime1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.pinot.core.plan;

import java.util.concurrent.TimeoutException;
import org.apache.pinot.common.utils.DataTable;
import org.apache.pinot.spi.annotations.InterfaceAudience;

Expand All @@ -32,5 +33,6 @@ public interface Plan {
PlanNode getPlanNode();

/** Execute the query plan and get the instance response. */
DataTable execute();
DataTable execute()
throws TimeoutException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeoutException;
import javax.annotation.Nullable;
import org.apache.pinot.common.request.BrokerRequest;
import org.apache.pinot.common.request.PinotQuery;
Expand Down Expand Up @@ -196,8 +197,14 @@ private BrokerResponseNative getBrokerResponse(PinotQuery pinotQuery, PlanMaker
// Server side
serverQueryContext.setEndTimeMs(System.currentTimeMillis() + Server.DEFAULT_QUERY_EXECUTOR_TIMEOUT_MS);
Plan plan = planMaker.makeInstancePlan(getIndexSegments(), serverQueryContext, EXECUTOR_SERVICE, null);
DataTable instanceResponse =
queryContext.isExplain() ? ServerQueryExecutorV1Impl.processExplainPlanQueries(plan) : plan.execute();
DataTable instanceResponse;
try {
instanceResponse =
queryContext.isExplain() ? ServerQueryExecutorV1Impl.processExplainPlanQueries(plan) : plan.execute();
} catch (TimeoutException e) {
e.printStackTrace();
return null;
}

// Broker side
// Use 2 Threads for 2 data-tables
Expand Down Expand Up @@ -264,10 +271,22 @@ private BrokerResponseNative getBrokerResponseDistinctInstances(PinotQuery pinot
Plan plan1 = planMaker.makeInstancePlan(instances.get(0), serverQueryContext, EXECUTOR_SERVICE, null);
Plan plan2 = planMaker.makeInstancePlan(instances.get(1), serverQueryContext, EXECUTOR_SERVICE, null);

DataTable instanceResponse1 =
queryContext.isExplain() ? ServerQueryExecutorV1Impl.processExplainPlanQueries(plan1) : plan1.execute();
DataTable instanceResponse2 =
queryContext.isExplain() ? ServerQueryExecutorV1Impl.processExplainPlanQueries(plan2) : plan2.execute();
DataTable instanceResponse1;
try {
instanceResponse1 =
queryContext.isExplain() ? ServerQueryExecutorV1Impl.processExplainPlanQueries(plan1) : plan1.execute();
} catch (TimeoutException e) {
e.printStackTrace();
return null;
}
DataTable instanceResponse2;
try {
instanceResponse2 =
queryContext.isExplain() ? ServerQueryExecutorV1Impl.processExplainPlanQueries(plan2) : plan2.execute();
} catch (TimeoutException e) {
e.printStackTrace();
return null;
}

// Broker side
// Use 2 Threads for 2 data-tables
Expand Down