-
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: failover plugin #20
Conversation
71f08bc
to
61373ca
Compare
@@ -19,6 +19,9 @@ import { HostListProvider } from "./host_list_provider/host_list_provider"; | |||
import { HostListProviderService } from "./host_list_provider_service"; | |||
|
|||
export interface DatabaseDialect { | |||
getConnectFunc(newTargetClient: AwsClient): () => Promise<any>; |
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.
getConnectFunc
is good for Java where there's no promises. For Node.js/TypeScript is quite natural when a method name has no prefixes like Func
. We might consider review variable and method names to make them look more TypeScript natural. It could be a separate PR for that.
|
||
protected async internalPostConnect() { | ||
const info = this.pluginService.getCurrentHostInfo(); | ||
if (info != null) { |
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.
Does it make sense to move this.isConnected = true
in the connect methods to internalPostConnect? Since it is only ever called after a successful connect.
|
||
this.hostList = results.hosts; | ||
return Array.from(this.hostList); | ||
const currentClient = targetClient ? targetClient : this.hostListProviderService.getCurrentClient().targetClient; |
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.
const currentClient = targetClient ? targetClient : this.hostListProviderService.getCurrentClient().targetClient; | |
const currentClient = targetClient ?? this.hostListProviderService.getCurrentClient().targetClient; |
const currentClient = client ? client : this.hostListProviderService.getCurrentClient(); | ||
const results: FetchTopologyResult = await this.getTopology(currentClient, false); | ||
logger.debug(logTopology(results.hosts, results.isCachedData ? "[From cache]" : "")); | ||
const currentClient = targetClient ? targetClient : this.hostListProviderService.getCurrentClient().targetClient; |
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.
const currentClient = targetClient ? targetClient : this.hostListProviderService.getCurrentClient().targetClient; | |
const currentClient = targetClient ??: this.hostListProviderService.getCurrentClient().targetClient; |
this.hostList = results.hosts; | ||
return Array.from(this.hostList); |
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.hostList = results.hosts; | |
return Array.from(this.hostList); | |
this.hostList = results.hosts; | |
return this.hostList; |
common/lib/plugin_service.ts
Outdated
if (targetClient) { | ||
await this.getDialect().tryClosingTargetClient(targetClient); | ||
} else { | ||
await this.getDialect().tryClosingTargetClient(this._currentClient.targetClient); | ||
} |
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.
if (targetClient) { | |
await this.getDialect().tryClosingTargetClient(targetClient); | |
} else { | |
await this.getDialect().tryClosingTargetClient(this._currentClient.targetClient); | |
} | |
await this.getDialect().tryClosingTargetClient(targetClient ?? this._currentClient.targetClient); |
["reader-or-writer", FailoverMode.READER_OR_WRITER] | ||
]); | ||
|
||
export function failoverModeFromValue(value: string): FailoverMode | null { |
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.
Should we add an "Unknown" FailoverMode and return that instead of null to show more intent?
if (!value || value === "") { | ||
return null; | ||
} | ||
return nameToValue.get(value.toLowerCase()) ?? null; |
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.
if (!value || value === "") { | |
return null; | |
} | |
return nameToValue.get(value.toLowerCase()) ?? null; | |
return nameToValue.get(value?.toLowerCase()) ?? null; |
if (this._rdsUrlType.isRdsCluster) { | ||
this.failoverMode = this._rdsUrlType === RdsUrlType.RDS_READER_CLUSTER ? FailoverMode.READER_OR_WRITER : FailoverMode.STRICT_WRITER; | ||
} else { | ||
this.failoverMode = FailoverMode.STRICT_WRITER; | ||
} |
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.
Do you need to check for isRdsCluster here if you are not doing anything with other cluster types?
if (this._rdsUrlType.isRdsCluster) { | |
this.failoverMode = this._rdsUrlType === RdsUrlType.RDS_READER_CLUSTER ? FailoverMode.READER_OR_WRITER : FailoverMode.STRICT_WRITER; | |
} else { | |
this.failoverMode = FailoverMode.STRICT_WRITER; | |
} | |
if (this.failoverMode == null) { | |
this.failoverMode = this._rdsUrlType === RdsUrlType.RDS_READER_CLUSTER ? FailoverMode.READER_OR_WRITER : FailoverMode.STRICT_WRITER; | |
} |
const res = methodFunc(); | ||
logger.debug(`Execution time for plugin ${this.id}: ${performance.now() - start} ms`); | ||
return res; |
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.
const res = methodFunc(); | |
logger.debug(`Execution time for plugin ${this.id}: ${performance.now() - start} ms`); | |
return res; | |
return methodFunc(); |
const res = await methodFunc(); | ||
logger.debug(`Execution time for plugin ${this.id}: ${performance.now() - start} ms`); | ||
return res; |
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.
const res = await methodFunc(); | |
logger.debug(`Execution time for plugin ${this.id}: ${performance.now() - start} ms`); | |
return res; | |
return await methodFunc(); |
b45ac3d
to
1fdfba4
Compare
1fdfba4
to
898999d
Compare
Summary
Description
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.