Skip to content

Unable to see traffic on read replica using read-write-plugin #1372

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

Closed
amihaescu opened this issue Apr 25, 2025 · 2 comments
Closed

Unable to see traffic on read replica using read-write-plugin #1372

amihaescu opened this issue Apr 25, 2025 · 2 comments

Comments

@amihaescu
Copy link

Hello team,

I am trying to use the aws-advanced-jdbc-wrapper in a SpringBoot 3.4.4 application that connects to an RDS Aurora Postgres cluster with 2 replicas. I am using aws-advanced-jdbc-wrapper:2.5.6

We have a 3 tier architecture - Controller-Service-Repository - with all service classes having the annotation @Transactional ( readOnly = true) and only methods that alter the data have @Transactional

Here is some of the configuration

application-prod.yml

  datasource:
    aws-jdbc-wrapper:
      driver-class-name: software.amazon.jdbc.Driver
      url: jdbc:aws-wrapper:postgresql://${env.DATABASE_HOSTNAME}:5432/${env.DATABASE_NAME}?wrapperProfileName=SF_F0&readerInitialConnectionHostSelectorStrategy=roundRobin
      username: ${env.DATABASE_USERNAME}
      password: ${env.DATABASE_PASSWORD}
      type: org.springframework.jdbc.datasource.SimpleDriverDataSource
      wrapper-plugins: readWriteSplitting,failover2,efm2
      wrapper-dialect: aurora-pg
      reader-host-selector-strategy: roundRobin

DATABASE_HOSTNAME -> points to the writer

@Configuration
class DatabaseConfig {

  @Bean
  fun dataSource(awsJdbcWrapperConfig: AwsJdbcWrapperConfig): DataSource {
    val ds = SimpleDriverDataSource()
    val properties = Properties()

    // wrapper config
    awsJdbcWrapperConfig.wrapperPlugins?.let { properties["wrapperPlugins"] = it }
    awsJdbcWrapperConfig.wrapperDialect?.let { properties["wrapperDialect"] = it }
    awsJdbcWrapperConfig.readerHostSelectorStrategy?.let {
      properties["readerHostSelectorStrategy"] = it
    }
    awsJdbcWrapperConfig.clusterInstanceHostPattern?.let {
      properties["clusterInstanceHostPattern"] = it
    }
    properties["connectTimeout"] = TimeUnit.SECONDS.toMillis(30)

    // https://github.com/aws/aws-advanced-jdbc-wrapper/issues/1138
    // workaround to use internal connection pool
    properties[RdsHostListProvider.CLUSTER_ID.name] = "test"

    ds.setDriverClass(software.amazon.jdbc.Driver::class.java)
    ds.url = awsJdbcWrapperConfig.url
    ds.username = awsJdbcWrapperConfig.username
    ds.password = awsJdbcWrapperConfig.password
    ds.connectionProperties = properties

    // Enable jdbc wrapper internal connection pool
    // https://github.com/aws/aws-advanced-jdbc-wrapper/blob/main/docs/using-the-jdbc-driver/using-plugins/UsingTheReadWriteSplittingPlugin.md#internal-connection-pooling
    ConnectionProviderManager.setConnectionProvider(
      HikariPooledConnectionProvider { _, _ ->
        // https://github.com/brettwooldridge/HikariCP
        val config = HikariConfig()
        config.maximumPoolSize = 10
        config.connectionTimeout = TimeUnit.SECONDS.toMillis(30)

        return@HikariPooledConnectionProvider config
      }
    )
    return ds
  }
}

@ConfigurationProperties(prefix = "spring.datasource.aws-jdbc-wrapper")
data class AwsJdbcWrapperConfig(
  val url: String,
  val username: String,
  val password: String,
  val wrapperPlugins: String?,
  val wrapperDialect: String?,
  val readerHostSelectorStrategy: String?,
  val clusterInstanceHostPattern: String?,
)

Any pointer to what I might be doing wrong?

We have some E2E tests that perform both read and write operations, but in the AWS RDS Performance insights I only see traffic on the writer replica.

@sergiyvamz
Copy link
Contributor

Hi @amihaescu

Thank you for reaching out with this issue.

It seems that your application uses SF_F0 profile and this profile has no ReadWriteSplitting plugin included.

https://github.com/aws/aws-advanced-jdbc-wrapper/blob/main/docs/using-the-jdbc-driver/ConfigurationPresets.md#existing-configuration-presets

Configuration presets starting with the SF_ prefix are optimized for Spring Framework/Boot applications. These presets correspond to the same presets with no such prefix, but have the Read/Write Splitting Plugin disabled.

We can suggest to try F0 profile instead.


@amihaescu
Copy link
Author

@sergiyvamz thank you for your reply. That seems to have fixed it. Thank you ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants