1

We're testing the failover behaviour using the MariaDB JDBC connector Aurora specific features.

We've set the JDBC URL as the documentation suggest:

jdbc:mysql:aurora://cluster.cluster-xxxx.us-east-1.rds.amazonaws.com/db

The problem is that as soon as we add the aurora: part in the URL schema, we can see an increase in the connections to the database writer until the point that we've to rollback the change (it even reaches 3.000 connections).

Versions:

Configuration:

master {
  profile = "slick.jdbc.MySQLProfile$"
  db {
    driver = "org.mariadb.jdbc.Driver"
    url = "jdbc:mysql:aurora://cluster-name.cluster-xxx.us-east-1.rds.amazonaws.com/db_name?characterEncoding=utf8mb4&rewriteBatchedStatements=true&usePipelineAuth=false"
    user = "rw_user"
    password = "rw_user_pass"
    numThreads = 20
    queueSize = 1000000
  }
}
slaves = [
  {
    profile = "slick.jdbc.MySQLProfile$"
    db {
      driver = "org.mariadb.jdbc.Driver"
      url = "jdbc:mysql:aurora://cluster-name.cluster-ro-xxx.us-east-1.rds.amazonaws.com/db_name?characterEncoding=utf8mb4&usePipelineAuth=false"
      user = "ro_user"
      password = "ro_user_pass"
      numThreads = 20
      queueSize = 1000000
    }
  }
]

We'd tried to add the aurora: part to the JDBC URL schema after upgrading the MariaDB connector version, but the number of connections to the Reader started to increase again:

If we run a show processlist on the read only endpoint, we can see all the opened connections in "cleaned up" state, and "Sleep" command.

We'd removed the aurora: part from the read only endpoint just in order to stabilize the number of connections to it. Is it possible that the driver searches for the cluster master while opening connections? That would explain this kind of behaviour.

4
  • (Mariadb tracker link is jira.mariadb.org/projects/CONJ/issues) Commented May 18, 2017 at 13:54
  • can you execute a "show processlist" to list those multiple connections and their states ? Commented May 18, 2017 at 13:55
  • @DiegoDupin, thanks for your help. I've edited the question providing more details about the issue including the connections status.
    – JavierCane
    Commented May 22, 2017 at 13:12
  • @JavierCane were you ever able to figure this out? It's been a few years, and I'm running into this same problem
    – JPotts
    Commented Mar 10, 2021 at 20:23

2 Answers 2

2

When using the "aurora" keyword, driver , under the hood, create 2 connections:

  • a connection to the primary server,
  • a connection to one of the replicas if any.

The goal is always to save resources on the main server. Generally, only one pool is configured. The driver then uses the connection to the primary / replica according to [Connection.setReadOnly] [1].

When you have separate "write" / "read" pools, using the configuration "failover" will solve your issue: Driver will use only one real connection. This way, there will be no "wasted" connection.

Failover will then be handled differently, but with the same results (for example, a query not in a transaction that is to be sent to a replica that just crashed will not directly use the primary connection as when using the "aurora" configuration, the driver will recreate a new connection to another replicas before executing the query).

5
  • 1. According to your comment, then it wouldn't make too much sense to have multiple Aurora Reader instances, would it? I mean, if the driver will only choose one of the Reader replicas, it will not be distributing the load between the different replicas. It only will be useful in case of a replica failover :S 2. According to your suggestion, we should set the URL schema for the master as jdbc:mysql:aurora:// and the one for the slave as jdbc:mysql:failover:// (full example), have I understood you well? Thanks!
    – JavierCane
    Commented May 24, 2017 at 15:06
  • if you use the "master" pooling configuration only to connect to master i.e , never switch a connection using connection.setReadOnly() or component that will do that like Spring @Transaction(readonly=true), then you can use "jdbc:mysql:failover://". This will avoid to create a slave connection for each connection to master. Commented May 29, 2017 at 7:58
  • The replicat connection is selected randomly among the valid hosts. Thereafter, all statements will run on that database server until the connection will be closed (or fails). So with 60 connections to replicas with a cluster of 3 replicas, their will be roughly 20 connections to each replicas Commented May 29, 2017 at 8:02
  • I just understood your point. My mistake was thinking about connection pools as groups of connections to the very same Reader. In the scenario you just described, the slave connection pool would be formed based on connections to different random Readers, so it will actually balance the load between them. Thanks!
    – JavierCane
    Commented May 30, 2017 at 7:59
  • Regarding to the master connection pool: 1. So if I point out to the cluster-name.cluster-xxx.us-east-1.rds.amazonaws.com URL with the failover: config, it will always open the connection against the Writer? 2. In that case, will we be missing any other connector feature for Aurora?
    – JavierCane
    Commented May 30, 2017 at 8:09
1

Once you get past several dozen active connections, the database starts stumbling over itself. It is better to throttle the connections in the client instead of assuming you have infinite bandwidth to accept connections in Aurora.

1
  • Sure :) The thing is that if I don't add the aurora: part to the JDBC URL schema, HikariCP (the DB connection pool) properly manages the number of connections in the client. But as soon as I add the aurora: part, it doesn't do that. In case this is a bug, how can I report it to the MariaDB JDBC connector? They don't have the GitHub "Issues" enabled in their repo :/ github.com/MariaDB/mariadb-connector-j
    – JavierCane
    Commented May 18, 2017 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.