SessionPool
Class used to manage connections to Spanner.
You don't need to use this class directly, connections will be handled for you.
Constructor
SessionPool
new SessionPool(database, options)
Parameter |
|
---|---|
database |
The DB instance. |
options |
Optional Configuration options. |
- Extends
- EventEmitter
Properties
available
number
Total number of available sessions.
borrowed
number
Total number of borrowed sessions.
isFull
boolean
Flag to determine if Pool is full.
reads
number
Total number of read sessions.
size
number
Total size of pool.
writes
number
Total number of write sessions.
Methods
formatTrace
formatTrace(trace) returns string
Formats stack trace objects into Node-like stack trace.
Parameter |
|
---|---|
trace |
Array of object The trace object. |
- Returns
-
string
_fill
_fill() returns Promise
Fills the pool with the minimum number of sessions.
- Returns
-
Promise
_getLeaks
_getLeaks() returns Array of string
Returns stack traces for sessions that have not been released.
- Returns
-
Array of string
_isValidSession
_isValidSession(session) returns boolean
Checks to see whether or not session is expired.
Parameter |
|
---|---|
session |
The session to check. |
- Returns
-
boolean
close
close(callback)
Closes and the pool.
Parameter |
|
---|---|
callback |
function() The callback function. |
- Fires
- SessionPool#event:close
getReadSession
getReadSession(callback, err, session)
Retrieve a read session.
Parameter |
|
---|---|
callback |
function() The callback function. |
err |
Error Error, if any. Value may be null. |
session |
The read session. |
getWriteSession
getWriteSession(callback, err, session, transaction)
Retrieve a read/write session.
Parameter |
|
---|---|
callback |
function() The callback function. |
err |
Error Error, if any. Value may be null. |
session |
The read/write session. |
transaction |
The transaction object. |
open
open() returns Promise
Opens the pool, filling it to the configured number of read and write sessions.
- Fires
- SessionPool#event:open
- Returns
-
Promise
release
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.
Parameter |
|
---|---|
session |
The session to release. |
- Fires
- SessionPool#event:available
- SessionPool#event:error
- Throws
-
Error
For unknown sessions.