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

Failed to set a custom configuration for HikariCP (Aurora mysql) #1121

Open
dpiva97 opened this issue Sep 18, 2024 · 0 comments
Open

Failed to set a custom configuration for HikariCP (Aurora mysql) #1121

dpiva97 opened this issue Sep 18, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@dpiva97
Copy link

dpiva97 commented Sep 18, 2024

Describe the bug

Hi,
I have an RDS Aurora MySQL cluster with two instances (writer and reader), and I’m trying to follow the SpringHibernateBalancedReaderTwoDataSourceExample to reduce the load on the writer instance.

Everything seems to work fine, but when I attempt to set a custom Hikari configuration, as described in the commented section of the example , it doesn’t get applied. This appears to be because the HikariPooledConnectionProvider's acceptsUrl method does not accept cluster type URL, so it uses a default provider.

Expected Behavior

Set a custom HikariConfig and print the log inside the HikariPoolConfigurator's configurePool method when a connection pool is created.

What plugins are used? What other connection properties were set?

Using a custom profile starting from the SF_F0 preset (details in additional info section)

Current Behavior

The HikariPooledConnectionProvider is never used.

Reproduction Steps

Follow the SpringHibernateBalancedReaderTwoDataSourceExample with an Aurora mysql cluster

Possible Solution

Modify the acceptsUrl method in HikariPooledConnectionProvider

Additional Information/Context

My custom profile:

static {

        ConfigurationProfileBuilder.get().from(ConfigurationProfilePresetCodes.SF_F0)
                .withName("datasource-with-internal-connection-pool")
                .withConnectionProvider(new ClusterHikariPooledConnectionProvider(
                        (hostSpec, originalProps) -> {
                            LOGGER.info("Start a new HikariCP pool for {}", hostSpec.getHost());

                            final HikariConfig config = new HikariConfig();
                            config.setMaximumPoolSize(25);
                            // holds few extra connections in case of sudden traffic peak
                            config.setMinimumIdle(2);
                            // close idle connection in 15min; helps to get back to normal pool size after load peak
                            config.setIdleTimeout(TimeUnit.MINUTES.toMillis(15));
                            // verify pool configuration and creates no connections during initialization phase
                            config.setInitializationFailTimeout(-1);
                            config.setConnectionTimeout(TimeUnit.SECONDS.toMillis(10));
                            // validate idle connections at least every 3 min
                            config.setKeepaliveTime(TimeUnit.MINUTES.toMillis(3));
                            // allows to quickly validate connection in the pool and move on to another connection if needed
                            config.setValidationTimeout(TimeUnit.SECONDS.toMillis(1));
                            config.setMaxLifetime(TimeUnit.DAYS.toMillis(1));

                            config.setAutoCommit(false);

                            return config;
                        },
                        null
                ))
                .buildAndSet();

    }

application.yml:

spring:
  datasource:
    writer-datasource:
      url: jdbc:aws-wrapper:mysql://####.cluster-####.eu-south-1.rds.amazonaws.com:3306/####?wrapperProfileName=datasource-with-internal-connection-pool&wrapperDialect=aurora-mysql
      username: ####
      password: ####
      driver-class-name: software.amazon.jdbc.Driver
      type: org.springframework.jdbc.datasource.SimpleDriverDataSource
    load-balanced-reader-datasource:
      url: jdbc:aws-wrapper:mysql://####.cluster-ro-####.eu-south-1.rds.amazonaws.com:3306/####?wrapperProfileName=datasource-with-internal-connection-pool&wrapperDialect=aurora-mysql&readerInitialConnectionHostSelectorStrategy=roundRobin
      username: ####
      password: ####
      driver-class-name: software.amazon.jdbc.Driver
      type: org.springframework.jdbc.datasource.SimpleDriverDataSource

The AWS Advanced JDBC Driver version used

2.3.9

JDK version used

17

Operating System and version

windows 11

@dpiva97 dpiva97 added the bug Something isn't working label Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant