Skip to content

Commit 85792da

Browse files
committed
Optimization with Easy Connect String processing
1 parent ef885dc commit 85792da

File tree

3 files changed

+25
-61
lines changed

3 files changed

+25
-61
lines changed

doc/src/release_notes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Common Changes
1919
Thin Mode Changes
2020
++++++++++++++++++
2121

22+
#) Internal code refactoring to improve connection performance when using
23+
input easy connection Strings.
24+
2225
#) Fixed bug that throws an 'ORA-01000' error when a query is executed multiple
2326
times even though query returned errors like 'NJS-119', 'NJS-016'.
2427

lib/thin/sqlnet/ezConnectResolver.js

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
'use strict';
2828

29-
const {lookup} = require('dns').promises;
3029
const errors = require("../../errors.js");
3130

3231
// The host information pattern of the EZConnect URL format.
@@ -71,14 +70,7 @@ const DESCRIPTION_PARAMS = ["ENABLE", "FAILOVER", "LOAD_BALANCE",
7170
class EZConnectResolver {
7271
constructor(url) {
7372
this.URL_PROPS_ALIAS = this.initializeUrlAlias();
74-
const jdbcUrlPrefix = url.indexOf('@');
75-
if (jdbcUrlPrefix != -1) {
76-
this.url = url.substring(jdbcUrlPrefix + 1);
77-
this.urlPrefix = url.substring(0, jdbcUrlPrefix + 1);
78-
} else {
79-
this.url = url;
80-
this.urlPrefix = "";
81-
}
73+
this.url = url;
8274
this.resolvedUrl = '';
8375
this.connectionProps = new Map();
8476
this.urlProps = new Map();
@@ -89,8 +81,8 @@ class EZConnectResolver {
8981
* Returns the resolved long TNS String.
9082
* @return Resolved TNS URL.
9183
*/
92-
async getResolvedUrl() {
93-
await this.parse();
84+
getResolvedUrl() {
85+
this.parse();
9486
return this.resolvedUrl;
9587
}
9688

@@ -99,29 +91,22 @@ class EZConnectResolver {
9991
* After parsing the extended settings if the remaining part of the URL is in
10092
* EZConnectURL format then resolve it to long TNS url format.
10193
*/
102-
async parse() {
94+
parse() {
10395
// First try to parse the extended settings part of the URL.
10496
let parsedUrl = this.parseExtendedSettings(this.url);
10597
if (this.connectionProps.size === 0 && this.urlProps.size === 0) {
10698
// If we have not parsed anything then use the received url as is.
10799
parsedUrl = this.url;
108100
}
109-
110-
if (parsedUrl.startsWith("(")) {
111-
// Skip resolve the URL if it is in TNS format,
112-
// TNS format starts with '('
113-
this.resolvedUrl = this.urlPrefix + parsedUrl;
114-
} else {
115-
// Try to resolve the EZConnectURL to Long TNS URL.
116-
this.resolvedUrl = this.urlPrefix + await this.resolveToLongURLFormat(parsedUrl);
117-
}
101+
// Try to resolve the EZConnectURL to Long TNS URL.
102+
this.resolvedUrl = this.resolveToLongURLFormat(parsedUrl);
118103
}
119104
/**
120105
* Translate the given ezconnect url format to Long TNS format.
121106
* @param url EZConnect URL
122107
* @return Returns resolved TNS url.
123108
*/
124-
async resolveToLongURLFormat(url) {
109+
resolveToLongURLFormat(url) {
125110
// URL is in the following format
126111
// [protocol://]host1[,host13][:port1][,host2:port2][/service_name][:server][/instance_name]
127112

@@ -151,7 +136,7 @@ class EZConnectResolver {
151136
const proxyHost = this.urlProps.get("HTTPS_PROXY");
152137
const proxyPort = this.urlProps.get("HTTPS_PROXY_PORT");
153138
const addressInfo =
154-
await this.buildAddressList(hostInfo, protocol, proxyHost, proxyPort);
139+
this.buildAddressList(hostInfo, protocol, proxyHost, proxyPort);
155140

156141
const connectionIdPrefix =
157142
this.urlProps.get("CONNECTION_ID_PREFIX");
@@ -210,10 +195,8 @@ class EZConnectResolver {
210195
* @param proxyPort proxy server port [optional].
211196
* @return address information of the DESCRIPTION node.
212197
*/
213-
async buildAddressList(hostInfo, protocol,
198+
buildAddressList(hostInfo, protocol,
214199
proxyHost, proxyPort) {
215-
let shost = '';
216-
let ipcnt = 0;
217200
const builder = new Array();
218201
let proxyInfo = '';
219202
if (proxyHost != null) {
@@ -239,7 +222,6 @@ class EZConnectResolver {
239222
}
240223
for (const hname in hostnames) {
241224
addressListBuilder.push(this.getAddrStr(hostnames[hname], port, protocol, proxyInfo));
242-
shost = hostnames[hname];
243225
addressNodeCount++;
244226
}
245227
}
@@ -253,21 +235,6 @@ class EZConnectResolver {
253235
else
254236
builder.push(parts.join(''));
255237
}
256-
if (naddr == 1) {
257-
shost = shost.trim();
258-
// If it is IPV6 format address then remove the enclosing '[' and ']'
259-
if (shost.startsWith("[") && shost.endsWith("]"))
260-
shost = shost.substring(1, shost.length - 1);
261-
try {
262-
await lookup(shost);
263-
ipcnt++;
264-
} catch {
265-
// nothing
266-
}
267-
if (ipcnt == 0) {
268-
errors.throwErr(errors.ERR_INVALID_EZCONNECT_SYNTAX, 'could not resolve hostname', shost);
269-
}
270-
}
271238

272239
if (addressLists.length < 2 && naddr > 1) {
273240
this.lb = true;

lib/thin/sqlnet/networkSession.js

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,29 +71,23 @@ async function resolveConnectStr(connectString, configDir) {
7171
const connStr = connectString.trim();
7272
let resolvedVal = connStr;
7373
if ((connStr.indexOf(')') == -1) || (connStr.indexOf('(') != 0)) {
74-
try {
75-
/* Try through ezconnect */
74+
if ((connStr.indexOf(':') != -1) || (connStr.indexOf('/') != -1)) {
7675
const ezcnObj = new EzConnect(connStr);
77-
resolvedVal = await ezcnObj.getResolvedUrl();
78-
} catch (err) {
79-
try {
80-
/* try tns alias */
81-
const namesFilePath = tnsnamesFilePath(configDir);
82-
const p = await nlParamParser.initializeNlpa(namesFilePath);
83-
resolvedVal = p.get(connStr.toUpperCase());
84-
if (!resolvedVal)
85-
errors.throwErr(errors.ERR_TNS_ENTRY_NOT_FOUND, connStr, configDir ? configDir + '/tnsnames.ora' : process.env.TNS_ADMIN + '/tnsnames.ora');
86-
resolvedVal = resolvedVal.getListElement(0);
87-
} catch (err1) {
88-
if ((connStr.indexOf(':') != -1) || (connStr.indexOf('/') != -1)) {
89-
throw err;
90-
} else {
91-
throw err1;
92-
}
93-
}
76+
resolvedVal = ezcnObj.getResolvedUrl();
77+
return resolvedVal;
78+
} else {
79+
//try tns alias
80+
const namesFilePath = tnsnamesFilePath(configDir);
81+
const p = await nlParamParser.initializeNlpa(namesFilePath);
82+
resolvedVal = p.get(connStr.toUpperCase());
83+
if (!resolvedVal)
84+
errors.throwErr(errors.ERR_TNS_ENTRY_NOT_FOUND, connStr, configDir ? configDir + '/tnsnames.ora' : process.env.TNS_ADMIN + '/tnsnames.ora');
85+
resolvedVal = resolvedVal.getListElement(0);
9486
}
87+
9588
}
9689
return resolvedVal;
90+
9791
}
9892

9993
async function resolveAddress(connStr, configDir) {

0 commit comments

Comments
 (0)