-
Notifications
You must be signed in to change notification settings - Fork 443
feat: add support for instance name #1491
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
MichaelSun90
wants to merge
7
commits into
master
Choose a base branch
from
AddSupportForInstanceName
base: master
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
7 commits
Select commit
Hold shift + click to select a range
2e72a87
feat: add support for instance name
MichaelSun90 c1b6583
feat: fix the test failures
MichaelSun90 a74f7e0
Merge branch 'master' into AddSupportForInstanceName
MichaelSun90 eb9d1f9
feat: fix some tests and added comments
MichaelSun90 2cd7a8e
Merge branch 'master' into AddSupportForInstanceName
MichaelSun90 1b00bcc
feat: adding the additional tests
MichaelSun90 423c0a6
feat: changes based on review comments
MichaelSun90 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
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -854,6 +854,7 @@ const CLEANUP_TYPE = { | |||||
| interface RoutingData { | ||||||
| server: string; | ||||||
| port: number; | ||||||
| instanceName: string | undefined; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
|
|
@@ -1253,7 +1254,7 @@ class Connection extends EventEmitter { | |||||
| maxRetriesOnTransientErrors: 3, | ||||||
| multiSubnetFailover: false, | ||||||
| packetSize: DEFAULT_PACKET_SIZE, | ||||||
| port: DEFAULT_PORT, | ||||||
| port: undefined, | ||||||
| readOnlyIntent: false, | ||||||
| requestTimeout: DEFAULT_CLIENT_REQUEST_TIMEOUT, | ||||||
| rowCollectionOnDone: false, | ||||||
|
|
@@ -1272,10 +1273,6 @@ class Connection extends EventEmitter { | |||||
| }; | ||||||
|
|
||||||
| if (config.options) { | ||||||
| if (config.options.port && config.options.instanceName) { | ||||||
| throw new Error('Port and instanceName are mutually exclusive, but ' + config.options.port + ' and ' + config.options.instanceName + ' provided'); | ||||||
| } | ||||||
|
|
||||||
| if (config.options.abortTransactionOnError !== undefined) { | ||||||
| if (typeof config.options.abortTransactionOnError !== 'boolean' && config.options.abortTransactionOnError !== null) { | ||||||
| throw new TypeError('The "config.options.abortTransactionOnError" property must be of type string or null.'); | ||||||
|
|
@@ -1502,7 +1499,6 @@ class Connection extends EventEmitter { | |||||
| } | ||||||
|
|
||||||
| this.config.options.instanceName = config.options.instanceName; | ||||||
| this.config.options.port = undefined; | ||||||
| } | ||||||
|
|
||||||
| if (config.options.isolationLevel !== undefined) { | ||||||
|
|
@@ -1553,7 +1549,8 @@ class Connection extends EventEmitter { | |||||
| } | ||||||
|
|
||||||
| this.config.options.port = config.options.port; | ||||||
| this.config.options.instanceName = undefined; | ||||||
| } else if (!this.config.options.instanceName) { | ||||||
| this.config.options.port = DEFAULT_PORT; | ||||||
| } | ||||||
|
|
||||||
| if (config.options.readOnlyIntent !== undefined) { | ||||||
|
|
@@ -1883,15 +1880,23 @@ class Connection extends EventEmitter { | |||||
| initialiseConnection() { | ||||||
| const signal = this.createConnectTimer(); | ||||||
|
|
||||||
| // If user provided both port and an instance name, | ||||||
| // the code should always use the port and skip the instance lookup | ||||||
| if (this.config.options.port) { | ||||||
| return this.connectOnPort(this.config.options.port, this.config.options.multiSubnetFailover, signal); | ||||||
| } else { | ||||||
| // The instance lookup communicates with the server and gets all the | ||||||
| // available instance name and their corresponding ports. | ||||||
|
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.
Suggested change
|
||||||
| // Then based on the provided instance name and the result ports, | ||||||
| // logic will try to find a match and connection to the instance by its port. | ||||||
| return instanceLookup({ | ||||||
| server: this.config.server, | ||||||
| instanceName: this.config.options.instanceName!, | ||||||
| timeout: this.config.options.connectTimeout, | ||||||
| signal: signal | ||||||
| }).then((port) => { | ||||||
| // If we get a port from the instance lookup process, the logic will try to connect | ||||||
| // using this port. | ||||||
| process.nextTick(() => { | ||||||
| this.connectOnPort(port, this.config.options.multiSubnetFailover, signal); | ||||||
| }); | ||||||
|
|
@@ -2235,7 +2240,8 @@ class Connection extends EventEmitter { | |||||
|
|
||||||
| const payload = new PreloginPayload({ | ||||||
| encrypt: this.config.options.encrypt, | ||||||
| version: { major: Number(major), minor: Number(minor), build: Number(build), subbuild: 0 } | ||||||
| version: { major: Number(major), minor: Number(minor), build: Number(build), subbuild: 0 }, | ||||||
| instanceName: this.routingData?.instanceName ?? this.config.options.instanceName | ||||||
| }); | ||||||
|
|
||||||
| this.messageIo.sendMessage(TYPE.PRELOGIN, payload.data); | ||||||
|
|
@@ -3148,6 +3154,11 @@ Connection.prototype.STATE = { | |||||
| } | ||||||
|
|
||||||
| const preloginPayload = new PreloginPayload(messageBuffer); | ||||||
| if (preloginPayload.instanceName !== undefined && preloginPayload.instanceName !== '\x00') { | ||||||
| this.emit('connect', new ConnectionError('Server instanceName does not match')); | ||||||
| return this.close(); | ||||||
| } | ||||||
|
|
||||||
| this.debug.payload(function() { | ||||||
| return preloginPayload.toString(' '); | ||||||
| }); | ||||||
|
|
||||||
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
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
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.