Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/using-the-aws-driver/UsingTheAwsDriver.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ In addition to the parameters that you can configure for the [MySQL Connector/OD
| ---------------------------------- |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------|----------|------------------------------------------|
| `ENABLE_CLUSTER_FAILOVER` | Set to `1` to enable the fast failover behaviour offered by the AWS ODBC Driver for MySQL. | bool | No | `1` |
| `ALLOW_READER_CONNECTIONS` | Set to `1` to allow connections to reader instances during the failover process. | bool | No | `0` |
| `ENABLE_STRICT_READER_FAILOVER` | Set to `1` to only allow failover to reader nodes during the reader failover process. If enabled, reader failover to a writer node will only be allowed for single-node clusters. This parameter is only applicable when `ALLOW_READER_CONNECTIONS` is set to `1`. | bool | No | `0` |
| `GATHER_PERF_METRICS` | Set to `1` to record failover-associated metrics. | bool | No | `0` |
| `GATHER_PERF_METRICS_PER_INSTANCE` | Set to `1` to gather additional performance metrics per instance as well as cluster. | bool | No | `0` |
| `HOST_PATTERN` | This parameter is not required unless connecting to an AWS RDS cluster via an IP address or custom domain URL. In those cases, this parameter specifies the cluster instance DNS pattern that will be used to build a complete instance endpoint. A "?" character in this pattern should be used as a placeholder for the DB instance identifiers of the instances in the cluster. <br/><br/>Example: `?.my-domain.com`, `any-subdomain.?.my-domain.com:9999`<br/><br/>Usecase Example: If your cluster instance endpoint follows this pattern:`instanceIdentifier1.customHost`, `instanceIdentifier2.customHost`, etc. and you want your initial connection to be to `customHost:1234`, then your connection string should look like this: `SERVER=customHost;PORT=1234;DATABASE=test;HOST_PATTERN=?.customHost` <br><br/> If the provided connection string is not an IP address or custom domain, the driver will automatically acquire the cluster instance host pattern from the customer-provided connection string. | char\* | If connecting using an IP address or custom domain URL: Yes <br><br> Otherwise: No <br><br> See [Host Pattern](#host-pattern) for more details. | `NONE` |
Expand Down
2 changes: 2 additions & 0 deletions driver/failover.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class FAILOVER_READER_HANDLER {
std::shared_ptr<TOPOLOGY_SERVICE> topology_service,
std::shared_ptr<CONNECTION_HANDLER> connection_handler,
int failover_timeout_ms, int failover_reader_connect_timeout,
bool enable_strict_reader_failover,
unsigned long dbc_id, bool enable_logging = false);

~FAILOVER_READER_HANDLER();
Expand Down Expand Up @@ -100,6 +101,7 @@ class FAILOVER_READER_HANDLER {
std::shared_ptr<TOPOLOGY_SERVICE> topology_service;
std::shared_ptr<CONNECTION_HANDLER> connection_handler;
const int READER_CONNECT_INTERVAL_SEC = 1; // 1 sec
bool enable_strict_reader_failover = false;
std::shared_ptr<FILE> logger = nullptr;
unsigned long dbc_id = 0;
};
Expand Down
4 changes: 3 additions & 1 deletion driver/failover_reader_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ FAILOVER_READER_HANDLER::FAILOVER_READER_HANDLER(
std::shared_ptr<TOPOLOGY_SERVICE> topology_service,
std::shared_ptr<CONNECTION_HANDLER> connection_handler,
int failover_timeout_ms, int failover_reader_connect_timeout,
bool enable_strict_reader_failover,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When defining the FAILOVER_READER_HANDLER, did you pass this parameter to constructor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. The compiler didn't catch it because of the FAILOVER_READER_HANDLER constructor's optional argument.

unsigned long dbc_id, bool enable_logging)
: topology_service{topology_service},
connection_handler{connection_handler},
max_failover_timeout_ms{failover_timeout_ms},
reader_connect_timeout_ms{failover_reader_connect_timeout},
enable_strict_reader_failover{enable_strict_reader_failover},
dbc_id{dbc_id} {

if (enable_logging)
Expand All @@ -69,7 +71,7 @@ READER_FAILOVER_RESULT FAILOVER_READER_HANDLER::failover(
auto reader_result_future = std::async(std::launch::async, [=, &global_sync, &reader_result]() {
std::vector<std::shared_ptr<HOST_INFO>> hosts_list;
while (!global_sync.is_completed()) {
hosts_list = build_hosts_list(current_topology, true);
hosts_list = build_hosts_list(current_topology, !enable_strict_reader_failover);
reader_result = get_connection_from_hosts(hosts_list, global_sync);
if (reader_result.connected) {
global_sync.mark_as_complete(true);
Expand Down
1 change: 1 addition & 0 deletions installer/myodbc-installer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ int list_datasource_details(DataSource *ds)
/* Failover */
if (ds->enable_cluster_failover) printf("\tENABLE_CLUSTER_FAILOVER\n");
if (ds->allow_reader_connections) printf("\tALLOW_READER_CONNECTIONS\n");
if (ds->enable_strict_reader_failover) printf("\tENABLE_STRICT_READER_FAILOVER\n");
if (ds->gather_perf_metrics) printf("\tGATHER_PERF_METRICS\n");
if (ds->gather_metrics_per_instance) printf("\tGATHER_METRICS_PER_INSTANCE\n");
if (ds->topology_refresh_rate) printf("\tTOPOLOGY_REFRESH_RATE=%d\n", ds->topology_refresh_rate);
Expand Down
13 changes: 13 additions & 0 deletions setupgui/callbacks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ void syncTabsData(HWND hwnd, DataSource *params)
/* 4 - Failover */
GET_BOOL_TAB(FAILOVER_TAB, enable_cluster_failover);
GET_BOOL_TAB(FAILOVER_TAB, allow_reader_connections);
if (READ_BOOL_TAB(FAILOVER_TAB, allow_reader_connections))
{
GET_BOOL_TAB(FAILOVER_TAB, enable_strict_reader_failover);
}
GET_BOOL_TAB(FAILOVER_TAB, gather_perf_metrics);
if (READ_BOOL_TAB(FAILOVER_TAB, gather_perf_metrics))
{
Expand Down Expand Up @@ -445,6 +449,15 @@ void syncTabs(HWND hwnd, DataSource *params)
/* 4 - Failover */
SET_BOOL_TAB(FAILOVER_TAB, enable_cluster_failover);
SET_BOOL_TAB(FAILOVER_TAB, allow_reader_connections);
if (READ_BOOL_TAB(FAILOVER_TAB, allow_reader_connections))
{
#ifdef _WIN32
SET_ENABLED(FAILOVER_TAB, IDC_CHECK_enable_strict_reader_failover, TRUE);
#endif
SET_CHECKED_TAB(FAILOVER_TAB, allow_reader_connections, TRUE);
SET_BOOL_TAB(FAILOVER_TAB, enable_strict_reader_failover);
}
SET_BOOL_TAB(FAILOVER_TAB, enable_strict_reader_failover);
SET_BOOL_TAB(FAILOVER_TAB, gather_perf_metrics);
if(READ_BOOL_TAB(FAILOVER_TAB, gather_perf_metrics))
{
Expand Down
12 changes: 12 additions & 0 deletions setupgui/windows/odbcdialogparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,18 @@ void FormMain_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
EnableWindow(secret_id, usingSecretsManager);
}
break;
case IDC_CHECK_allow_reader_connections:
{
HWND failoverTab = TabCtrl_1.hTabPages[FAILOVER_TAB - 1];
assert(failoverTab);
HWND prefetch = GetDlgItem(failoverTab, IDC_CHECK_enable_strict_reader_failover);
assert(prefetch);

EnableWindow(prefetch, !!Button_GetCheck(GetDlgItem(failoverTab,
IDC_CHECK_allow_reader_connections)));
setBoolFieldData(failoverTab, IDC_CHECK_enable_strict_reader_failover, Button_GetCheck(prefetch));
}
break;
case IDC_CHECK_gather_perf_metrics:
{
HWND failoverTab = TabCtrl_1.hTabPages[FAILOVER_TAB-1];
Expand Down
40 changes: 21 additions & 19 deletions setupgui/windows/odbcdialogparams.rc
Original file line number Diff line number Diff line change
Expand Up @@ -218,28 +218,30 @@ BEGIN
"Button",BS_AUTOCHECKBOX | WS_TABSTOP, 12, 12, 89, 10
CONTROL "&Allow reader connections", IDC_CHECK_allow_reader_connections,
"Button", BS_AUTOCHECKBOX | WS_TABSTOP, 12, 27, 100, 10
CONTROL "&Enable strict reader failover", IDC_CHECK_enable_strict_reader_failover,
"Button", BS_AUTOCHECKBOX | WS_TABSTOP | WS_DISABLED, 132, 27, 100, 10
CONTROL "&Gather performance metrics",IDC_CHECK_gather_perf_metrics,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP, 12, 42, 100, 10
CONTROL "&Gather instance-specific metrics",IDC_CHECK_gather_metrics_per_instance,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP | WS_DISABLED, 12, 57, 115, 10
RTEXT "&Host pattern:",IDC_STATIC,12,75,117,8
EDITTEXT IDC_EDIT_host_pattern,132,73,196,12,ES_AUTOHSCROLL
RTEXT "&Cluster ID:",IDC_STATIC,12,90,116,8
EDITTEXT IDC_EDIT_cluster_id,132,88,196,12,ES_AUTOHSCROLL
RTEXT "Topology refresh rate (ms):",IDC_STATIC,12,105,116,8
EDITTEXT IDC_EDIT_topology_refresh_rate,132,103,64,12,ES_AUTOHSCROLL | ES_NUMBER
RTEXT "Failover timeout (ms):",IDC_STATIC,12,120,116,8
EDITTEXT IDC_EDIT_failover_timeout,132,118,64,12,ES_AUTOHSCROLL | ES_NUMBER
RTEXT "Failover topology refresh rate (ms):",IDC_STATIC,11,135,117,8
EDITTEXT IDC_EDIT_failover_topology_refresh_rate,132,133,64,12,ES_AUTOHSCROLL | ES_NUMBER
RTEXT "Writer reconnect interval (ms):",IDC_STATIC,11,150,117,8
EDITTEXT IDC_EDIT_failover_writer_reconnect_interval,132,148,64,12,ES_AUTOHSCROLL | ES_NUMBER
RTEXT "Reader connect timeout (ms):",IDC_STATIC,11,165,117,8
EDITTEXT IDC_EDIT_failover_reader_connect_timeout,132,162,64,12,ES_AUTOHSCROLL | ES_NUMBER
RTEXT "Host Connect timeout (s):",IDC_STATIC,11,180,117,8
EDITTEXT IDC_EDIT_connect_timeout,132,178,64,12,ES_AUTOHSCROLL | ES_NUMBER
RTEXT "Host Read/Write timeout (s):",IDC_STATIC,11,195,117,8
EDITTEXT IDC_EDIT_network_timeout,132,193,64,12,ES_AUTOHSCROLL | ES_NUMBER
"Button",BS_AUTOCHECKBOX | WS_TABSTOP | WS_DISABLED, 132, 42, 115, 10
RTEXT "&Host pattern:",IDC_STATIC,12,60,117,8
EDITTEXT IDC_EDIT_host_pattern,132,58,196,12,ES_AUTOHSCROLL
RTEXT "&Cluster ID:",IDC_STATIC,12,77,116,8
EDITTEXT IDC_EDIT_cluster_id,132,75,196,12,ES_AUTOHSCROLL
RTEXT "Topology refresh rate (ms):",IDC_STATIC,12,94,116,8
EDITTEXT IDC_EDIT_topology_refresh_rate,132,92,64,12,ES_AUTOHSCROLL | ES_NUMBER
RTEXT "Failover timeout (ms):",IDC_STATIC,12,111,116,8
EDITTEXT IDC_EDIT_failover_timeout,132,109,64,12,ES_AUTOHSCROLL | ES_NUMBER
RTEXT "Failover topology refresh rate (ms):",IDC_STATIC,11,128,117,8
EDITTEXT IDC_EDIT_failover_topology_refresh_rate,132,126,64,12,ES_AUTOHSCROLL | ES_NUMBER
RTEXT "Writer reconnect interval (ms):",IDC_STATIC,11,145,117,8
EDITTEXT IDC_EDIT_failover_writer_reconnect_interval,132,143,64,12,ES_AUTOHSCROLL | ES_NUMBER
RTEXT "Reader connect timeout (ms):",IDC_STATIC,11,162,117,8
EDITTEXT IDC_EDIT_failover_reader_connect_timeout,132,160,64,12,ES_AUTOHSCROLL | ES_NUMBER
RTEXT "Host Connect timeout (s):",IDC_STATIC,11,179,117,8
EDITTEXT IDC_EDIT_connect_timeout,132,177,64,12,ES_AUTOHSCROLL | ES_NUMBER
RTEXT "Host Read/Write timeout (s):",IDC_STATIC,11,196,117,8
EDITTEXT IDC_EDIT_network_timeout,132,194,64,12,ES_AUTOHSCROLL | ES_NUMBER
END

#if MFA_ENABLED
Expand Down
1 change: 1 addition & 0 deletions setupgui/windows/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
#define IDC_EDIT_connect_timeout 10086
#define IDC_EDIT_network_timeout 10087
#define IDC_CHECK_allow_reader_connections 10088
#define IDC_CHECK_enable_strict_reader_failover 10089
#define IDC_CHECK_enable_failure_detection 10100
#define IDC_EDIT_failure_detection_time 10101
#define IDC_EDIT_failure_detection_interval 10102
Expand Down
16 changes: 8 additions & 8 deletions unit_testing/failover_reader_handler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ TEST_F(FailoverReaderHandlerTest, GenerateTopology) {
}

TEST_F(FailoverReaderHandlerTest, BuildHostsList) {
FAILOVER_READER_HANDLER reader_handler(mock_ts, mock_connection_handler, 60000, 30000, 0);
FAILOVER_READER_HANDLER reader_handler(mock_ts, mock_connection_handler, 60000, 30000, false, 0);
std::shared_ptr<CLUSTER_TOPOLOGY_INFO> topology_info;
std::vector<std::shared_ptr<HOST_INFO>> hosts_list;

Expand Down Expand Up @@ -227,7 +227,7 @@ TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_Failure) {
EXPECT_CALL(*mock_ts, mark_host_down(reader_c_host)).Times(1);
EXPECT_CALL(*mock_ts, mark_host_down(writer_host)).Times(1);

FAILOVER_READER_HANDLER reader_handler(mock_ts, mock_connection_handler, 60000, 30000, 0);
FAILOVER_READER_HANDLER reader_handler(mock_ts, mock_connection_handler, 60000, 30000, false, 0);
auto hosts_list = reader_handler.build_hosts_list(topology, true);
READER_FAILOVER_RESULT result = reader_handler.get_connection_from_hosts(hosts_list, std::ref(mock_sync));

Expand All @@ -250,7 +250,7 @@ TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_Success_Reader) {
// Reader C will not be used as it is put at the end. Will only try to connect to A and B
EXPECT_CALL(*mock_ts, mark_host_up(reader_a_host)).Times(1);

FAILOVER_READER_HANDLER reader_handler(mock_ts, mock_connection_handler, 60000, 30000, 0);
FAILOVER_READER_HANDLER reader_handler(mock_ts, mock_connection_handler, 60000, 30000, false, 0);
auto hosts_list = reader_handler.build_hosts_list(topology, true);
READER_FAILOVER_RESULT result = reader_handler.get_connection_from_hosts(hosts_list, std::ref(mock_sync));

Expand All @@ -276,7 +276,7 @@ TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_Success_Writer) {

EXPECT_CALL(*mock_ts, mark_host_up(writer_host)).Times(1);

FAILOVER_READER_HANDLER reader_handler(mock_ts, mock_connection_handler, 60000, 30000, 0);
FAILOVER_READER_HANDLER reader_handler(mock_ts, mock_connection_handler, 60000, 30000, false, 0);
auto hosts_list = reader_handler.build_hosts_list(topology, true);
READER_FAILOVER_RESULT result = reader_handler.get_connection_from_hosts(hosts_list, std::ref(mock_sync));

Expand Down Expand Up @@ -313,7 +313,7 @@ TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_FastestHost) {
return mock_reader_b_proxy;
}));

FAILOVER_READER_HANDLER reader_handler(mock_ts, mock_connection_handler, 60000, 30000, 0);
FAILOVER_READER_HANDLER reader_handler(mock_ts, mock_connection_handler, 60000, 30000, false, 0);
auto hosts_list = reader_handler.build_hosts_list(topology, true);
READER_FAILOVER_RESULT result = reader_handler.get_connection_from_hosts(hosts_list, std::ref(mock_sync));

Expand Down Expand Up @@ -352,7 +352,7 @@ TEST_F(FailoverReaderHandlerTest, GetConnectionFromHosts_Timeout) {
EXPECT_CALL(*mock_ts, mark_host_down(_)).Times(AnyNumber());
EXPECT_CALL(*mock_ts, mark_host_down(writer_host)).Times(1);

FAILOVER_READER_HANDLER reader_handler(mock_ts, mock_connection_handler, 60000, 1000, 0);
FAILOVER_READER_HANDLER reader_handler(mock_ts, mock_connection_handler, 60000, 1000, false, 0);
auto hosts_list = reader_handler.build_hosts_list(topology, true);
READER_FAILOVER_RESULT result = reader_handler.get_connection_from_hosts(hosts_list, std::ref(mock_sync));

Expand All @@ -372,7 +372,7 @@ TEST_F(FailoverReaderHandlerTest, Failover_Failure) {
EXPECT_CALL(*mock_ts, mark_host_down(reader_c_host)).Times(1);
EXPECT_CALL(*mock_ts, mark_host_down(writer_host)).Times(1);

FAILOVER_READER_HANDLER reader_handler(mock_ts, mock_connection_handler, 3000, 1000, 0);
FAILOVER_READER_HANDLER reader_handler(mock_ts, mock_connection_handler, 3000, 1000, false, 0);
READER_FAILOVER_RESULT result = reader_handler.failover(topology);

EXPECT_FALSE(result.connected);
Expand Down Expand Up @@ -409,7 +409,7 @@ TEST_F(FailoverReaderHandlerTest, Failover_Success_Reader) {
return mock_reader_b_proxy;
}));

FAILOVER_READER_HANDLER reader_handler(mock_ts, mock_connection_handler, 60000, 30000, 0);
FAILOVER_READER_HANDLER reader_handler(mock_ts, mock_connection_handler, 60000, 30000, false, 0);
READER_FAILOVER_RESULT result = reader_handler.failover(current_topology);

EXPECT_TRUE(result.connected);
Expand Down
2 changes: 1 addition & 1 deletion unit_testing/mock_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class MOCK_TOPOLOGY_SERVICE : public TOPOLOGY_SERVICE {

class MOCK_READER_HANDLER : public FAILOVER_READER_HANDLER {
public:
MOCK_READER_HANDLER() : FAILOVER_READER_HANDLER(nullptr, nullptr, 0, 0, 0) {}
MOCK_READER_HANDLER() : FAILOVER_READER_HANDLER(nullptr, nullptr, 0, 0, false, 0) {}
MOCK_METHOD(READER_FAILOVER_RESULT, get_reader_connection,
(std::shared_ptr<CLUSTER_TOPOLOGY_INFO>, FAILOVER_SYNC&));
};
Expand Down
Loading