sohami commented on a change in pull request #1762: [DRILL-7191 / DRILL-7026]: RM state blob persistence in Zookeeper and Integration of Distributed queue configuration with Planner URL: https://github.com/apache/drill/pull/1762#discussion_r280211576
########## File path: exec/java-exec/src/main/java/org/apache/drill/exec/planner/fragment/DistributedQueueParallelizer.java ########## @@ -0,0 +1,273 @@ +/* + * 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.drill.exec.planner.fragment; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.drill.common.exceptions.ExecutionSetupException; +import org.apache.drill.common.util.function.CheckedConsumer; +import org.apache.drill.exec.ops.QueryContext; +import org.apache.drill.exec.physical.PhysicalOperatorSetupException; +import org.apache.drill.exec.physical.base.PhysicalOperator; +import org.apache.drill.common.DrillNode; +import org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint; +import org.apache.drill.exec.resourcemgr.NodeResources; +import org.apache.drill.exec.resourcemgr.config.QueryQueueConfig; +import org.apache.drill.exec.resourcemgr.config.exception.QueueSelectionException; +import org.apache.drill.exec.work.foreman.rm.QueryResourceManager; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.BiFunction; +import java.util.stream.Collectors; + +/** + * Paralellizer specialized for managing resources for a query based on Queues. This parallelizer + * does not deal with increase/decrease of the parallelization of a query plan based on the current + * cluster state. However, the memory assignment for each operator, minor fragment and major + * fragment is based on the cluster state and provided queue configuration. + */ +public class DistributedQueueParallelizer extends SimpleParallelizer { + static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DistributedQueueParallelizer.class); + private final boolean planHasMemory; + private final QueryContext queryContext; + private final QueryResourceManager rm; + private final Map<DrillNode, Map<PhysicalOperator, Long>> operators; + + public DistributedQueueParallelizer(boolean memoryPlanning, QueryContext queryContext, QueryResourceManager queryRM) { + super(queryContext); + this.planHasMemory = memoryPlanning; + this.queryContext = queryContext; + this.rm = queryRM; + this.operators = new HashMap<>(); + } + + // return the memory computed for a physical operator on a drillbitendpoint. + public BiFunction<DrillbitEndpoint, PhysicalOperator, Long> getMemory() { + return (endpoint, operator) -> { + if (!planHasMemory) { + final DrillNode drillEndpointNode = DrillNode.create(endpoint); + if (operator.isBufferedOperator(queryContext)) { + Long operatorsMemory = operators.get(drillEndpointNode).get(operator); + logger.debug(" Memory requirement for the operator {} in endpoint {} is {}", operator, endpoint, operatorsMemory); + return operatorsMemory; + } else { + Long nonBufferedMemory = (long)operator.getCost().getMemoryCost(); + logger.debug(" Memory requirement for the operator {} in endpoint {} is {}", operator, endpoint, nonBufferedMemory); + return nonBufferedMemory; + } + } + else { + return operator.getMaxAllocation(); + } + }; Review comment: How about below ? Also would be good to add a comment why memory for buffered operator is not retrieved from the `PreCostEstimates`. ``` return (endpoint, operator) -> { long operatorMemory = operator.getMaxAllocation(); if (!planHasMemory) { final DrillNode drillEndpointNode = DrillNode.create(endpoint); if (operator.isBufferedOperator(queryContext)) { operatorMemory = operators.get(drillEndpointNode).get(operator); } else { operatorMemory = (long)operator.getCost().getMemoryCost(); } } logger.debug(" Memory requirement for the operator {} in endpoint {} is {}", operator, endpoint, operatorMemory); return operatorMemory; }; ``` ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services
