Closed niveathika closed 2 years ago
LGTM. The only concern I have is the name Option
is too generic. Do we follow a similar naming convention in other DB modules?. For instance, in I/O we follow a specific naming for each option as in here.
There is only one option as there is only one SQL client, if we introduce more options, the init functions will have a lot of optional records configurations.
Shouldn't we allow to define the access mode for failover? Whether the failover is readonly or read/write both?
@anupama-pathirage Seems I missed it in the initial proposal. I have now updated it to include the failOveryReadOnly
flag.
Few suggestions on naming convenntion.
Change ServerFailover
record name to FailoverConfig
- Seems it is matching with current standard lib conventions like http:CacheConfig
, http:RetryConfig` etc.
Instead of [string, int] [] define a record as FailoverServer
and use record arrays?
Change the field name of Options
as failoverConfig
instead of failover
?
Change the failOverReadOnly
to failoverReadOnly
Definitions
public type FailoverConfig record {|
FailoverServer[] failoverServers;
int timeBeforeRetry?;
int queriesBeforeRetry?;
boolean failoverReadOnly = true;
|};
public type FailoverServer record {|
string host;
int port;
|};
public type Options record {|
FailoverConfig failoverConfig?;
|};
Usage
Options option = {
failoverConfig: {
failoverServers: [
{
host: "localhost",
port: 5506
},
{
host: "x.x.x.x",
port: 5506
}
],
queriesBeforeRetry: 100,
timeBeforeRetry: 100,
failOverReadOnly: true
}
};
@anupama-pathirage I have updated the proposal to include all the naming streamlining as suggested.
As per the offline discussion with @anupama-pathirage, I am going ahead with the latest design.
Accepted proposal added in https://github.com/ballerina-platform/module-ballerinax-mysql/pull/268
Summary
Currently, the ballerina SQL client can only connect to one MySQL server. The user has to handle connection errors by switching to the secondary replicated database or retrying. We can support MySQL server failovers so that the user does not need to maintain multiple clients to switch between secondary databases.
Goals
Allow ballerina client to connect to secondary databases in case of connection errors using the MySQL server Failover feature.
Motivation
The user can easily connect between database replicas without using complex logic.
Description
FailoverConfig
configuration will be introduced tomysql:Options
.Failover configuration usage will be,
Testing
Since a replication MySQL server is needed as a prerequisite for testing, this feature is manually tested. A docker-based MySQL replication is used for testing. Prerequisite Reference
After the docker images are set up following code can be used for testing,
While the program is sleeping master node should be shut down to verify the failover.
Reference
MySQL Server Failover