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

New HaMode: sequential write, loadbalance read

Details

    • New Feature
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Fixed
    • None
    • 3.5.1
    • Failover, galera
    • None

    Description

      This is a proposal / feature request for a new HA mode (sequential write, loadbalance read) in the MariaDb Connector/J.

      When running a multi-master cluster (i.e. Galera), writing to more than one node can lead to optimistic locking errors (weirdly called "deadlocks"), see https://galeracluster.com/library/kb/deadlock-found.html.
      Writing concurrently to multiple nodes also doesn't bring a whole lot of performance, due to having to (synchronously) replicate to all 3 nodes anyway.

      The recommended workaround is to use a read-write splitter (e.g. MaxScale) which would redirect writes to one node, but allow reading from multiple.

      Such read-write splitting looks like something that can be easily done client-side by the MariaDB Connector/J, by adding a new HaMode.java enum value that will:

      • pick the single write node sequentially (to ensure high-availability), but
      • load-balance multiple read nodes

      An example implementation could be as simple as:

        SEQUENTIAL_WRITE_LOADBALANCE_READ("sequential-write-load-balance-read") {
          @Override
          public Optional<HostAddress> getAvailableHost(
                  List<HostAddress> hostAddresses,
                  ConcurrentMap<HostAddress, Long> denyList,
                  boolean primary) {
            if (primary) {
              return SEQUENTIAL.getAvailableHost(hostAddresses, denyList, true);
            } else {
              return LOADBALANCE.getAvailableHost(hostAddresses, denyList, false);
            }
          }
        },
      

      Note: the implementation is not final/tested, but is rather meant to gauge interest for a potential PR and as a starting point for a discussion.

      Attachments

        Activity

          diego dupin Diego Dupin added a comment - - edited

          it make sense. This possibility is already available on node.js connector, using code like :

          const cluster = mariadb.createPoolCluster();
            cluster.add('master1', { host: 'mydb1.com', user: 'myUser', connectionLimit: 5 });
            cluster.add('master2', { host: 'mydb2.com', user: 'myUser', connectionLimit: 5 });
            cluster.add('replica1', { host: 'mydb3.com', user: 'myUser', connectionLimit: 5 });
            cluster.add('replica2', { host: 'mydb4.com', user: 'myUser', connectionLimit: 5 });
           
            // get 'write' connection : will retrieve in order by default
            const writeConn = cluster.getConnection('master*');
           
            // get 'read' connection : will retrieve in round-robin
            const readConn = cluster.getConnection('replica*', 'RR');
          
          

          but there is no possibility using java connector

          diego dupin Diego Dupin added a comment - - edited it make sense. This possibility is already available on node.js connector, using code like : const cluster = mariadb.createPoolCluster(); cluster.add( 'master1' , { host: 'mydb1.com' , user: 'myUser' , connectionLimit: 5 }); cluster.add( 'master2' , { host: 'mydb2.com' , user: 'myUser' , connectionLimit: 5 }); cluster.add( 'replica1' , { host: 'mydb3.com' , user: 'myUser' , connectionLimit: 5 }); cluster.add( 'replica2' , { host: 'mydb4.com' , user: 'myUser' , connectionLimit: 5 });   // get 'write' connection : will retrieve in order by default const writeConn = cluster.getConnection( 'master*' );   // get 'read' connection : will retrieve in round-robin const readConn = cluster.getConnection( 'replica*' , 'RR' ); but there is no possibility using java connector
          diego dupin Diego Dupin added a comment - done in https://github.com/mariadb-corporation/mariadb-connector-j/commit/9c2db3bee043c71755a35ace70fde10c8fffa6a9 new HA mode is named "load-balance-read"

          People

            diego dupin Diego Dupin
            Bragolgirith Bragolgirith
            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.