Details
-
New Feature
-
Status: Closed (View Workflow)
-
Minor
-
Resolution: Fixed
-
None
-
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.