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);
}
}
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();
}
}
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));
}
}
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();
}
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);
}
}
Aggregations