Skip to content

Commit

Permalink
feat: read-write splitting plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
joyc-bq committed May 10, 2024
1 parent 77ea4d0 commit da2bc0a
Show file tree
Hide file tree
Showing 8 changed files with 745 additions and 5 deletions.
4 changes: 3 additions & 1 deletion common/lib/connection_plugin_chain_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { ExecuteTimePluginFactory } from "./plugins/execute_time_plugin";
import { ConnectTimePluginFactory } from "./plugins/connect_time_plugin";
import { AwsSecretsManagerPluginFactory } from "./authentication/aws_secrets_manager_plugin";
import { ConnectionProvider } from "./connection_provider";
import { ReadWriteSplittingPluginFactory } from "./plugins/read_write_splitting";

export class PluginFactoryInfo {}

Expand All @@ -40,7 +41,8 @@ export class ConnectionPluginChainBuilder {
["executeTime", ExecuteTimePluginFactory],
["connectTime", ConnectTimePluginFactory],
["secretsManager", AwsSecretsManagerPluginFactory],
["failover", FailoverPluginFactory]
["failover", FailoverPluginFactory],
["readWriteSplitting", ReadWriteSplittingPluginFactory]
]);

getPlugins(
Expand Down
6 changes: 5 additions & 1 deletion common/lib/host_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class HostInfo {
private readonly _host: string;
private readonly _port: number;
private _availability: HostAvailability;
private readonly _role: HostRole;
private _role: HostRole;
protected aliases: Set<string> = new Set<string>();
private _allAliases: Set<string> = new Set<string>();
private readonly _weight: number; // Greater or equal 0. Lesser the weight, the healthier node.
Expand Down Expand Up @@ -129,6 +129,10 @@ export class HostInfo {
return this._role;
}

set role(value: HostRole) {
this._role = value;
}

get allAliases(): Set<string> {
return this._allAliases;
}
Expand Down
9 changes: 9 additions & 0 deletions common/lib/plugin_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ export class PluginService implements ErrorHandler, HostListProviderService {
return false;
}

acceptsStrategy(role: HostRole, strategy: string): boolean {
return this.pluginServiceManagerContainer.pluginManager?.acceptsStrategy(role, strategy) ?? false;
}

async forceRefreshHostList(): Promise<void>;
async forceRefreshHostList(client?: AwsClient): Promise<void>;
async forceRefreshHostList(client?: AwsClient): Promise<void> {
Expand Down Expand Up @@ -222,6 +226,11 @@ export class PluginService implements ErrorHandler, HostListProviderService {
throw new AwsWrapperError("AwsClient is missing create target client function."); // This should not be reached
}

getHostInfoByStrategy(role: HostRole, strategy: string): HostInfo | undefined {
const pluginManager = this.pluginServiceManagerContainer.pluginManager;
return pluginManager?.getHostInfoByStrategy(role, strategy);
}

connect<T>(hostInfo: HostInfo, props: Map<string, any>, connectFunc: () => Promise<T>) {
if (connectFunc) {
return this.pluginServiceManagerContainer.pluginManager?.connect(hostInfo, props, false, connectFunc);
Expand Down
Loading

0 comments on commit da2bc0a

Please sign in to comment.