Skip to content

Commit c83cc1e

Browse files
committed
Pool reconfiguration support in Thin mode
1 parent 2469fb2 commit c83cc1e

File tree

5 files changed

+121
-61
lines changed

5 files changed

+121
-61
lines changed

doc/src/api_manual/pool.rst

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,6 @@ Pool Methods
536536
as the maximum number of connections in the pool, or the statement cache
537537
size used by connections can be changed.
538538

539-
.. note::
540-
541-
This method is only supported in node-oracledb Thick mode. See
542-
:ref:`enablingthick`.
543-
544539
Properties are optional. Unspecified properties will leave those pool
545540
properties unchanged. The properties are processed in two stages. After
546541
any size change has been processed, reconfiguration on the other
@@ -587,19 +582,19 @@ Pool Methods
587582
- Description
588583
* - ``poolAttrs``
589584
- Object
590-
- The ``oracledb.createPool()`` properties that can be changed with ``pool.reconfigure()`` are:
585+
- The following ``oracledb.createPool()`` properties can be changed with ``pool.reconfigure()`` in both Thin and Thick modes unless otherwise specified:
591586

592587
- :ref:`enableStatistics <createpoolpoolattrsstats>`
593588
- :ref:`poolIncrement <createpoolpoolattrspoolincrement>`
594589
- :ref:`poolMax <createpoolpoolattrspoolmax>`
595-
- :ref:`poolMaxPerShard <createpoolpoolattrspoolmaxpershard>`
590+
- :ref:`poolMaxPerShard <createpoolpoolattrspoolmaxpershard>` in only Thick mode
596591
- :ref:`poolMin <createpoolpoolattrspoolmin>`
597592
- :ref:`poolPingInterval <createpoolpoolattrspoolpinginterval>`
598593
- :ref:`poolTimeout <createpoolpoolattrspooltimeout>`
599594
- :ref:`queueMax <createpoolpoolattrsqueuemax>`
600595
- :ref:`queueRequests <createpoolpoolattrsqueuerequests>`
601596
- :ref:`queueTimeout <createpoolpoolattrsqueuetimeout>`
602-
- :ref:`sodaMetaDataCache <createpoolpoolattrssodamdcache>`
597+
- :ref:`sodaMetaDataCache <createpoolpoolattrssodamdcache>` in only Thick mode
603598
- :ref:`stmtCacheSize <createpoolpoolattrsstmtcachesize>`
604599

605600
A ``resetStatistics`` property can also be set to *true*. This zeros the current pool statistics, with the exception of ``queueMax`` which is set to the current queue length. Statistics are also reset when statistics recording is turned on with the ``enableStatistics`` property.

doc/src/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ Thin Mode Changes
5858
errors were raised.
5959
See `Issue #1652 <https://github.com/oracle/node-oracledb/issues/1652>`__.
6060

61+
#) Added support for pool reconfiguration.
62+
6163
#) Added support for Oracle Database 23c
6264
:ref:`Implicit Connection Pooling <implicitpool>` in DRCP and PRCP.
6365

lib/thin/pool.js

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,11 @@ class ThinPoolImpl extends PoolImpl {
386386
}
387387

388388
//---------------------------------------------------------------------------
389-
// _getNumConns()
389+
// _getNumConnsToCreate()
390390
//
391391
// get number of connections need to be created
392392
//---------------------------------------------------------------------------
393-
_getNumConns() {
393+
_getNumConnsToCreate() {
394394
const usedConns = this._freeConnectionList.length + this._usedConnectionList.size;
395395
// less connections in the pool than poolMin? restore to poolMin
396396
if (usedConns < this._poolMin) {
@@ -416,11 +416,19 @@ class ThinPoolImpl extends PoolImpl {
416416

417417
// continue until a close request is received
418418
while (!this._poolCloseWaiter) {
419-
// get count for connections to be created
420-
const numConns = this._getNumConns();
419+
// eliminate connections that exceed the poolMax (this should only happen
420+
// after a reconfiguration has taken place where the maximum number of
421+
// connections is reduced)
422+
let numToDestroy = this._poolMax - this.getConnectionsOpen();
423+
while (numToDestroy > 0 && this._freeConnectionList.length > 0) {
424+
const connToBeRemoved = this._freeConnectionList.shift();
425+
this.eventEmitter.emit('_removePoolConnection', connToBeRemoved);
426+
numToDestroy--;
427+
}
421428

429+
const numToCreate = this._getNumConnsToCreate();
422430
// connection creation is going on serially and not concurrently
423-
for (let i = 0; i < numConns; i++) {
431+
for (let i = 0; i < numToCreate; i++) {
424432
try {
425433
// get deobfuscated value
426434
const config = await this._getConnAttrs();
@@ -565,8 +573,14 @@ class ThinPoolImpl extends PoolImpl {
565573
if (conn.nscon.connected) {
566574
conn._lastTimeUsed = Date.now();
567575
conn._newSession = false;
568-
this._freeConnectionList.push(conn);
576+
if ((this._freeConnectionList.length + this._usedConnectionList.size)
577+
< this._poolMax) {
578+
this._freeConnectionList.push(conn);
579+
} else {
580+
this.eventEmitter.emit('_removePoolConnection', conn);
581+
}
569582
}
583+
570584
this._setScheduler();
571585
}
572586

@@ -579,6 +593,47 @@ class ThinPoolImpl extends PoolImpl {
579593
this._userConfig.connectionClass = crypto.randomBytes(16).toString('base64');
580594
this._userConfig.connectionClass = "NJS:" + this._userConfig.connectionClass;
581595
}
596+
597+
//---------------------------------------------------------------------------
598+
// reconfigure()
599+
//
600+
// Reconfigures the pool with new parameters
601+
//---------------------------------------------------------------------------
602+
reconfigure(params) {
603+
if (params.poolIncrement !== undefined) {
604+
this._poolIncrement = params.poolIncrement;
605+
}
606+
607+
if (params.poolTimeout !== undefined &&
608+
this._poolTimeout !== params.poolTimeout) {
609+
this._poolTimeout = params.poolTimeout;
610+
// clear scheduled job
611+
if (this._schedulerJob) {
612+
clearTimeout(this._schedulerJob);
613+
this._schedulerJob = null;
614+
}
615+
}
616+
617+
if (params.poolPingInterval !== undefined) {
618+
this._poolPingInterval = params.poolPingInterval;
619+
}
620+
621+
if (params.stmtCacheSize !== undefined) {
622+
this._stmtCacheSize = params.stmtCacheSize;
623+
}
624+
625+
if (params.poolMax !== undefined) {
626+
this._poolMax = params.poolMax;
627+
}
628+
629+
if (params.poolMin !== undefined) {
630+
this._poolMin = params.poolMin;
631+
}
632+
633+
if (this.bgWaiter) {
634+
this.bgWaiter();
635+
}
636+
}
582637
}
583638

584639
module.exports = ThinPoolImpl;

test/dbconfig.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ if (process.env.NODE_ORACLEDB_CONNECTIONSTRING) {
6767
if (process.env.NODE_ORACLEDB_EXTERNALAUTH) {
6868
const eauth = process.env.NODE_ORACLEDB_EXTERNALAUTH;
6969
if (eauth.toLowerCase() === 'true') {
70+
if (oracledb.thin) {
71+
throw new Error("Cannot use externalAuth with thin driver.");
72+
}
7073
config.test.externalAuth = true;
7174
}
7275
}

0 commit comments

Comments
 (0)