use of org.apache.drill.shaded.guava.com.google.common.annotations.VisibleForTesting in project drill by apache.
the class JdbcStoragePlugin method initDataSource.
/**
* Initializes {@link HikariDataSource} instance and configures it based on given
* storage plugin configuration.
* Basic parameters such as driver, url, user name and password are set using setters.
* Other source parameters are set dynamically through the properties. See the list
* of available Hikari properties: <a href="https://github.com/brettwooldridge/HikariCP">.
*
* @param config storage plugin config
* @return Hikari data source instance
* @throws UserException if unable to configure Hikari data source
*/
@VisibleForTesting
static HikariDataSource initDataSource(JdbcStorageConfig config) {
try {
Properties properties = new Properties();
/*
Set default HikariCP values which prefer to connect lazily to avoid overwhelming source
systems with connections which mostly remain idle. A data source that is present in N
storage configs replicated over P drillbits with a HikariCP minimumIdle value of Q will
have N×P×Q connections made to it eagerly.
The trade off of lazier connections is increased latency should there be a spike in user
queries involving a JDBC data source. When comparing the defaults that follow with e.g. the
HikariCP defaults, bear in mind that the context here is OLAP, not OLTP. It is normal
for queries to run for a long time and to be separated by long intermissions. Users who
prefer eager to lazy connections remain free to overwrite the following defaults in their
storage config.
*/
// maximum amount of time that a connection is allowed to sit idle in the pool, 0 = forever
// 1 hour
properties.setProperty("dataSource.idleTimeout", String.format("%d000", 1 * 60 * 60));
// how frequently HikariCP will attempt to keep a connection alive, 0 = disabled
properties.setProperty("dataSource.keepaliveTime", String.format("%d000", 0));
// maximum lifetime of a connection in the pool, 0 = forever
// 6 hours
properties.setProperty("dataSource.maxLifetime", String.format("%d000", 6 * 60 * 60));
// minimum number of idle connections that HikariCP tries to maintain in the pool, 0 = none
properties.setProperty("dataSource.minimumIdle", "0");
// maximum size that the pool is allowed to reach, including both idle and in-use connections
properties.setProperty("dataSource.maximumPoolSize", "10");
// apply any HikariCP parameters the user may have set, overwriting defaults
properties.putAll(config.getSourceParameters());
HikariConfig hikariConfig = new HikariConfig(properties);
hikariConfig.setDriverClassName(config.getDriver());
hikariConfig.setJdbcUrl(config.getUrl());
UsernamePasswordCredentials credentials = config.getUsernamePasswordCredentials();
hikariConfig.setUsername(credentials.getUsername());
hikariConfig.setPassword(credentials.getPassword());
// this serves as a hint to the driver, which *might* enable database optimizations
hikariConfig.setReadOnly(!config.isWritable());
return new HikariDataSource(hikariConfig);
} catch (RuntimeException e) {
throw UserException.connectionError(e).message("Unable to configure data source: %s", e.getMessage()).build(logger);
}
}
use of org.apache.drill.shaded.guava.com.google.common.annotations.VisibleForTesting in project drill by apache.
the class PartitionerDecorator method executeMethodLogic.
/**
* Helper to execute the different methods wrapped into same logic
* @param iface
* @throws ExecutionException
*/
@VisibleForTesting
void executeMethodLogic(final GeneralExecuteIface iface) throws ExecutionException {
// interrupts waiting threads. This makes sure that we are actually interrupting the blocked partitioner threads.
try (CountDownLatchInjection testCountDownLatch = injector.getLatch(context.getExecutionControls(), "partitioner-sender-latch")) {
testCountDownLatch.initialize(1);
final AtomicInteger count = new AtomicInteger();
List<PartitionerTask> partitionerTasks = new ArrayList<>(partitioners.size());
ExecutionException executionException = null;
// start waiting on main stats to adjust by sum(max(processing)) at the end
startWait();
try {
partitioners.forEach(partitioner -> createAndExecute(iface, testCountDownLatch, count, partitionerTasks, partitioner));
// Wait for main fragment interruption.
injector.injectInterruptiblePause(context.getExecutionControls(), "wait-for-fragment-interrupt", logger);
testCountDownLatch.countDown();
} catch (InterruptedException e) {
logger.warn("fragment thread interrupted", e);
throw new QueryCancelledException();
} catch (RejectedExecutionException e) {
logger.warn("Failed to execute partitioner tasks. Execution service down?", e);
executionException = new ExecutionException(e);
} finally {
await(count, partitionerTasks);
stopWait();
processPartitionerTasks(partitionerTasks, executionException);
}
}
}
use of org.apache.drill.shaded.guava.com.google.common.annotations.VisibleForTesting in project drill by apache.
the class Drillbit method start.
@VisibleForTesting
public static Drillbit start(final DrillConfig config, final CaseInsensitiveMap<OptionDefinition> validators, final RemoteServiceSet remoteServiceSet) throws DrillbitStartupException {
logger.debug("Starting new Drillbit.");
// TODO: allow passing as a parameter
ScanResult classpathScan = ClassPathScanner.fromPrescan(config);
Drillbit bit;
try {
bit = new Drillbit(config, validators, remoteServiceSet, classpathScan);
} catch (final Exception ex) {
if (ex instanceof DrillbitStartupException) {
throw (DrillbitStartupException) ex;
} else {
throw new DrillbitStartupException("Failure while initializing values in Drillbit.", ex);
}
}
try {
bit.run();
} catch (final Exception e) {
logger.error("Failure during initial startup of Drillbit.", e);
bit.close();
throw new DrillbitStartupException("Failure during initial startup of Drillbit.", e);
}
logger.debug("Started new Drillbit.");
return bit;
}
use of org.apache.drill.shaded.guava.com.google.common.annotations.VisibleForTesting in project drill by apache.
the class PluginBootstrapLoaderImpl method loadBootstrapPlugins.
@VisibleForTesting
protected StoragePlugins loadBootstrapPlugins(Map<String, URL> pluginURLMap) throws IOException {
// bootstrap load the config since no plugins are stored.
String storageBootstrapFileName = context.config().getString(ExecConstants.BOOTSTRAP_STORAGE_PLUGINS_FILE);
Set<URL> storageUrls = ClassPathScanner.forResource(storageBootstrapFileName, false);
if (storageUrls == null || storageUrls.isEmpty()) {
throw new IOException("Cannot find storage plugin boostrap file: " + storageBootstrapFileName);
}
logger.info("Loading the storage plugin configs from URLs {}.", storageUrls);
StoragePlugins bootstrapPlugins = new StoragePlugins();
for (URL url : storageUrls) {
try {
loadStoragePlugins(url, bootstrapPlugins, pluginURLMap);
} catch (IOException e) {
throw new IOException("Failed to load bootstrap plugins from " + url.toString(), e);
}
}
return bootstrapPlugins;
}
use of org.apache.drill.shaded.guava.com.google.common.annotations.VisibleForTesting in project drill by apache.
the class DrillClient method executePreparedStatement.
/**
* Execute the given prepared statement and return the results.
*
* @param preparedStatementHandle Prepared statement handle returned in response to
* {@link #createPreparedStatement(String)}.
* @return List of {@link QueryDataBatch}s. It is responsibility of the caller to release query data batches.
* @throws RpcException
*/
@VisibleForTesting
public List<QueryDataBatch> executePreparedStatement(final PreparedStatementHandle preparedStatementHandle) throws RpcException {
final RunQuery runQuery = newBuilder().setResultsMode(STREAM_FULL).setType(QueryType.PREPARED_STATEMENT).setPreparedStatementHandle(preparedStatementHandle).build();
final ListHoldingResultsListener resultsListener = new ListHoldingResultsListener(runQuery);
client.submitQuery(resultsListener, runQuery);
return resultsListener.getResults();
}
Aggregations