Class SessionPool (7.3.0) Stay organized with collections Save and categorize content based on your preferences.
Class used to manage connections to Spanner.
**You don't need to use this class directly, connections will be handled for you.**
{EventEmitter}
Inheritance
EventEmitter >SessionPoolPackage
@google-cloud/spannerConstructors
(constructor)(database, options)
constructor(database:Database,options?:SessionPoolOptions);Constructs a new instance of theSessionPool class
| Parameters | |
|---|---|
| Name | Description |
database | DatabaseThe DB instance. |
options | SessionPoolOptionsConfiguration options. |
Properties
_acquires
_acquires:PQueue;_evictHandle
_evictHandle:NodeJS.Timer;_inventory
_inventory:SessionInventory;_onClose
_onClose:Promise<void>;_pending
_pending:number;_pingHandle
_pingHandle:NodeJS.Timer;_requests
_requests:PQueue;_traces
_traces:Map<string,trace.StackFrame[]>;_waiters
_waiters:number;available
getavailable():number;Total number of available sessions. {number}
borrowed
getborrowed():number;Total number of borrowed sessions. {number}
currentWriteFraction
getcurrentWriteFraction():number;database
database:Database;isFull
getisFull():boolean;Flag to determine if Pool is full. {boolean}
isOpen
isOpen:boolean;numReadWaiters
getnumReadWaiters():number;numWriteWaiters
getnumWriteWaiters():number;options
options:SessionPoolOptions;pendingPrepare
getpendingPrepare():number;reads
getreads():number;size
getsize():number;Total size of pool. {number}
totalPending
gettotalPending():number;Number of sessions being created or prepared for a read/write transaction. {number}
totalWaiters
gettotalWaiters():number;Sum of read and write waiters. {number}
writes
getwrites():number;Methods
_acquire()
_acquire():Promise<Session>;Attempts to borrow a session from the pool.
| Returns | |
|---|---|
| Type | Description |
Promise<Session> | {Promise |
_borrow(session)
_borrow(session:Session):void;Moves a session into the borrowed group.
| Parameter | |
|---|---|
| Name | Description |
session | SessionThe session object. |
| Returns | |
|---|---|
| Type | Description |
void | |
_borrowFrom()
_borrowFrom():Session;Borrows the first session from the inventory.
{Session}
| Returns | |
|---|---|
| Type | Description |
Session | |
_borrowNextAvailableSession()
_borrowNextAvailableSession():Session;Grabs the next available session.
| Returns | |
|---|---|
| Type | Description |
Session | {Promise |
_createSession()
_createSession():Promise<void>;Attempts to create a single session.
| Returns | |
|---|---|
| Type | Description |
Promise<void> | {Promise} |
_createSessions(amount)
_createSessions(amount:number):Promise<void>;Batch creates sessions.
| Parameter | |
|---|---|
| Name | Description |
amount | numberConfig specifying how many sessions to create. |
| Returns | |
|---|---|
| Type | Description |
Promise<void> | {Promise} SessionPool#createError |
_destroy(session)
_destroy(session:Session):Promise<void>;Attempts to delete a session, optionally creating a new one of the same type if the pool is still open and we're under the configured min value.
SessionPool#error
| Parameter | |
|---|---|
| Name | Description |
session | SessionThe session to delete. |
| Returns | |
|---|---|
| Type | Description |
Promise<void> | {Promise} |
_evictIdleSessions()
_evictIdleSessions():void;Deletes idle sessions that exceed the maxIdle configuration.
| Returns | |
|---|---|
| Type | Description |
void | |
_fill()
_fill():Promise<void>;Fills the pool with the minimum number of sessions.
{Promise}
| Returns | |
|---|---|
| Type | Description |
Promise<void> | |
_getIdleSessions()
_getIdleSessions():Session[];Retrieves a list of all the idle sessions.
| Returns | |
|---|---|
| Type | Description |
Session[] | {Session[]} |
_getLeaks()
_getLeaks():string[];Returns stack traces for sessions that have not been released.
{string[]}
| Returns | |
|---|---|
| Type | Description |
string[] | |
_getSession(startTime)
_getSession(startTime:number):Promise<Session>;Attempts to get a session.
| Parameter | |
|---|---|
| Name | Description |
startTime | numberTimestamp to use when determining timeouts. |
| Returns | |
|---|---|
| Type | Description |
Promise<Session> | {Promise |
_hasSessionUsableFor()
_hasSessionUsableFor():boolean;Returns true if the pool has a usable session.
| Returns | |
|---|---|
| Type | Description |
boolean | |
_isValidSession(session)
_isValidSession(session:Session):boolean;Checks to see whether or not session is expired.
| Parameter | |
|---|---|
| Name | Description |
session | SessionThe session to check. |
| Returns | |
|---|---|
| Type | Description |
boolean | {boolean} |
_ping(session)
_ping(session:Session):Promise<void>;Pings an individual session.
| Parameter | |
|---|---|
| Name | Description |
session | SessionThe session to ping. |
| Returns | |
|---|---|
| Type | Description |
Promise<void> | {Promise} |
_pingIdleSessions()
_pingIdleSessions():Promise<void>;Makes a keep alive request to all the idle sessions.
| Returns | |
|---|---|
| Type | Description |
Promise<void> | {Promise} |
_prepareTransaction(session)
_prepareTransaction(session:Session):void;Creates a transaction for a session.
| Parameter | |
|---|---|
| Name | Description |
session | SessionThe session object. |
| Returns | |
|---|---|
| Type | Description |
void | |
_release(session)
_release(session:Session):void;Releases a session back into the pool.
SessionPool#available SessionPool#session-available
| Parameter | |
|---|---|
| Name | Description |
session | SessionThe session object. |
| Returns | |
|---|---|
| Type | Description |
void | |
_startHouseKeeping()
_startHouseKeeping():void;Starts housekeeping (pinging/evicting) of idle sessions.
| Returns | |
|---|---|
| Type | Description |
void | |
_stopHouseKeeping()
_stopHouseKeeping():void;Stops housekeeping.
| Returns | |
|---|---|
| Type | Description |
void | |
close(callback)
close(callback:SessionPoolCloseCallback):void;Closes and the pool.
SessionPool#close
| Parameter | |
|---|---|
| Name | Description |
callback | SessionPoolCloseCallbackThe callback function. |
| Returns | |
|---|---|
| Type | Description |
void | |
formatTrace(frames)
staticformatTrace(frames:trace.StackFrame[]):string;Formats stack trace objects into Node-like stack trace.
| Parameter | |
|---|---|
| Name | Description |
frames | StackFrame[] |
| Returns | |
|---|---|
| Type | Description |
string | |
getReadSession(callback)
getReadSession(callback:GetReadSessionCallback):void;Retrieve a read session.
| Parameter | |
|---|---|
| Name | Description |
callback | GetReadSessionCallbackThe callback function. |
| Returns | |
|---|---|
| Type | Description |
void | |
getSession(callback)
getSession(callback:GetSessionCallback):void;Retrieve a session.
| Parameter | |
|---|---|
| Name | Description |
callback | GetSessionCallbackThe callback function. |
| Returns | |
|---|---|
| Type | Description |
void | |
getWriteSession(callback)
getWriteSession(callback:GetWriteSessionCallback):void;Retrieve a read/write session.
| Parameter | |
|---|---|
| Name | Description |
callback | GetWriteSessionCallbackThe callback function. |
| Returns | |
|---|---|
| Type | Description |
void | |
open()
open():void;Opens the pool, filling it to the configured number of read and write sessions.
SessionPool#open {Promise}
| Returns | |
|---|---|
| Type | Description |
void | |
release(session)
release(session:Session):void;Releases session back into the pool.
| Parameter | |
|---|---|
| Name | Description |
session | SessionThe session to release. |
| Returns | |
|---|---|
| Type | Description |
void | |
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-10-30 UTC.