Constructor
new SessionPool(database, optionsopt)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
database |
Database |
The DB instance. |
|
options |
SessionPoolOptions |
<optional> |
Configuration options. |
Extends
- EventEmitter
Members
available
Total number of available sessions.
borrowed
Total number of borrowed sessions.
currentWriteFraction
Current fraction of write-prepared sessions in the pool.
isFull
Flag to determine if Pool is full.
numReadWaiters
Current number of waiters for a read-only session.
numWriteWaiters
Current number of waiters for a read/write session.
pendingPrepare
Number of sessions currently being prepared for a read/write transaction before being released into the pool. This number does not include the number of sessions being prepared for a read/write transaction that have already been checked out of the pool.
reads
Total number of read sessions.
size
Total size of pool.
totalPending
Number of sessions being created or prepared for a read/write transaction.
totalWaiters
Sum of read and write waiters.
writes
Total number of write sessions.
Methods
(static) formatTrace(trace) → {string}
Formats stack trace objects into Node-like stack trace.
Parameters:
Name | Type | Description |
---|---|---|
trace |
Array.<object> |
The trace object. |
Returns:
Type | Description |
---|---|
string |
(async) _fill() → {Promise}
Fills the pool with the minimum number of sessions.
Returns:
Type | Description |
---|---|
Promise |
_getLeaks() → {Array.<string>}
Returns stack traces for sessions that have not been released.
Returns:
Type | Description |
---|---|
Array.<string> |
_isValidSession(session) → {boolean}
Checks to see whether or not session is expired.
Parameters:
Name | Type | Description |
---|---|---|
session |
Session |
The session to check. |
Returns:
Type | Description |
---|---|
boolean |
close(callback)
Closes and the pool.
Parameters:
Name | Type | Description |
---|---|---|
callback |
SessionPoolCloseCallback |
The callback function. |
Fires:
- SessionPool#event:close
getReadSession(callback)
Retrieve a read session.
Parameters:
Name | Type | Description |
---|---|---|
callback |
GetReadSessionCallback |
The callback function. |
getWriteSession(callback)
Retrieve a read/write session.
Parameters:
Name | Type | Description |
---|---|---|
callback |
GetWriteSessionCallback |
The callback function. |
open() → {Promise}
Opens the pool, filling it to the configured number of read and write sessions.
Returns:
Type | Description |
---|---|
Promise |
Fires:
- SessionPool#event:open
release(session)
Releases session back into the pool. If the session is a write session it will also prepare a new transaction before releasing it.
Parameters:
Name | Type | Description |
---|---|---|
session |
Session |
The session to release. |
Fires:
- SessionPool#event:available
- SessionPool#event:error
- SessionPool#event:readonly-available
- SessionPool#event:readwrite-available
Throws:
-
For unknown sessions.
- Type
- Error