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

Permit connection creation to allow execution of read-only statements on slaves when master is down

Details

    • Task
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 2.1.0
    • 2.2.0
    • Failover
    • None

    Description

      Some users would like their application to be able to execute read-only statements on slaves even if the master is down. Unfortunately, MariaDB Connector/J does not currently seem to allow this. If the master is down, MariaDB Connector/J throws an exception saying that it failed to connect.

      Would it make sense to add an option that would allow the application to continue executing read-only queries when the master is down? Maybe it could be called "masterDownAllowReadOnly" or something?

      For an example of what I mean, please see the test program that I will attach to the issue. When running the program, I see the following output:

      [ec2-user@ip-172-30-0-249 ~]$ export CLASSPATH=/home/ec2-user/mariadb-java-client-2.1.0.jar:.
      [ec2-user@ip-172-30-0-249 ~]$ javac TestDriverFailoverNoMaster.java
      [ec2-user@ip-172-30-0-249 ~]$ java TestDriverFailoverNoMaster
      SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
      SQLState: 08
      VendorError: 0
      SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
      SQLState: 08
      VendorError: 0
      SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
      SQLState: 08
      VendorError: 0
      SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
      SQLState: 08
      VendorError: 0
      SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
      SQLState: 08
      VendorError: 0
      SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
      SQLState: 08
      VendorError: 0
      SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
      SQLState: 08
      VendorError: 0
      SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
      SQLState: 08
      VendorError: 0
      SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
      SQLState: 08
      VendorError: 0
      SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
      SQLState: 08
      VendorError: 0
      SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
      SQLState: 08
      VendorError: 0
      SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
      SQLState: 08
      VendorError: 0
      SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
      SQLState: 08
      VendorError: 0
      SQLException: Communications link failure with primary. No active connection found for master : Could not connect to HostAddress{host='nonexistent', port=3306, type='master'}. nonexistent.
      SQLState: 08
      VendorError: 0
      

      Attachments

        Activity

          GeoffMontee Geoff Montee (Inactive) created issue -
          GeoffMontee Geoff Montee (Inactive) made changes -
          Field Original Value New Value
          Attachment TestDriverFailoverNoMaster.java [ 43940 ]
          diego dupin Diego Dupin made changes -
          Fix Version/s 2.2.0 [ 22557 ]
          diego dupin Diego Dupin added a comment -

          Actually, existing connection permit that functionnality :
          if masters are down, and application ask for a read-only connection, connection to a slave will be used.

          But driver doesn't permit to create new connection since JDBC default to use master connection.

          This option make sense to permit creating a new connection even if no master connection is up.

          diego dupin Diego Dupin added a comment - Actually, existing connection permit that functionnality : if masters are down, and application ask for a read-only connection, connection to a slave will be used. But driver doesn't permit to create new connection since JDBC default to use master connection. This option make sense to permit creating a new connection even if no master connection is up.
          ralf.gebhardt Ralf Gebhardt made changes -
          Comment [ [~julien.fritsch][~GeoffMontee] just to have the comment from Julien closed here. We will not remove the support id from this Jira issue. ]
          diego dupin Diego Dupin made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          julien.fritsch Julien Fritsch made changes -
          Comment [ A comment with security level 'Developers' was removed. ]
          diego dupin Diego Dupin made changes -
          Resolution Fixed [ 1 ]
          Status In Progress [ 3 ] Closed [ 6 ]
          diego dupin Diego Dupin made changes -
          Summary Allow execution of read-only statements on slaves when master is down Permit connection creation to allow execution of read-only statements on slaves when master is down

          Based on the code changes in the commit for this feature request, it looks like "allowMasterDownConnection=true" needs to be set in order to make this work. Is that correct? If so, I don't see this new option documented yet:

          https://github.com/MariaDB/mariadb-connector-j/commit/cc2cfbd4b01c2480f3c3d8a38a080039f72fec9b#diff-3bea78d9419402bb147fda9c505a1281R536

          https://mariadb.com/kb/en/library/about-mariadb-connector-j/#optional-url-parameters

          GeoffMontee Geoff Montee (Inactive) added a comment - Based on the code changes in the commit for this feature request, it looks like "allowMasterDownConnection=true" needs to be set in order to make this work. Is that correct? If so, I don't see this new option documented yet: https://github.com/MariaDB/mariadb-connector-j/commit/cc2cfbd4b01c2480f3c3d8a38a080039f72fec9b#diff-3bea78d9419402bb147fda9c505a1281R536 https://mariadb.com/kb/en/library/about-mariadb-connector-j/#optional-url-parameters
          diego dupin Diego Dupin added a comment -

          Exactly.
          You're right about the missing documentation, i'll add it tomorrow

          diego dupin Diego Dupin added a comment - Exactly. You're right about the missing documentation, i'll add it tomorrow
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 81936 ] MariaDB v4 [ 128356 ]

          People

            diego dupin Diego Dupin
            GeoffMontee Geoff Montee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.