-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: failover2 #363
base: main
Are you sure you want to change the base?
feat: failover2 #363
Conversation
c4a4778
to
871729d
Compare
common/lib/host_list_provider/monitoring/cluster_topology_monitor.ts
Outdated
Show resolved
Hide resolved
common/lib/host_list_provider/monitoring/cluster_topology_monitor.ts
Outdated
Show resolved
Hide resolved
common/lib/host_list_provider/monitoring/cluster_topology_monitor.ts
Outdated
Show resolved
Hide resolved
common/lib/host_list_provider/monitoring/cluster_topology_monitor.ts
Outdated
Show resolved
Hide resolved
common/lib/host_list_provider/monitoring/cluster_topology_monitor.ts
Outdated
Show resolved
Hide resolved
common/lib/host_list_provider/monitoring/cluster_topology_monitor.ts
Outdated
Show resolved
Hide resolved
common/lib/host_list_provider/monitoring/cluster_topology_monitor.ts
Outdated
Show resolved
Hide resolved
common/lib/host_list_provider/monitoring/cluster_topology_monitor.ts
Outdated
Show resolved
Hide resolved
4a749c6
to
f86dc16
Compare
common/lib/host_list_provider/monitoring/monitoring_host_list_provider.ts
Outdated
Show resolved
Hide resolved
fix: integration tests apply review comments test: include rw integration tests fix: remove wrapper properties
94cee75
to
64dcca3
Compare
64dcca3
to
8d30bbf
Compare
let monitor: ClusterTopologyMonitor = MonitoringRdsHostListProvider.monitors.get( | ||
this.clusterId, | ||
MonitoringRdsHostListProvider.MONITOR_EXPIRATION_NANOS | ||
); | ||
if (!monitor) { | ||
monitor = this.initMonitor(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
computeIfAbsent
will check the map and create the item for the given key if item doesn't already exist. I don't think we need to call get here, then call computeIfAbsent in initMonitor. This implementation will check the map twice.
You could just call computeIfAbsent directly here
const monitor: ClusterTopologyMonitor = MonitoringRdsHostListProvider.monitors.computeIfAbsent(
this.clusterId,
(x) =>
new ClusterTopologyMonitorImpl(
this.clusterId,
MonitoringRdsHostListProvider.topologyCache,
this.initialHost,
this.properties,
this.pluginService,
this,
WrapperProperties.CLUSTER_TOPOLOGY_REFRESH_RATE_MS.get(this.properties),
WrapperProperties.CLUSTER_TOPOLOGY_HIGH_REFRESH_RATE_MS.get(this.properties)
),
MonitoringRdsHostListProvider.MONITOR_EXPIRATION_NANOS
);
async forceMonitoringRefresh(shouldVerifyWriter: boolean, timeoutMs: number): Promise<boolean> { | ||
const hostListProvider: HostListProvider = this.getHostListProvider(); | ||
if (!this.isBlockingHostListProvider(hostListProvider)) { | ||
throw new AwsWrapperError(Messages.get("PluginService.requiredMonitoringRdsHostListProvider"), typeof hostListProvider); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to update the error message to use BlockingHostListProvider
instead of MonitoringRdsHostListProvider
const updatedHostList: HostInfo[] = await (hostListProvider as MonitoringRdsHostListProvider).forceMonitoringRefresh( | ||
shouldVerifyWriter, | ||
timeoutMs | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need to cast it.
const updatedHostList: HostInfo[] = await (hostListProvider as MonitoringRdsHostListProvider).forceMonitoringRefresh( | |
shouldVerifyWriter, | |
timeoutMs | |
); | |
const updatedHostList: HostInfo[] = await hostListProvider.forceMonitoringRefresh(shouldVerifyWriter, timeoutMs); |
If you really need to cast it, use the interface not the implementation.
); | ||
} | ||
|
||
async updateTopology() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer used in the code, could remove this and relevant unit tests
// Call was initiated by Failover2 Plugin, does not require additional processing. | ||
if (props.has(Failover2Plugin.INTERNAL_CONNECT_PROPERTY_NAME)) { | ||
return await this._staleDnsHelper.getVerifiedConnection(hostInfo.host, isInitialConnection, this.hostListProviderService!, props, connectFunc); | ||
} | ||
|
||
// Failover is not enabled, does not require additional processing. | ||
if (!this.enableFailoverSetting || !WrapperProperties.ENABLE_CLUSTER_AWARE_FAILOVER.get(props)) { | ||
return await this._staleDnsHelper.getVerifiedConnection(hostInfo.host, isInitialConnection, this.hostListProviderService!, props, connectFunc); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Call was initiated by Failover2 Plugin, does not require additional processing. | |
if (props.has(Failover2Plugin.INTERNAL_CONNECT_PROPERTY_NAME)) { | |
return await this._staleDnsHelper.getVerifiedConnection(hostInfo.host, isInitialConnection, this.hostListProviderService!, props, connectFunc); | |
} | |
// Failover is not enabled, does not require additional processing. | |
if (!this.enableFailoverSetting || !WrapperProperties.ENABLE_CLUSTER_AWARE_FAILOVER.get(props)) { | |
return await this._staleDnsHelper.getVerifiedConnection(hostInfo.host, isInitialConnection, this.hostListProviderService!, props, connectFunc); | |
} | |
if ( | |
// Call was initiated by Failover2 Plugin, does not require additional processing. | |
props.has(Failover2Plugin.INTERNAL_CONNECT_PROPERTY_NAME) || | |
// Failover is not enabled, does not require additional processing. | |
!this.enableFailoverSetting || | |
!WrapperProperties.ENABLE_CLUSTER_AWARE_FAILOVER.get(props) | |
) { | |
return await this._staleDnsHelper.getVerifiedConnection(hostInfo.host, isInitialConnection, this.hostListProviderService!, props, connectFunc); | |
} |
Can we merge the checks to reduce code duplication
await this.failoverReader(); | ||
} | ||
|
||
if (this._isInTransaction || this.pluginService.isInTransaction()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this._isInTransaction
is set via this.pluginService.isInTransaction()
, and when we use it we check this.pluginService.isInTransaction()
anyway. Not sure if it is worth having this local variable.
logger.error(Messages.get("Failover.unableToConnectToWriter")); | ||
this.failoverWriterFailedCounter.inc(); | ||
throw new FailoverFailedError(Messages.get("Failover.unableToConnectToWriter")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we refactor this logic into a method to reduce duplicated code
private logAndThrowError(errorMessage: string) {
logger.error(errorMessage);
this.failoverWriterFailedCounter.inc();
throw new FailoverFailedError(errorMessage);
}
Summary
Description
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.