Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable HikariCP for server config #444

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ project.ext.externalDependency = [
'elasticSearchTransport7': 'org.elasticsearch.client:transport:7.17.24',
'flywayCore': 'org.flywaydb:flyway-core:7.15.0',
'guava': 'com.google.guava:guava:32.0.0-jre',
"hikariCP": "com.zaxxer:HikariCP:3.2.0",
'h2': 'com.h2database:h2:1.4.196',
'jacksonCore': 'com.fasterxml.jackson.core:jackson-core:2.17.2',
'jacksonDataBind': 'com.fasterxml.jackson.core:jackson-databind:2.17.2',
Expand Down
1 change: 1 addition & 0 deletions dao-impl/ebean-dao/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {
compile externalDependency.ebean
compile externalDependency.flywayCore
compile externalDependency.guava
implementation externalDependency.hikariCP
compile externalDependency.jsonSimple
compile externalDependency.log4j

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import javax.persistence.PersistenceException;
import lombok.extern.slf4j.Slf4j;
import org.json.simple.JSONObject;
import com.zaxxer.hikari.HikariDataSource;

import static com.linkedin.metadata.dao.EbeanLocalDAO.*;
import static com.linkedin.metadata.dao.utils.EBeanDAOUtils.*;
Expand Down Expand Up @@ -494,16 +495,38 @@ private String toJsonString(@Nonnull URN urn) {

@Nonnull
private SchemaEvolutionManager createSchemaEvolutionManager(@Nonnull ServerConfig serverConfig) {
String identifier = serverConfig.getDataSourceConfig().getCustomProperties() != null
? serverConfig.getDataSourceConfig().getCustomProperties().getOrDefault(SERVICE_IDENTIFIER, null)
: null;
SchemaEvolutionManager.Config config = new SchemaEvolutionManager.Config(
serverConfig.getDataSourceConfig().getUrl(),
serverConfig.getDataSourceConfig().getPassword(),
serverConfig.getDataSourceConfig().getUsername(),
identifier);

return new FlywaySchemaEvolutionManager(config);
// if ServerConfig is created with a HikariDataSource, we need to extract the config differently.
if (isHikariConfig(serverConfig)) {
final HikariDataSource hikariDataSource = (HikariDataSource) serverConfig.getDataSource();

final SchemaEvolutionManager.Config config = new SchemaEvolutionManager.Config(
hikariDataSource.getJdbcUrl(),
hikariDataSource.getPassword(),
hikariDataSource.getUsername(),
null);

return new FlywaySchemaEvolutionManager(config);
} else {
String identifier = serverConfig.getDataSourceConfig().getCustomProperties() != null
? serverConfig.getDataSourceConfig().getCustomProperties().getOrDefault(SERVICE_IDENTIFIER, null)
: null;
SchemaEvolutionManager.Config config = new SchemaEvolutionManager.Config(
serverConfig.getDataSourceConfig().getUrl(),
serverConfig.getDataSourceConfig().getPassword(),
serverConfig.getDataSourceConfig().getUsername(),
identifier);

return new FlywaySchemaEvolutionManager(config);
}
}

/**
* Checks if the serverConfig is a HikariConfig.
* @param serverConfig contains either a HikariDataSource as dataSource, or a DataSourceConfig as dataSourceConfig.
* @return true if the dataSource is a HikariDataSource, false otherwise.
*/
private boolean isHikariConfig(@Nonnull ServerConfig serverConfig) {
return serverConfig.getDataSource() instanceof HikariDataSource;
}

/**
Expand Down
Loading