generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 8
feat: GDB RW Splitting #626
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
Open
karenc-bq
wants to merge
3
commits into
feat/gdb-failover
Choose a base branch
from
feat/gdb-rw-splitting
base: feat/gdb-failover
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
common/lib/plugins/read_write_splitting/gdb_read_write_splitting_plugin.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| /* | ||
| 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 { ReadWriteSplittingPlugin } from "./read_write_splitting_plugin"; | ||
| import { WrapperProperties } from "../../wrapper_property"; | ||
| import { HostInfo } from "../../host_info"; | ||
| import { RdsUtils } from "../../utils/rds_utils"; | ||
| import { ReadWriteSplittingError } from "../../utils/errors"; | ||
| import { Messages } from "../../utils/messages"; | ||
| import { logger } from "../../../logutils"; | ||
| import { ClientWrapper } from "../../client_wrapper"; | ||
| import { equalsIgnoreCase } from "../../utils/utils"; | ||
|
|
||
| export class GdbReadWriteSplittingPlugin extends ReadWriteSplittingPlugin { | ||
| protected readonly rdsUtils: RdsUtils = new RdsUtils(); | ||
|
|
||
| protected restrictWriterToHomeRegion: boolean; | ||
| protected restrictReaderToHomeRegion: boolean; | ||
|
|
||
| protected isInitialized: boolean = false; | ||
| protected homeRegion: string; | ||
|
|
||
| protected initSettings(initHostInfo: HostInfo, properties: Map<string, any>): void { | ||
karenc-bq marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (this.isInitialized) { | ||
| return; | ||
| } | ||
| this.restrictWriterToHomeRegion = WrapperProperties.GDB_RW_RESTRICT_WRITER_TO_HOME_REGION.get(properties); | ||
| this.restrictReaderToHomeRegion = WrapperProperties.GDB_RW_RESTRICT_READER_TO_HOME_REGION.get(properties); | ||
|
|
||
| this.homeRegion = WrapperProperties.GDB_RW_HOME_REGION.get(properties); | ||
| if (!this.homeRegion) { | ||
| const rdsUrlType = this.rdsUtils.identifyRdsType(initHostInfo.host); | ||
| if (rdsUrlType.hasRegion) { | ||
| this.homeRegion = this.rdsUtils.getRdsRegion(initHostInfo.host); | ||
| } | ||
| } | ||
|
|
||
| if (!this.homeRegion) { | ||
| throw new ReadWriteSplittingError(Messages.get("GdbReadWriteSplittingPlugin.missingHomeRegion", initHostInfo.host)); | ||
| } | ||
|
|
||
| logger.debug(Messages.get("GdbReadWriteSplittingPlugin.parameterValue", "gdbRwHomeRegion", this.homeRegion)); | ||
|
|
||
| this.isInitialized = true; | ||
| } | ||
|
|
||
| override async connect( | ||
| hostInfo: HostInfo, | ||
| props: Map<string, any>, | ||
| isInitialConnection: boolean, | ||
| connectFunc: () => Promise<ClientWrapper> | ||
| ): Promise<ClientWrapper> { | ||
| this.initSettings(hostInfo, props); | ||
| return super.connect(hostInfo, props, isInitialConnection, connectFunc); | ||
| } | ||
|
|
||
| override setWriterClient(writerTargetClient: ClientWrapper | undefined, writerHostInfo: HostInfo) { | ||
| if ( | ||
| this.restrictWriterToHomeRegion && | ||
| writerHostInfo != null && | ||
| !equalsIgnoreCase(this.rdsUtils.getRdsRegion(writerHostInfo.host), this.homeRegion) | ||
| ) { | ||
| throw new ReadWriteSplittingError( | ||
| Messages.get("GdbReadWriteSplittingPlugin.cantConnectWriterOutOfHomeRegion", writerHostInfo.host, this.homeRegion) | ||
| ); | ||
| } | ||
| super.setWriterClient(writerTargetClient, writerHostInfo); | ||
| } | ||
|
|
||
| protected getReaderHostCandidates(): HostInfo[] { | ||
karenc-bq marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (this.restrictReaderToHomeRegion) { | ||
| const hostsInRegion: HostInfo[] = this.pluginService | ||
| .getHosts() | ||
| .filter((x) => equalsIgnoreCase(this.rdsUtils.getRdsRegion(x.host), this.homeRegion)); | ||
|
|
||
| if (hostsInRegion.length === 0) { | ||
| throw new ReadWriteSplittingError(Messages.get("GdbReadWriteSplittingPlugin.noAvailableReadersInHomeRegion", this.homeRegion)); | ||
| } | ||
| return hostsInRegion; | ||
| } | ||
| return super.getReaderHostCandidates(); | ||
karenc-bq marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
40 changes: 40 additions & 0 deletions
40
common/lib/plugins/read_write_splitting/gdb_read_write_splitting_plugin_factory.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| 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 { ConnectionPluginFactory } from "../../plugin_factory"; | ||
| import { PluginService } from "../../plugin_service"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think we can remove this import |
||
| import { ConnectionPlugin } from "../../connection_plugin"; | ||
| import { AwsWrapperError } from "../../utils/errors"; | ||
| import { Messages } from "../../utils/messages"; | ||
| import { FullServicesContainer } from "../../utils/full_services_container"; | ||
|
|
||
| export class GdbReadWriteSplittingPluginFactory extends ConnectionPluginFactory { | ||
| private static gdbReadWriteSplittingPlugin: any; | ||
|
|
||
| async getInstance(servicesContainer: FullServicesContainer, properties: Map<string, any>): Promise<ConnectionPlugin> { | ||
| try { | ||
| if (!GdbReadWriteSplittingPluginFactory.gdbReadWriteSplittingPlugin) { | ||
| GdbReadWriteSplittingPluginFactory.gdbReadWriteSplittingPlugin = await import("./gdb_read_write_splitting_plugin"); | ||
| } | ||
| return new GdbReadWriteSplittingPluginFactory.gdbReadWriteSplittingPlugin.GdbReadWriteSplittingPlugin( | ||
| servicesContainer.getPluginService(), | ||
| properties | ||
| ); | ||
| } catch (error: any) { | ||
| throw new AwsWrapperError(Messages.get("ConnectionPluginChainBuilder.errorImportingPlugin", error.message, "gdbReadWriteSplittingPlugin")); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
common/lib/plugins/read_write_splitting/read_write_splitting_plugin_factory.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.