Uploaded image for project: 'MariaDB Connector/C'
  1. MariaDB Connector/C
  2. CONC-735

reconnect doesn't do node failover

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Critical
    • Resolution: Fixed
    • 3.4.1, 3.3.11
    • 3.4.3, 3.3.13
    • Other
    • None
    • Linux

    Description

      When using a connection string with multiple hosts, to achieve failover, and reconnections happens, either by calling mariadb_reconnect(), using MYSQL_OPT_RECONNECT or the reconnect=1 connection string option, reconnection will only tried on the host that was connected to in the connection string, even though there are more hosts to choose from. This is non-intuitive and is also not the way Connector/J works.

      The following code should, when srv1 fails, report an error and then reconnect to srv2, but instead it keeps reporting errors on connecting to srv1:

      #include <stdio.h>
      #include <stdlib.h>
      #include <mysql.h>
       
      int main(int argc, char *argv[])
         {
         MYSQL *pMariaDB;
         MYSQL_RES *pRes;
         MYSQL_ROW row;
         my_bool bTrue = 1;
       
         pMariaDB = mysql_init(NULL);
         mysql_optionsv(pMariaDB, MYSQL_OPT_RECONNECT, &bTrue);
         if(mysql_real_connect(pMariaDB, "host=srv1,srv2;user=appuser;"
           "password=apppwd;database=appdb;ssl_verify_server_cert=0;reconnect=1",
           NULL, NULL, NULL, 0, NULL, CLIENT_INTERACTIVE) == NULL)
            {
            fprintf(stderr, "Error connecting to MariaDB:\n%s\n", mysql_error(pMariaDB));
            return 1;
            }
       
         for(;; sleep(1))
            {
            if(mysql_query(pMariaDB, "SELECT NOW()") != 0)
               fprintf(stderr, "Error in query MariaDB:\n%s\n", mysql_error(pMariaDB));
            else
               {
               if((pRes = mysql_store_result(pMariaDB)) == NULL)
                  {
                  fprintf(stderr, "Error in store_result MariaDB:\n%s\n",
                    mysql_error(pMariaDB));
                  continue;
                  }
       
               while((row = mysql_fetch_row(pRes)) != NULL)
                  printf("Now: %s\n", row[0]);
               mysql_free_result(pRes);
               }
            }
       
         mysql_close(pMariaDB);
         return 0;
         }
      

      Attachments

        Activity

          People

            georg Georg Richter
            karlsson Anders Karlsson
            Votes:
            0 Vote for this issue
            Watchers:
            2 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.