Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/integration_tests_latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches:
- main
- fix/parameterized-queries
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will remove before merging

paths-ignore:
- "**/*.md"
- "**/*.jpg"
Expand Down
10 changes: 6 additions & 4 deletions common/lib/aws_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { HostListProvider } from "./host_list_provider/host_list_provider";
import { PluginManager } from "./plugin_manager";

import pkgStream from "stream";
import { DriverConnectionProvider } from "./driver_connection_provider";
import { ClientWrapper } from "./client_wrapper";
import { ConnectionProviderManager } from "./connection_provider_manager";
import { DefaultTelemetryFactory } from "./utils/telemetry/default_telemetry_factory";
Expand All @@ -35,10 +34,12 @@ import { AwsWrapperError } from "./utils/errors";
import { Messages } from "./utils/messages";
import { TransactionIsolationLevel } from "./utils/transaction_isolation_level";
import { HostListProviderService } from "./host_list_provider_service";
import { SessionStateClient } from "./session_state_client";
import { ConnectionProvider } from "./connection_provider";

const { EventEmitter } = pkgStream;

export abstract class AwsClient extends EventEmitter {
export abstract class AwsClient extends EventEmitter implements SessionStateClient {
private _defaultPort: number = -1;
protected telemetryFactory: TelemetryFactory;
protected pluginManager: PluginManager;
Expand All @@ -55,7 +56,8 @@ export abstract class AwsClient extends EventEmitter {
dbType: DatabaseType,
knownDialectsByCode: Map<string, DatabaseDialect>,
parser: ConnectionUrlParser,
driverDialect: DriverDialect
driverDialect: DriverDialect,
connectionProvider: ConnectionProvider
) {
super();
this.config = config;
Expand Down Expand Up @@ -110,7 +112,7 @@ export abstract class AwsClient extends EventEmitter {
this.pluginManager = new PluginManager(
container,
this.properties,
new ConnectionProviderManager(new DriverConnectionProvider(), WrapperProperties.CONNECTION_PROVIDER.get(this.properties)),
new ConnectionProviderManager(connectionProvider, WrapperProperties.CONNECTION_PROVIDER.get(this.properties)),
this.telemetryFactory
);
}
Expand Down
2 changes: 2 additions & 0 deletions common/lib/client_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export interface ClientWrapper {
readonly properties: Map<string, any>;
readonly id: string;

// Internal method, executes wrapper-specific queries like the topology query.
query(sql: string): Promise<any>;
query(config: any, values?: any, callback?: any): Promise<any>;

end(): Promise<void>;

Expand Down
2 changes: 2 additions & 0 deletions common/lib/driver_dialect/driver_dialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ export interface DriverDialect {
setQueryTimeout(props: Map<string, any>, sql?: any, wrapperConnectTimeout?: any): void;

setKeepAliveProperties(props: Map<string, any>, keepAliveProps: any): void;

getQueryFromMethodArg(methodArg: any): string;
}
2 changes: 1 addition & 1 deletion common/lib/host_list_provider_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { DatabaseDialect } from "./database_dialect/database_dialect";
import { HostInfoBuilder } from "./host_info_builder";
import { ConnectionUrlParser } from "./utils/connection_url_parser";
import { TelemetryFactory } from "./utils/telemetry/telemetry_factory";
import { AllowedAndBlockedHosts } from "./AllowedAndBlockedHosts";
import { AllowedAndBlockedHosts } from "./allowed_and_blocked_hosts";

export interface HostListProviderService {
getHostListProvider(): HostListProvider | null;
Expand Down
4 changes: 2 additions & 2 deletions common/lib/pg_client_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export class PgClientWrapper implements ClientWrapper {
this.id = uniqueId("PgClient_");
}

query(sql: string): Promise<any> {
return this.client?.query(sql);
query(config: any, values?: any, callback?: any): Promise<any> {
return this.client?.query(config, values, callback);
}

queryWithTimeout(sql: string): Promise<any> {
Expand Down
2 changes: 1 addition & 1 deletion common/lib/plugin_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { DatabaseDialectCodes } from "./database_dialect/database_dialect_codes"
import { getWriter, logTopology } from "./utils/utils";
import { TelemetryFactory } from "./utils/telemetry/telemetry_factory";
import { DriverDialect } from "./driver_dialect/driver_dialect";
import { AllowedAndBlockedHosts } from "./AllowedAndBlockedHosts";
import { AllowedAndBlockedHosts } from "./allowed_and_blocked_hosts";
import { ConnectionPlugin } from "./connection_plugin";

export interface PluginService extends ErrorHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { PluginService } from "../../plugin_service";
import { TelemetryCounter } from "../../utils/telemetry/telemetry_counter";
import { logger } from "../../../logutils";
import { CustomEndpointInfo } from "./custom_endpoint_info";
import { AllowedAndBlockedHosts } from "../../AllowedAndBlockedHosts";
import { AllowedAndBlockedHosts } from "../../allowed_and_blocked_hosts";
import { CacheMap } from "../../utils/cache_map";
import { MemberListType } from "./member_list_type";
import { Messages } from "../../utils/messages";
Expand Down
2 changes: 1 addition & 1 deletion common/lib/plugins/read_write_splitting_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class ReadWriteSplittingPlugin extends AbstractConnectionPlugin implement
}

override async execute<T>(methodName: string, executeFunc: () => Promise<T>, methodArgs: any): Promise<T> {
const statement = methodArgs.sql ?? methodArgs;
const statement = SqlMethodUtils.parseMethodArgs(methodArgs, this.pluginService.getDriverDialect());
const statements = SqlMethodUtils.parseMultiStatementQueries(statement);

const updateReadOnly: boolean | undefined = SqlMethodUtils.doesSetReadOnly(statements, this.pluginService.getDialect());
Expand Down
39 changes: 39 additions & 0 deletions common/lib/session_state_client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { TransactionIsolationLevel } from "./utils/transaction_isolation_level";

export interface SessionStateClient {
setReadOnly(readOnly: boolean): Promise<any | void>;

isReadOnly(): boolean;

setAutoCommit(autoCommit: boolean): Promise<any | void>;

getAutoCommit(): boolean;

setTransactionIsolation(level: TransactionIsolationLevel): Promise<any | void>;

getTransactionIsolation(): TransactionIsolationLevel;

setSchema(schema: any): Promise<any | void>;

getSchema(): string;

setCatalog(catalog: string): Promise<any | void>;

getCatalog(): string;
}
14 changes: 14 additions & 0 deletions common/lib/utils/sql_method_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import { DatabaseDialect } from "../database_dialect/database_dialect";
import { TransactionIsolationLevel } from "./transaction_isolation_level";
import { DriverDialect } from "../driver_dialect/driver_dialect";

export class SqlMethodUtils {
static doesOpenTransaction(sql: string) {
Expand Down Expand Up @@ -129,4 +130,17 @@ export class SqlMethodUtils {

return sql.split(";");
}

static parseMethodArgs(methodArgs: any, driverDialect: DriverDialect) {
// MethodArgs may be an array, where the first element could be either a string, a MySQL2 Query Object, or a Node-Postgres config object.
if (!methodArgs) {
return methodArgs;
}
if (!Array.isArray(methodArgs)) {
return driverDialect.getQueryFromMethodArg(methodArgs);
}

const statement = methodArgs[0];
return driverDialect.getQueryFromMethodArg(statement);
}
}
33 changes: 31 additions & 2 deletions common/lib/utils/subscribed_method_helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,35 @@
*/

export class SubscribedMethodHelper {
static readonly NETWORK_BOUND_METHODS: string[] = ["connect", "forceConnect", "query", "rollback"];
static readonly METHODS_REQUIRING_UPDATED_TOPOLOGY: string[] = ["connect", "forceConnect", "query"];
static readonly NETWORK_BOUND_METHODS: string[] = [
"connect",
"forceConnect",
"query",
// MySQL-specific
"execute",
"rollback",
"beginTransaction",
"commit",
"changeUser",
"pause",
"resume",
"prepare",
"unprepare"
];

static readonly METHODS_REQUIRING_UPDATED_TOPOLOGY: string[] = [
"connect",
"forceConnect",
"query",
// MySQL-specific
"beginTransaction",
"commit",
"changeUser",
"pause",
"resume",
"execute",
"rollback",
"prepare",
"unprepare"
];
}
10 changes: 2 additions & 8 deletions common/lib/wrapper_property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,14 +464,8 @@ export class WrapperProperties {
BlueGreenStatusProvider.MONITORING_PROPERTY_PREFIX
];

private static startsWithPrefix(key: string) {
for (const prefix in WrapperProperties.PREFIXES) {
if (key.startsWith(prefix)) {
return true;
}
}

return false;
private static startsWithPrefix(key: string): boolean {
return WrapperProperties.PREFIXES.some((prefix) => key.startsWith(prefix));
}

static removeWrapperProperties(props: Map<string, any>): Map<string, any> {
Expand Down
Loading
Loading