Skip to content

Commit ae2a9f6

Browse files
committed
chore: address comments and fix linter issues
1 parent 6167281 commit ae2a9f6

16 files changed

Lines changed: 101 additions & 87 deletions

common/lib/connection_info.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/*
2-
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License").
5-
* You may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
2+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License").
5+
You may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
1616

1717
import { ClientWrapper } from "./client_wrapper";
1818

common/lib/host_list_provider/global_aurora_host_list_provider.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,13 @@ export class GlobalAuroraHostListProvider extends RdsHostListProvider {
5555
}
5656
};
5757

58-
return await this.servicesContainers
59-
.monitorService
60-
.runIfAbsent(ClusterTopologyMonitorImpl, this.clusterId, this.servicesContainers, this.properties, initializer);
58+
return await this.servicesContainers.monitorService.runIfAbsent(
59+
ClusterTopologyMonitorImpl,
60+
this.clusterId,
61+
this.servicesContainers,
62+
this.properties,
63+
initializer
64+
);
6165
}
6266

6367
override async getCurrentTopology(targetClient: ClientWrapper, dialect: DatabaseDialect): Promise<HostInfo[]> {

common/lib/host_list_provider/monitoring/cluster_topology_monitor.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ export class ClusterTopologyMonitorImpl extends AbstractMonitor implements Clust
389389
await this.closeHostMonitors();
390390

391391
if (!(hosts !== null && !this.isVerifiedWriterConnection)) {
392+
await this.delay(true);
392393
continue;
393394
}
394395

@@ -417,7 +418,7 @@ export class ClusterTopologyMonitorImpl extends AbstractMonitor implements Clust
417418
this.monitoringClient = writerClient;
418419
this.writerHostInfo = writerClientHostInfo;
419420
this.isVerifiedWriterConnection = true;
420-
this.highRefreshRateEndTimeNs = getTimeInNanos() + this.highRefreshRateEndTimeNs;
421+
this.highRefreshRateEndTimeNs = getTimeInNanos() + BigInt(this.highRefreshRateNs);
421422

422423
this.hostMonitorsStop = true;
423424
await this.closeHostMonitors();
@@ -426,14 +427,20 @@ export class ClusterTopologyMonitorImpl extends AbstractMonitor implements Clust
426427
this.readerTopologiesById.clear();
427428
this.completedOneCycle.clear();
428429

430+
await this.delay(true);
429431
continue;
430432
} else {
431433
// Update host monitors with the new instances in the topology.
432434
const hosts: HostInfo[] | null = this.hostMonitorsLatestTopology;
433435
if (hosts && !this.hostMonitorsStop) {
434436
hosts.forEach((hostInfo) => {
435437
if (!this.submittedHosts.get(hostInfo.host)) {
436-
const hostMonitor = new HostMonitor(this.servicesContainer, this, hostInfo, this.writerHostInfo);
438+
const minimalServiceContainer = ServiceUtils.instance.createMinimalServiceContainerFrom(
439+
this.servicesContainer,
440+
this._monitoringProperties
441+
);
442+
minimalServiceContainer.pluginManager.init();
443+
const hostMonitor = new HostMonitor(minimalServiceContainer, this, hostInfo, this.writerHostInfo);
437444
const promise = hostMonitor.run();
438445
this.submittedHosts.set(hostInfo.host, promise);
439446
}
@@ -462,6 +469,7 @@ export class ClusterTopologyMonitorImpl extends AbstractMonitor implements Clust
462469
await this.closeConnection(clientToClose);
463470
this.isVerifiedWriterConnection = false;
464471
this.writerHostInfo = null;
472+
await this.delay(false);
465473
continue;
466474
}
467475

@@ -725,9 +733,9 @@ export class HostMonitor {
725733
// Successfully updated the host monitor writer connection.
726734
logger.debug(Messages.get("HostMonitor.detectedWriter", this.hostInfo.hostId, this.hostInfo.url));
727735

728-
this.servicesContainer
729-
.importantEventService
730-
.registerEvent(() => Messages.get("HostMonitor.detectedWriter", this.hostInfo.hostId, this.hostInfo.url));
736+
this.servicesContainer.importantEventService.registerEvent(() =>
737+
Messages.get("HostMonitor.detectedWriter", this.hostInfo.hostId, this.hostInfo.url)
738+
);
731739

732740
await this.monitor.fetchTopologyAndUpdateCache(this.client);
733741
this.hostInfo.setAvailability(HostAvailability.AVAILABLE);

common/lib/plugin_service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { ErrorHandler } from "./error_handler";
1818
import { HostInfo } from "./host_info";
1919
import { AwsClient } from "./aws_client";
2020
import { HostListProviderService } from "./host_list_provider_service";
21-
import { HostListProvider } from "./host_list_provider/host_list_provider";
21+
import { DynamicHostListProvider, HostListProvider } from "./host_list_provider/host_list_provider";
2222
import { ConnectionUrlParser } from "./utils/connection_url_parser";
2323
import { DatabaseDialect, DatabaseType } from "./database_dialect/database_dialect";
2424
import { HostInfoBuilder } from "./host_info_builder";
@@ -315,7 +315,7 @@ export class PluginServiceImpl implements PluginService, HostListProviderService
315315
}
316316

317317
try {
318-
const updatedHostList: HostInfo[] = await (hostListProvider as any).forceMonitoringRefresh(shouldVerifyWriter, timeoutMs);
318+
const updatedHostList: HostInfo[] = await (hostListProvider as DynamicHostListProvider).forceMonitoringRefresh(shouldVerifyWriter, timeoutMs);
319319
if (updatedHostList) {
320320
this.updateHostAvailability(updatedHostList);
321321
await this.setHostList(this.hosts, updatedHostList);

common/lib/plugins/bluegreen/blue_green_plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export class BlueGreenPlugin extends AbstractConnectionPlugin implements CanRele
176176

177177
this.startTimeNano = getTimeInNanos();
178178

179-
while (routing && result && !result.isPresent()) {
179+
while (routing && (!result || !result.isPresent())) {
180180
result = await routing.apply(this, methodName, methodFunc, methodArgs, this.properties, this.pluginService);
181181
if (!result?.isPresent()) {
182182
this.bgStatus = this.pluginService.getStatus<BlueGreenStatus>(BlueGreenStatus, this.bgdId);

common/lib/plugins/bluegreen/blue_green_status_provider.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,10 @@ export class BlueGreenStatusProvider {
274274

275275
if (blueClusterHost !== null && greenClusterHost !== null) {
276276
if (!this.correspondingHosts.has(blueClusterHost)) {
277-
this.correspondingHosts.set(
278-
blueClusterHost,
279-
[this.hostInfoBuilder.withHost(blueClusterHost).build(), this.hostInfoBuilder.withHost(greenClusterHost).build()]
280-
);
277+
this.correspondingHosts.set(blueClusterHost, [
278+
this.hostInfoBuilder.withHost(blueClusterHost).build(),
279+
this.hostInfoBuilder.withHost(greenClusterHost).build()
280+
]);
281281
}
282282
}
283283

@@ -294,10 +294,10 @@ export class BlueGreenStatusProvider {
294294

295295
if (blueClusterReaderHost !== null && greenClusterReaderHost !== null) {
296296
if (!this.correspondingHosts.has(blueClusterReaderHost)) {
297-
this.correspondingHosts.set(
298-
blueClusterReaderHost,
299-
[this.hostInfoBuilder.withHost(blueClusterReaderHost).build(), this.hostInfoBuilder.withHost(greenClusterReaderHost).build()]
300-
);
297+
this.correspondingHosts.set(blueClusterReaderHost, [
298+
this.hostInfoBuilder.withHost(blueClusterReaderHost).build(),
299+
this.hostInfoBuilder.withHost(greenClusterReaderHost).build()
300+
]);
301301
}
302302
}
303303

@@ -314,10 +314,10 @@ export class BlueGreenStatusProvider {
314314
});
315315
if (greenHost) {
316316
if (!this.correspondingHosts.has(blueHost)) {
317-
this.correspondingHosts.set(
318-
blueHost,
319-
[this.hostInfoBuilder.withHost(blueHost).build(), this.hostInfoBuilder.withHost(greenHost).build()]
320-
);
317+
this.correspondingHosts.set(blueHost, [
318+
this.hostInfoBuilder.withHost(blueHost).build(),
319+
this.hostInfoBuilder.withHost(greenHost).build()
320+
]);
321321
}
322322
}
323323
}

common/lib/plugins/connection_tracker/aurora_connection_tracker_plugin_factory.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ export class AuroraConnectionTrackerPluginFactory extends ConnectionPluginFactor
2828
if (!AuroraConnectionTrackerPluginFactory.auroraConnectionTrackerPlugin) {
2929
AuroraConnectionTrackerPluginFactory.auroraConnectionTrackerPlugin = await import("./aurora_connection_tracker_plugin");
3030
}
31-
return new AuroraConnectionTrackerPluginFactory.auroraConnectionTrackerPlugin.AuroraConnectionTrackerPlugin(
32-
servicesContainer.pluginService
33-
);
31+
return new AuroraConnectionTrackerPluginFactory.auroraConnectionTrackerPlugin.AuroraConnectionTrackerPlugin(servicesContainer.pluginService);
3432
} catch (error: any) {
3533
throw new AwsWrapperError(Messages.get("ConnectionPluginChainBuilder.errorImportingPlugin", error.message, "AuroraConnectionTrackerPlugin"));
3634
}

common/lib/plugins/gdb_failover/global_db_failover_plugin.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ export class GlobalDbFailoverPlugin extends Failover2Plugin {
242242
this.failoverWriterSuccessCounter.inc();
243243
} catch (ex) {
244244
if (!(ex instanceof FailoverFailedError)) {
245+
// Counter has already been incremented in Failover2Plugin before throwing the FailoverFailedError.
246+
// So no need to increment again here.
245247
this.failoverWriterFailedCounter.inc();
246248
}
247249
throw ex;
@@ -316,7 +318,12 @@ export class GlobalDbFailoverPlugin extends Failover2Plugin {
316318
}
317319

318320
if (!candidateHost) {
319-
logger.debug(logTopology(remainingAllowedHosts, `${Messages.get("GlobalDbFailoverPlugin.candidateNull", String(verifyRole))} `));
321+
logger.debug(
322+
logTopology(
323+
remainingAllowedHosts,
324+
`${Messages.get("GlobalDbFailoverPlugin.unableToFindCandidateWithMatchingRole", String(verifyRole), this.failoverReaderHostSelectorStrategy)}`
325+
)
326+
);
320327
await sleep(100);
321328
break;
322329
}

common/lib/plugins/read_write_splitting/read_write_splitting_plugin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
3+
44
Licensed under the Apache License, Version 2.0 (the "License").
55
You may not use this file except in compliance with the License.
66
You may obtain a copy of the License at
7-
7+
88
http://www.apache.org/licenses/LICENSE-2.0
9-
9+
1010
Unless required by applicable law or agreed to in writing, software
1111
distributed under the License is distributed on an "AS IS" BASIS,
1212
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

common/lib/utils/important_event_service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
3+
44
Licensed under the Apache License, Version 2.0 (the "License").
55
You may not use this file except in compliance with the License.
66
You may obtain a copy of the License at
7-
7+
88
http://www.apache.org/licenses/LICENSE-2.0
9-
9+
1010
Unless required by applicable law or agreed to in writing, software
1111
distributed under the License is distributed on an "AS IS" BASIS,
1212
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

0 commit comments

Comments
 (0)