Search in sources :

Example 21 with OptionManager

use of org.apache.drill.exec.server.options.OptionManager in project drill by apache.

the class TestQueryMemoryAlloc method testOpMemory.

/**
 * Test with default options, various memory configs.
 * Since we can't change the actual CPUs on this node, use an
 * option to specify the number (rather than the usual 70% of
 * actual cores.)
 *
 * @throws Exception
 */
@Test
public void testOpMemory() throws Exception {
    OperatorFixture.Builder builder = OperatorFixture.builder(dirTestWatcher);
    builder.systemOption(ExecConstants.CPU_LOAD_AVERAGE_KEY, 0.7);
    builder.systemOption(ExecConstants.MAX_WIDTH_PER_NODE_KEY, 10);
    builder.systemOption(ExecConstants.MIN_MEMORY_PER_BUFFERED_OP_KEY, 40 * ONE_MB);
    try (OperatorFixture fixture = builder.build()) {
        final OptionManager optionManager = fixture.getOptionManager();
        optionManager.setLocalOption(ExecConstants.CPU_LOAD_AVERAGE_KEY, 0.7);
        optionManager.setLocalOption(ExecConstants.MAX_WIDTH_PER_NODE_KEY, 10);
        optionManager.setLocalOption(ExecConstants.MIN_MEMORY_PER_BUFFERED_OP_KEY, 40 * ONE_MB);
        // Enough memory to go above configured minimum.
        long opMinMem = MemoryAllocationUtilities.computeOperatorMemory(optionManager, 4 * ONE_GB, 2);
        assertEquals(4 * ONE_GB / 10 / 2, opMinMem);
        // Too little memory per operator. Use configured minimum.
        opMinMem = MemoryAllocationUtilities.computeOperatorMemory(optionManager, ONE_GB, 100);
        assertEquals(40 * ONE_MB, opMinMem);
    }
}
Also used : OperatorFixture(org.apache.drill.test.OperatorFixture) OptionManager(org.apache.drill.exec.server.options.OptionManager) Test(org.junit.Test) DrillTest(org.apache.drill.test.DrillTest)

Example 22 with OptionManager

use of org.apache.drill.exec.server.options.OptionManager in project drill by apache.

the class WebServer method generateOptionsDescriptionJSFile.

/**
 * Generate Options Description JavaScript to serve http://drillhost/options ACE library search features
 * @throws IOException when unable to generate functions JS file
 */
private void generateOptionsDescriptionJSFile() throws IOException {
    // Obtain list of Options & their descriptions
    OptionManager optionManager = this.drillbit.getContext().getOptionManager();
    OptionList publicOptions = optionManager.getPublicOptionList();
    List<OptionValue> options = new ArrayList<>(publicOptions);
    // Add internal options
    OptionList internalOptions = optionManager.getInternalOptionList();
    options.addAll(internalOptions);
    Collections.sort(options);
    int numLeftToWrite = options.size();
    // Template source Javascript file
    InputStream optionsDescribeTemplateStream = Resource.newClassPathResource(OPTIONS_DESCRIBE_TEMPLATE_JS).getInputStream();
    // Generated file
    File optionsDescriptionFile = new File(getOrCreateTmpJavaScriptDir(), OPTIONS_DESCRIBE_JS);
    final String file_content_footer = "};";
    // Create a copy of a template and write with that!
    java.nio.file.Files.copy(optionsDescribeTemplateStream, optionsDescriptionFile.toPath());
    logger.info("Will write {} descriptions to {}", numLeftToWrite, optionsDescriptionFile.getAbsolutePath());
    try (BufferedWriter writer = new BufferedWriter(new FileWriter(optionsDescriptionFile, true))) {
        // Iterate through options
        for (OptionValue option : options) {
            numLeftToWrite--;
            String optionName = option.getName();
            OptionDescription optionDescription = optionManager.getOptionDefinition(optionName).getValidator().getOptionDescription();
            if (optionDescription != null) {
                // Note: We don't need to worry about short descriptions for WebUI, since they will never be explicitly accessed from the map
                writer.append("  \"").append(optionName).append("\" : \"").append(StringEscapeUtils.escapeEcmaScript(optionDescription.getDescription())).append(numLeftToWrite > 0 ? "\"," : "\"");
                writer.newLine();
            }
        }
        writer.append(file_content_footer);
        writer.newLine();
        writer.flush();
    }
}
Also used : OptionDescription(org.apache.drill.exec.server.options.OptionValidator.OptionDescription) InputStream(java.io.InputStream) FileWriter(java.io.FileWriter) OptionValue(org.apache.drill.exec.server.options.OptionValue) ArrayList(java.util.ArrayList) File(java.io.File) OptionManager(org.apache.drill.exec.server.options.OptionManager) OptionList(org.apache.drill.exec.server.options.OptionList) BufferedWriter(java.io.BufferedWriter)

Example 23 with OptionManager

use of org.apache.drill.exec.server.options.OptionManager in project drill by apache.

the class SetOptionHandler method getPlan.

/**
 * Handles {@link DrillSqlSetOption} query
 */
@Override
public final PhysicalPlan getPlan(SqlNode sqlNode) throws ForemanSetupException {
    // sqlNode could contain DrillSqlResetOption or DrillSqlSetOption, depends on parsed statement
    SqlSetOption statement = unwrap(sqlNode, SqlSetOption.class);
    OptionScope optionScope = getScope(statement, context.getOptions());
    OptionManager optionManager = context.getOptions().getOptionManager(optionScope);
    String optionName = statement.getName().toString();
    SqlNode optionValue = statement.getValue();
    if (optionValue == null) {
        // OptionManager.getOptionDefinition() call ensures that the specified option name is valid
        OptionDefinition optionDefinition = optionManager.getOptionDefinition(optionName);
        String value = String.valueOf(optionManager.getOption(optionName).getValue());
        // obtains option name from OptionDefinition to use the name as defined in the option, rather than what the user provided
        return DirectPlan.createDirectPlan(context, new SetOptionViewResult(optionDefinition.getValidator().getOptionName(), value));
    } else {
        if (optionScope == OptionValue.OptionScope.SYSTEM) {
            checkAdminPrivileges(context.getOptions());
        }
        if (!(optionValue instanceof SqlLiteral)) {
            throw UserException.validationError().message("Drill does not support assigning non-literal values in SET statements.").build(logger);
        }
        optionManager.setLocalOption(optionName, sqlLiteralToObject((SqlLiteral) optionValue));
        return DirectPlan.createDirectPlan(context, true, String.format("%s updated.", optionName));
    }
}
Also used : OptionScope(org.apache.drill.exec.server.options.OptionValue.OptionScope) DrillSqlSetOption(org.apache.drill.exec.planner.sql.parser.DrillSqlSetOption) SqlSetOption(org.apache.calcite.sql.SqlSetOption) NlsString(org.apache.calcite.util.NlsString) OptionDefinition(org.apache.drill.exec.server.options.OptionDefinition) SqlLiteral(org.apache.calcite.sql.SqlLiteral) OptionManager(org.apache.drill.exec.server.options.OptionManager) SqlNode(org.apache.calcite.sql.SqlNode)

Example 24 with OptionManager

use of org.apache.drill.exec.server.options.OptionManager in project drill by apache.

the class QueryTestUtil method restoreScalarReplacementOption.

/**
 * Restore the original scalar replacement option returned from
 * setupScalarReplacementOption().
 *
 * <p>This also flushes the compiled code cache.
 *
 * @param drillbit the drillbit
 * @param srOption the scalar replacement option value to use
 */
public static void restoreScalarReplacementOption(final Drillbit drillbit, final String srOption) {
    final DrillbitContext drillbitContext = drillbit.getContext();
    final OptionManager optionManager = drillbitContext.getOptionManager();
    optionManager.setLocalOption(ExecConstants.SCALAR_REPLACEMENT_OPTION, srOption);
    // flush the code cache
    drillbitContext.getCompiler().flushCache();
}
Also used : DrillbitContext(org.apache.drill.exec.server.DrillbitContext) OptionManager(org.apache.drill.exec.server.options.OptionManager) SystemOptionManager(org.apache.drill.exec.server.options.SystemOptionManager)

Example 25 with OptionManager

use of org.apache.drill.exec.server.options.OptionManager in project drill by apache.

the class Foreman method acquireQuerySemaphore.

private void acquireQuerySemaphore(double totalCost) throws ForemanSetupException {
    final OptionManager optionManager = queryContext.getOptions();
    final long queueThreshold = optionManager.getOption(ExecConstants.QUEUE_THRESHOLD_SIZE);
    final long queueTimeout = optionManager.getOption(ExecConstants.QUEUE_TIMEOUT);
    final String queueName;
    try {
        final ClusterCoordinator clusterCoordinator = drillbitContext.getClusterCoordinator();
        final DistributedSemaphore distributedSemaphore;
        // get the appropriate semaphore
        if (totalCost > queueThreshold) {
            final int largeQueue = (int) optionManager.getOption(ExecConstants.LARGE_QUEUE_SIZE);
            distributedSemaphore = clusterCoordinator.getSemaphore("query.large", largeQueue);
            queueName = "large";
        } else {
            final int smallQueue = (int) optionManager.getOption(ExecConstants.SMALL_QUEUE_SIZE);
            distributedSemaphore = clusterCoordinator.getSemaphore("query.small", smallQueue);
            queueName = "small";
        }
        lease = distributedSemaphore.acquire(queueTimeout, TimeUnit.MILLISECONDS);
    } catch (final Exception e) {
        throw new ForemanSetupException("Unable to acquire slot for query.", e);
    }
    if (lease == null) {
        throw UserException.resourceError().message("Unable to acquire queue resources for query within timeout.  Timeout for %s queue was set at %d seconds.", queueName, queueTimeout / 1000).build(logger);
    }
}
Also used : DistributedSemaphore(org.apache.drill.exec.coord.DistributedSemaphore) ClusterCoordinator(org.apache.drill.exec.coord.ClusterCoordinator) OptionManager(org.apache.drill.exec.server.options.OptionManager) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) UserException(org.apache.drill.common.exceptions.UserException) RpcException(org.apache.drill.exec.rpc.RpcException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) OptimizerException(org.apache.drill.exec.exception.OptimizerException) OutOfMemoryException(org.apache.drill.exec.exception.OutOfMemoryException) ExecutionSetupException(org.apache.drill.common.exceptions.ExecutionSetupException) IOException(java.io.IOException)

Aggregations

OptionManager (org.apache.drill.exec.server.options.OptionManager)39 Test (org.junit.Test)10 DrillTest (org.apache.drill.test.DrillTest)8 OperatorFixture (org.apache.drill.test.OperatorFixture)8 DrillbitContext (org.apache.drill.exec.server.DrillbitContext)7 OptionValue (org.apache.drill.exec.server.options.OptionValue)6 ExecutionSetupException (org.apache.drill.common.exceptions.ExecutionSetupException)5 SystemOptionManager (org.apache.drill.exec.server.options.SystemOptionManager)5 LinkedList (java.util.LinkedList)4 Callable (java.util.concurrent.Callable)4 ExecutionException (java.util.concurrent.ExecutionException)4 DrillConfig (org.apache.drill.common.config.DrillConfig)4 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)4 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)4 MaterializedField (org.apache.drill.exec.record.MaterializedField)4 ArrayList (java.util.ArrayList)3 RelOptPlanner (org.apache.calcite.plan.RelOptPlanner)3 RelTraitSet (org.apache.calcite.plan.RelTraitSet)3 RelNode (org.apache.calcite.rel.RelNode)3 SqlSetOption (org.apache.calcite.sql.SqlSetOption)3