Skip to content
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

Merged
merged 1 commit into from
Apr 16, 2024
Merged

feat: failover plugin #20

merged 1 commit into from
Apr 16, 2024

Conversation

crystall-bitquill
Copy link
Contributor

Summary

Description

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@crystall-bitquill crystall-bitquill force-pushed the failover-plugin branch 3 times, most recently from 71f08bc to 61373ca Compare April 5, 2024 00:12
@crystall-bitquill crystall-bitquill added the ready for review Pull requests that are ready to be reviewed label Apr 5, 2024
@@ -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>;
Copy link
Contributor

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) {
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const currentClient = targetClient ? targetClient : this.hostListProviderService.getCurrentClient().targetClient;
const currentClient = targetClient ??: this.hostListProviderService.getCurrentClient().targetClient;

Comment on lines 163 to 164
this.hostList = results.hosts;
return Array.from(this.hostList);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
this.hostList = results.hosts;
return Array.from(this.hostList);
this.hostList = results.hosts;
return this.hostList;

Comment on lines 245 to 249
if (targetClient) {
await this.getDialect().tryClosingTargetClient(targetClient);
} else {
await this.getDialect().tryClosingTargetClient(this._currentClient.targetClient);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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 {
Copy link
Contributor

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?

Comment on lines 30 to 33
if (!value || value === "") {
return null;
}
return nameToValue.get(value.toLowerCase()) ?? null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!value || value === "") {
return null;
}
return nameToValue.get(value.toLowerCase()) ?? null;
return nameToValue.get(value?.toLowerCase()) ?? null;

Comment on lines 136 to 140
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;
}
Copy link
Contributor

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?

Suggested change
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;
}

Comment on lines 265 to 267
const res = methodFunc();
logger.debug(`Execution time for plugin ${this.id}: ${performance.now() - start} ms`);
return res;
Copy link
Contributor

@karenc-bq karenc-bq Apr 10, 2024

Choose a reason for hiding this comment

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

Suggested change
const res = methodFunc();
logger.debug(`Execution time for plugin ${this.id}: ${performance.now() - start} ms`);
return res;
return methodFunc();

Comment on lines 279 to 281
const res = await methodFunc();
logger.debug(`Execution time for plugin ${this.id}: ${performance.now() - start} ms`);
return res;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const res = await methodFunc();
logger.debug(`Execution time for plugin ${this.id}: ${performance.now() - start} ms`);
return res;
return await methodFunc();

@crystall-bitquill crystall-bitquill force-pushed the failover-plugin branch 4 times, most recently from b45ac3d to 1fdfba4 Compare April 16, 2024 17:23
@crystall-bitquill crystall-bitquill merged commit d67e13c into main Apr 16, 2024
1 check passed
@crystall-bitquill crystall-bitquill deleted the failover-plugin branch April 16, 2024 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review Pull requests that are ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants