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 :number

Total number of available sessions.

borrowed :number

Total number of borrowed sessions.

currentWriteFraction :number

Current fraction of write-prepared sessions in the pool.

isFull :boolean

Flag to determine if Pool is full.

numReadWaiters :number

Current number of waiters for a read-only session.

numWriteWaiters :number

Current number of waiters for a read/write session.

pendingPrepare :number

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 :number

Total number of read sessions.

size :number

Total size of pool.

totalPending :number

Number of sessions being created or prepared for a read/write transaction.

totalWaiters :number

Sum of read and write waiters.

writes :number

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.

(async) _fill() → {Promise}

Fills the pool with the minimum number of sessions.

_getLeaks() → {Array.<string>}

Returns stack traces for sessions that have not been released.

_isValidSession(session) → {boolean}

Checks to see whether or not session is expired.

Parameters:
Name Type Description
session Session

The session to check.

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.

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