From 9a226f72dcdd1a523baa5841d8d24c3c28684c18 Mon Sep 17 00:00:00 2001 From: joyc-bq Date: Tue, 7 Jan 2025 13:31:30 -0800 Subject: [PATCH] throw failover success --- .../lib/plugins/failover/failover_plugin.ts | 19 +++++-------------- tests/unit/failover_plugin.test.ts | 13 +++++++------ 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/common/lib/plugins/failover/failover_plugin.ts b/common/lib/plugins/failover/failover_plugin.ts index 80c59a07..638c3ee4 100644 --- a/common/lib/plugins/failover/failover_plugin.ts +++ b/common/lib/plugins/failover/failover_plugin.ts @@ -345,17 +345,7 @@ export class FailoverPlugin extends AbstractConnectionPlugin { } else { await this.failoverReader(failedHost); } - - if (this._isInTransaction || this.pluginService.isInTransaction()) { - // "Transaction resolution unknown. Please re-configure session state if required and try - // restarting transaction." - logger.debug(Messages.get("Failover.transactionResolutionUnknownError")); - throw new TransactionResolutionUnknownError(Messages.get("Failover.transactionResolutionUnknownError")); - } else { - // "The active SQL connection has changed due to a connection failure. Please re-configure - // session state if required." - throw new FailoverSuccessError(Messages.get("Failover.connectionChangedError")); - } + this.throwFailoverSuccessError(); } async failoverReader(failedHostInfo: HostInfo) { @@ -393,7 +383,7 @@ export class FailoverPlugin extends AbstractConnectionPlugin { await this.pluginService.setCurrentClient(result.client, result.newHost); this.pluginService.getCurrentHostInfo()?.removeAlias(Array.from(oldAliases)); await this.updateTopology(true); - await this.throwFailoverSuccessError(); + this.failoverWriterSuccessCounter.inc(); } catch (error: any) { this.failoverReaderFailedCounter.inc(); throw error; @@ -406,7 +396,7 @@ export class FailoverPlugin extends AbstractConnectionPlugin { } } - async throwFailoverSuccessError() { + throwFailoverSuccessError() { if (this._isInTransaction || this.pluginService.isInTransaction()) { this.pluginService.setInTransaction(false); @@ -455,7 +445,8 @@ export class FailoverPlugin extends AbstractConnectionPlugin { await this.pluginService.setCurrentClient(result.client, writerHostInfo); logger.debug(Messages.get("Failover.establishedConnection", this.pluginService.getCurrentHostInfo()?.host ?? "")); await this.pluginService.refreshHostList(); - await this.throwFailoverSuccessError(); + this.throwFailoverSuccessError(); + this.failoverWriterSuccessCounter.inc(); } catch (error: any) { this.failoverWriterFailedCounter.inc(); throw error; diff --git a/tests/unit/failover_plugin.test.ts b/tests/unit/failover_plugin.test.ts index a4a87b95..7a0c98c8 100644 --- a/tests/unit/failover_plugin.test.ts +++ b/tests/unit/failover_plugin.test.ts @@ -36,9 +36,10 @@ import { AwsMySQLClient } from "../../mysql/lib"; import { anything, instance, mock, reset, resetCalls, spy, verify, when } from "ts-mockito"; import { Messages } from "../../common/lib/utils/messages"; import { HostChangeOptions } from "../../common/lib/host_change_options"; -import { ClientWrapper } from "../../common/lib/client_wrapper"; import { NullTelemetryFactory } from "../../common/lib/utils/telemetry/null_telemetry_factory"; import { MySQLClientWrapper } from "../../common/lib/mysql_client_wrapper"; +import { DriverDialect } from "../../common/lib/driver_dialect/driver_dialect"; +import { MySQL2DriverDialect } from "../../mysql/lib/dialect/mysql2_driver_dialect"; const builder = new HostInfoBuilder({ hostAvailabilityStrategy: new SimpleHostAvailabilityStrategy() }); @@ -196,7 +197,7 @@ describe("reader failover handler", () => { const hostInfo = builder.withHost("hostA").build(); const hosts = [hostInfo]; - when(mockHostInfo.allAliases).thenReturn(new Set(["alias1", "aslias2"])); + when(mockHostInfo.allAliases).thenReturn(new Set(["alias1", "alias2"])); when(mockHostInfo.getRawAvailability()).thenReturn(HostAvailability.AVAILABLE); when(mockPluginService.getHosts()).thenReturn(hosts); when(await mockPluginService.getHostRole(anything())).thenReturn(HostRole.WRITER); @@ -231,7 +232,7 @@ describe("reader failover handler", () => { const hosts = [hostInfo]; const test = new AwsWrapperError("test"); - when(mockHostInfo.allAliases).thenReturn(new Set(["alias1", "aslias2"])); + when(mockHostInfo.allAliases).thenReturn(new Set(["alias1", "alias2"])); when(mockHostInfo.getRawAvailability()).thenReturn(HostAvailability.AVAILABLE); when(mockPluginService.getHosts()).thenReturn(hosts); when(mockReaderResult.exception).thenReturn(test); @@ -255,7 +256,7 @@ describe("reader failover handler", () => { const hosts = [hostInfo]; const test = new AwsWrapperError("test"); - when(mockHostInfo.allAliases).thenReturn(new Set(["alias1", "aslias2"])); + when(mockHostInfo.allAliases).thenReturn(new Set(["alias1", "alias2"])); when(mockPluginService.getHosts()).thenReturn(hosts); when(mockWriterResult.exception).thenReturn(test); when(mockWriterFailoverHandler.failover(anything())).thenResolve(instance(mockWriterResult)); @@ -276,7 +277,7 @@ describe("reader failover handler", () => { const hostInfo = builder.withHost("hostA").build(); const hosts = [hostInfo]; - when(mockHostInfo.allAliases).thenReturn(new Set(["alias1", "aslias2"])); + when(mockHostInfo.allAliases).thenReturn(new Set(["alias1", "alias2"])); when(mockPluginService.getHosts()).thenReturn(hosts); when(mockWriterResult.isConnected).thenReturn(false); when(mockWriterFailoverHandler.failover(anything())).thenResolve(instance(mockWriterResult)); @@ -306,7 +307,7 @@ describe("reader failover handler", () => { const hostInfo = builder.withHost("hostA").build(); const hosts = [hostInfo]; - when(mockHostInfo.allAliases).thenReturn(new Set(["alias1", "aslias2"])); + when(mockHostInfo.allAliases).thenReturn(new Set(["alias1", "alias2"])); when(mockPluginService.getHosts()).thenReturn(hosts); when(mockWriterResult.isConnected).thenReturn(false); when(mockWriterResult.topology).thenReturn(hosts);