Skip to content

Commit

Permalink
HIVE-28749: The default hikaricp.leakDetectionThreshold is not valid (#…
Browse files Browse the repository at this point in the history
…5639) (Shohei Okumiya, reviewed by Stamatis Zampetakis, Zhihua Deng)
  • Loading branch information
okumin authored Feb 14, 2025
1 parent fa6813f commit b395fc7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public class HikariCPDataSourceProvider implements DataSourceProvider {
private static final Logger LOG = LoggerFactory.getLogger(HikariCPDataSourceProvider.class);

static final String HIKARI = "hikaricp";
private static final String CONNECTION_TIMEOUT_PROPERTY = HIKARI + ".connectionTimeout";
private static final String LEAK_DETECTION_THRESHOLD = HIKARI + ".leakDetectionThreshold";

@Override
public DataSource create(Configuration hdpConfig, int maxPoolSize) throws SQLException {
Expand All @@ -52,10 +50,7 @@ public DataSource create(Configuration hdpConfig, int maxPoolSize) throws SQLExc
String user = DataSourceProvider.getMetastoreJdbcUser(hdpConfig);
String passwd = DataSourceProvider.getMetastoreJdbcPasswd(hdpConfig);

Properties properties = replacePrefix(
DataSourceProvider.getPrefixedProperties(hdpConfig, HIKARI));
long connectionTimeout = hdpConfig.getLong(CONNECTION_TIMEOUT_PROPERTY, 30000L);
long leakDetectionThreshold = hdpConfig.getLong(LEAK_DETECTION_THRESHOLD, 3600000L);
Properties properties = replacePrefix(DataSourceProvider.getPrefixedProperties(hdpConfig, HIKARI));

HikariConfig config;
try {
Expand All @@ -67,7 +62,6 @@ public DataSource create(Configuration hdpConfig, int maxPoolSize) throws SQLExc
config.setJdbcUrl(driverUrl);
config.setUsername(user);
config.setPassword(passwd);
config.setLeakDetectionThreshold(leakDetectionThreshold);
if (!StringUtils.isEmpty(poolName)) {
config.setPoolName(poolName);
}
Expand All @@ -79,13 +73,10 @@ public DataSource create(Configuration hdpConfig, int maxPoolSize) throws SQLExc
// so that the connection pool can retire the idle connection aggressively,
// this will make Metastore more scalable especially if there is a leader in the warehouse.
if ("mutex".equals(poolName)) {
int minimumIdle = Integer.valueOf(hdpConfig.get(HIKARI + ".minimumIdle", "2"));
int minimumIdle = Integer.parseInt(hdpConfig.get(HIKARI + ".minimumIdle", "2"));
config.setMinimumIdle(Math.min(maxPoolSize, minimumIdle));
}

//https://github.com/brettwooldridge/HikariCP
config.setConnectionTimeout(connectionTimeout);

DatabaseProduct dbProduct = DatabaseProduct.determineDatabaseProduct(driverUrl, hdpConfig);

String s = dbProduct.getPrepareTxnStmt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,27 @@ public void testNoDataSourceCreatedWithoutProps() throws SQLException {
}

@Test
public void testSetHikariCpLeakDetectionThresholdProperty() throws SQLException {
public void testDefaultHikariCpProperties() throws SQLException {
MetastoreConf.setVar(conf, ConfVars.CONNECTION_POOLING_TYPE, HikariCPDataSourceProvider.HIKARI);

DataSourceProvider dsp = DataSourceProviderFactory.tryGetDataSourceProviderOrNull(conf);
Assert.assertNotNull(dsp);

DataSource ds = dsp.create(conf);
Assert.assertTrue(ds instanceof HikariDataSource);
HikariDataSource hds = (HikariDataSource) ds;
Assert.assertEquals(30000L, hds.getConnectionTimeout());
Assert.assertEquals(1800000L, hds.getMaxLifetime());
Assert.assertEquals(0L, hds.getLeakDetectionThreshold());
Assert.assertEquals(1L, hds.getInitializationFailTimeout());
}

@Test
public void testSetHikariCpProperties() throws SQLException {

MetastoreConf.setVar(conf, ConfVars.CONNECTION_POOLING_TYPE, HikariCPDataSourceProvider.HIKARI);
conf.set(HikariCPDataSourceProvider.HIKARI + ".connectionTimeout", "2000");
conf.set(HikariCPDataSourceProvider.HIKARI + ".maxLifetime", "50000");
conf.set(HikariCPDataSourceProvider.HIKARI + ".leakDetectionThreshold", "3600");
conf.set(HikariCPDataSourceProvider.HIKARI + ".initializationFailTimeout", "-1");

Expand All @@ -74,7 +92,11 @@ public void testSetHikariCpLeakDetectionThresholdProperty() throws SQLException

DataSource ds = dsp.create(conf);
Assert.assertTrue(ds instanceof HikariDataSource);
Assert.assertEquals(3600L, ((HikariDataSource)ds).getLeakDetectionThreshold());
HikariDataSource hds = (HikariDataSource) ds;
Assert.assertEquals(2000L, hds.getConnectionTimeout());
Assert.assertEquals(50000L, hds.getMaxLifetime());
Assert.assertEquals(3600L, hds.getLeakDetectionThreshold());
Assert.assertEquals(-1L, hds.getInitializationFailTimeout());
}

@Test
Expand Down

0 comments on commit b395fc7

Please sign in to comment.