You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2020/07/22 20:29:56 UTC

[GitHub] [incubator-pinot] mayankshriv commented on a change in pull request #5686: Early termination for combining selection order-by results

mayankshriv commented on a change in pull request #5686:
URL: https://github.com/apache/incubator-pinot/pull/5686#discussion_r459062939



##########
File path: pinot-core/src/main/java/org/apache/pinot/core/operator/combine/BaseCombineOperator.java
##########
@@ -0,0 +1,190 @@
+/**
+ * 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.operator.combine;
+
+import java.util.List;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.Phaser;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.pinot.common.exception.QueryException;
+import org.apache.pinot.core.common.Operator;
+import org.apache.pinot.core.operator.BaseOperator;
+import org.apache.pinot.core.operator.blocks.IntermediateResultsBlock;
+import org.apache.pinot.core.query.exception.EarlyTerminationException;
+import org.apache.pinot.core.query.request.context.QueryContext;
+import org.apache.pinot.core.util.trace.TraceRunnable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Base implementation of the combine operator.
+ * <p>Combine operator uses multiple worker threads to process segments in parallel, and uses the main thread to merge
+ * the results blocks from the processed segments. It can early-terminate the query to save the system resources if it
+ * detects that the results collected so far can already satisfy the query, or the query is already timed out.
+ */
+@SuppressWarnings("rawtypes")
+public abstract class BaseCombineOperator extends BaseOperator<IntermediateResultsBlock> {
+  protected static final Logger LOGGER = LoggerFactory.getLogger(BaseCombineOperator.class);
+
+  protected final List<Operator> _operators;
+  protected final QueryContext _queryContext;
+  protected final ExecutorService _executorService;
+  protected final long _timeOutMs;
+
+  public BaseCombineOperator(List<Operator> operators, QueryContext queryContext, ExecutorService executorService,
+      long timeOutMs) {
+    _operators = operators;
+    _queryContext = queryContext;
+    _executorService = executorService;
+    _timeOutMs = timeOutMs;
+  }
+
+  @Override
+  protected IntermediateResultsBlock getNextBlock() {
+    long startTimeMs = System.currentTimeMillis();
+    long endTimeMs = startTimeMs + _timeOutMs;
+    int numOperators = _operators.size();
+    AtomicInteger numOperatorsSkipped = new AtomicInteger();
+
+    // Try to use all MAX_NUM_THREADS_PER_QUERY threads for the query, but ensure each thread has at least one operator

Review comment:
       Seems like this pattern is repeated in all the combine operator flavors. Given that we have fixed a bug in this part (related to refresh) we don't want additional flavors of it lurking around as we would have to fix any future bugs (or enhancements) in all these places. Any way to avoid this? You do have a base class, can that not be used to extract this out as a generic pattern?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org