Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-759

Connections sometimes don't respect setCatalog

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.4.4, 2.5.4
    • Fix Version/s: 2.6.0
    • Component/s: aurora, Failover
    • Labels:
      None
    • Environment:
      AWS Aurora RDS with 1 replica

      Description

      We have a multi-tenant DataSource implementation, which wraps HikariCP pools and calls setCatalog on connect, like so:

      @Override
      public Connection getConnection() throws SQLException {
        DataSource ds = getHikariDs(...);
        Connection conn = ds.getConnection();
        conn.setCatalog(...);
        return conn;
      }
      

      What I'm seeing is sporadic SQL errors indicating a connection is using the default database (from the url) and not the one specified in setCatalog. In debugging, I see that the connection with the error is different than the one created, leading me to think it's an issue with secondary protocol. This seems to happen with Spring MVC controller methods marked as @Transactional(readOnly=true).

      I found in reading the source a questionable condition which potentially might be leading to this issue, in MastersSlavesListener:: lockAndSwitchSecondary(): https://github.com/mariadb-corporation/mariadb-connector-j/blob/master/src/main/java/org/mariadb/jdbc/internal/failover/impl/MastersSlavesListener.java#L648

          // if asked to be on read only connection, switching to this new connection
          if (currentReadOnlyAsked
              || (urlParser.getOptions().failOnReadOnly && !currentReadOnlyAsked && isMasterHostFail())) {
      >>>      if (currentProtocol == null) {    <<<
              try {
                syncConnection(currentProtocol, newSecondaryProtocol);
              } catch (Exception e) {
                // Some error append during connection parameter synchronisation
              }
            }
            currentProtocol = newSecondaryProtocol;
      

      I am thinking that line should rather be " if (currentProtocol != null) ", so that the syncConnection() call can properly copy the database into the newSecondaryProtocol?

        Attachments

          Activity

            People

            Assignee:
            diego dupin Diego Dupin
            Reporter:
            jstehler Jared Stehler
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: