Skip to content

Commit 4543780

Browse files
committed
Add support for Network Compression
1 parent dfc166d commit 4543780

File tree

14 files changed

+339
-18
lines changed

14 files changed

+339
-18
lines changed

doc/src/release_notes.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ Common Changes
2828
Thin Mode Changes
2929
+++++++++++++++++
3030

31-
#) Added support for External Authentication using Transport Layer Security(TLS).
31+
#) Added support for external authentication using Transport Layer
32+
Security (TLS) protocol.
33+
34+
#) Added support for Advanced Network Compression which reduces the size
35+
of the network data packets transmitted over a connection for improved
36+
effective network throughput and bandwidth utilization.
3237

3338
#) Fixed issue that does not throw Authentication error for FastAuth
3439
when invalid token is used with external authentication.

lib/connection.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,10 @@ class Connection extends EventEmitter {
12161216
this._impl.isHealthy());
12171217
}
12181218

1219+
isCompressionEnabled() {
1220+
return (this._impl && this._impl.isCompressionEnabled());
1221+
}
1222+
12191223
//---------------------------------------------------------------------------
12201224
// maxIdentifierLength
12211225
//

lib/errors.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ const ERR_HOST_NOT_FOUND = 530;
206206
const ERR_ANO_PACKET = 531;
207207
const ERR_ANO_STATUS = 532;
208208
const ERR_ANO_NEGOTIATION = 533;
209+
const ERR_DATA_COMPRESSION = 534;
209210

210211
// Oracle SUCCESS_WITH_INFO warning start from 700
211212
const WRN_COMPILATION_CREATE = 700;
@@ -562,7 +563,7 @@ messages.set(ERR_ANO_STATUS, // NJS-532
562563
'%s service recieved status failure');
563564
messages.set(ERR_ANO_NEGOTIATION, // NJS-533
564565
'Advanced Networking Option service negotiation failed. Native Network Encryption and DataIntegrity only supported in node-oracledb thick mode.\nCause: ORA-%s');
565-
566+
messages.set(ERR_DATA_COMPRESSION, 'Error during data compression/decompression: %s\n'); //NJS-534
566567
// Oracle SUCCESS_WITH_INFO warning
567568
messages.set(WRN_COMPILATION_CREATE, // NJS-700
568569
'creation succeeded with compilation errors');
@@ -887,6 +888,7 @@ module.exports = {
887888
ERR_CONFIG_PROVIDER_FAILED_TO_RETRIEVE_CONFIG,
888889
ERR_CONFIG_PROVIDER_NOT_SUPPORTED,
889890
ERR_CONFIG_PROVIDER_LOAD_FAILED,
891+
ERR_DATA_COMPRESSION,
890892
ERR_WALLET_TYPE_NOT_SUPPORTED,
891893
ERR_HOST_NOT_FOUND,
892894
ERR_ANO_PACKET,

lib/impl/connection.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,10 @@ class ConnectionImpl {
409409
errors.throwNotImplemented("getting the health of the connection");
410410
}
411411

412+
isCompressionEnabled() {
413+
errors.throwNotImplemented("getting the data compression status on the connection");
414+
}
415+
412416
//---------------------------------------------------------------------------
413417
// ping()
414418
//

lib/oracledb.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,18 @@ async function _verifyOptions(options, inCreatePool) {
188188
"walletLocation");
189189
outOptions.walletLocation = options.walletLocation;
190190
}
191+
if (options.networkCompression !== undefined) {
192+
errors.assertParamPropValue(typeof options.networkCompression === 'boolean', 1,
193+
"networkCompression");
194+
outOptions.networkCompression = options.networkCompression;
195+
outOptions.networkCompressionLevels = [];
196+
outOptions.networkCompressionLevels.push('high');
197+
}
198+
199+
if (options.networkCompressionThreshold !== undefined) {
200+
errors.assertParamPropValue(Number.isInteger(options.networkCompressionThreshold), 1, "networkCompressionThreshold");
201+
outOptions.networkCompressionThreshold = options.networkCompressionThreshold;
202+
}
191203

192204
//wallet content must be a string
193205
if (options.walletContent !== undefined) {
@@ -1337,6 +1349,7 @@ module.exports = {
13371349
return settings.configProviderCacheTimeout;
13381350
},
13391351

1352+
13401353
get thin() {
13411354
return settings.thin;
13421355
},
@@ -1517,6 +1530,7 @@ module.exports = {
15171530
errors.assertPropValue(typeof value === 'string', "terminal");
15181531
settings.terminal = value;
15191532
},
1533+
15201534
set configProviderCacheTimeout(value) {
15211535
errors.assertPropValue(Number.isInteger(value) && value >= 0,
15221536
"configProviderCacheTimeout");

lib/thin/connection.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,9 @@ class ThinConnectionImpl extends ConnectionImpl {
715715
await this._protocol.breakMessage();
716716
}
717717

718+
isCompressionEnabled() {
719+
return this.nscon.compressionEnabled;
720+
}
718721
isHealthy() {
719722
try {
720723
if (this.nscon.recvInbandNotif() === 0)

lib/thin/protocol/packet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ class WritePacket extends BaseBuffer {
530530
if (!this.nsi.ntAdapter) {
531531
errors.throwErr(errors.ERR_INVALID_CONNECTION);
532532
}
533-
this.nsi.ntAdapter.send(buf);
533+
this.nsi.sendPacket(buf);
534534
}
535535

536536
/**

lib/thin/sqlnet/constants.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2022, 2024, Oracle and/or its affiliates.
1+
// Copyright (c) 2022, 2025, Oracle and/or its affiliates.
22

33
//-----------------------------------------------------------------------------
44
//
@@ -155,6 +155,7 @@ module.exports = {
155155
NSPDAFLG: 8, // Data flags
156156
NSPDADAT: 10, // Start of Data
157157
NSPDAFEOF: 0x40, // "end of file"
158+
NSPDAFCMP: 0x400, // "compressed data"
158159

159160
/* Marker Packet */
160161
NSPMKTYP: 8, // marker type (see below)
@@ -201,6 +202,9 @@ module.exports = {
201202
PURITY: 8, // Purity
202203
SID: 9, // SID
203204

205+
/* Network Compression Algorithms */
206+
NETWORK_COMPRESSION_ZLIB: 2,
207+
204208
/* FLAGS */
205209
NSNOBLOCK: 0x0001, // Do not block
206210
};

lib/thin/sqlnet/ezConnectResolver.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const EXT_PARAM_SEP = '&';
5757
const DESCRIPTION_PARAMS = ["ENABLE", "FAILOVER", "LOAD_BALANCE",
5858
"RECV_BUF_SIZE", "SEND_BUF_SIZE", "SDU",
5959
"SOURCE_ROUTE", "RETRY_COUNT", "RETRY_DELAY",
60-
"CONNECT_TIMEOUT", "TRANSPORT_CONNECT_TIMEOUT", "RECV_TIMEOUT", "USE_SNI"];
60+
"CONNECT_TIMEOUT", "TRANSPORT_CONNECT_TIMEOUT", "RECV_TIMEOUT", "USE_SNI", "COMPRESSION"];
6161
/*
6262
DESCRIPTION
6363
This class takes care resolving the EZConnect format to Long TNS URL format.
@@ -438,6 +438,7 @@ class EZConnectResolver {
438438
initializeUrlAlias() {
439439
const aliasMap = new Map();
440440
aliasMap.set("enable", "ENABLE");
441+
aliasMap.set("compression", "COMPRESSION");
441442
aliasMap.set("failover", "FAILOVER");
442443
aliasMap.set("load_balance", "LOAD_BALANCE");
443444
aliasMap.set("recv_buf_size", "RECV_BUF_SIZE");

lib/thin/sqlnet/navNodes.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,19 @@ class Description {
294294
}
295295
} else if (childnv.name.toUpperCase() == "SDU") {
296296
this.params.sdu = childnv.atom;
297+
} else if (childnv.name.toUpperCase() == "COMPRESSION") {
298+
this.params.networkCompression = (childnv.atom.toLowerCase() == "yes"
299+
|| childnv.atom.toLowerCase() == "on"
300+
|| childnv.atom.toLowerCase() == "true");
301+
this.params.networkCompressionLevels = [];
302+
} else if (childnv.name.toUpperCase() == "COMPRESSION_LEVELS") {
303+
const listsize = childnv.getListSize();
304+
for (let i = 0; i < listsize; i++) {
305+
const tmpnv = childnv.getListElement(i);
306+
if (tmpnv.name.toUpperCase() == "LEVEL") {
307+
this.params.networkCompressionLevels.push(tmpnv.atom.toLowerCase());
308+
}
309+
}
297310
} else if (childnv.name.toUpperCase() == "EXPIRE_TIME") {
298311
if (childnv.atom > 0)
299312
this.params.expireTime = childnv.atom;
@@ -700,7 +713,6 @@ class NavDescription extends Description {
700713
}
701714

702715
desc.params = this.params;
703-
704716
if ('connectTimeout' in this.params) {
705717
cs.sBuf.push("(CONNECT_TIMEOUT=" + this.params.connectTimeout + ")");
706718
}

0 commit comments

Comments
 (0)