SessionPool

SessionPool

Class used to manage connections to Spanner.

You don't need to use this class directly, connections will be handled for you.

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

isFull

Flag to determine if Pool is full.

numReadWaiters

numWriteWaiters

pendingPrepare

reads

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

Methods

(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.

Deprecated: Use getSession instead.

Parameters:
Name Type Description
callback GetReadSessionCallback

The callback function.

getSession(callback)

Retrieve a session.

Parameters:
Name Type Description
callback GetSessionCallback

The callback function.

getWriteSession(callback)

Retrieve a read/write session.

Deprecated: use getSession instead.

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.

Parameters:
Name Type Description
session Session

The session to release.

Fires:
  • SessionPool#event:available
  • SessionPool#event:error
  • SessionPool#event:session-available
  • @deprecated SessionPool#event:readonly-available
  • @deprecated SessionPool#event:readwrite-available
Throws:

For unknown sessions.

Type
Error

(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