@google-cloud/spanner 6.3.0 → 6.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31,7 +31,6 @@ const DEFAULTS = {
31
31
  max: 100,
32
32
  maxIdle: 1,
33
33
  min: 25,
34
- writes: 0,
35
34
  incStep: 25,
36
35
  };
37
36
  /**
@@ -146,44 +145,6 @@ exports.isProjectIdNotSetInEnvironmentError = isProjectIdNotSetInEnvironmentErro
146
145
  * @extends {EventEmitter}
147
146
  */
148
147
  class SessionPool extends events_1.EventEmitter {
149
- /**
150
- * @constructor
151
- * @param {Database} database The DB instance.
152
- * @param {SessionPoolOptions} [options] Configuration options.
153
- */
154
- constructor(database, options) {
155
- super();
156
- this._pending = 0;
157
- this._pendingPrepare = 0;
158
- this._numInProcessPrepare = 0;
159
- if (options && options.min && options.max && options.min > options.max) {
160
- throw new TypeError('Min sessions may not be greater than max sessions.');
161
- }
162
- this.isOpen = false;
163
- this.database = database;
164
- this.options = Object.assign({}, DEFAULTS, options);
165
- this.options.min = Math.min(this.options.min, this.options.max);
166
- const { writes } = this.options;
167
- if (writes < 0 || writes > 1) {
168
- throw new TypeError('Write percentage should be represented as a float between 0.0 and 1.0.');
169
- }
170
- this._inventory = {
171
- ["readonly" /* types.ReadOnly */]: [],
172
- ["readwrite" /* types.ReadWrite */]: [],
173
- borrowed: new Set(),
174
- };
175
- this._waiters = {
176
- ["readonly" /* types.ReadOnly */]: 0,
177
- ["readwrite" /* types.ReadWrite */]: 0,
178
- };
179
- this._requests = new p_queue_1.default({
180
- concurrency: this.options.concurrency,
181
- });
182
- this._acquires = new p_queue_1.default({
183
- concurrency: 1,
184
- });
185
- this._traces = new Map();
186
- }
187
148
  /**
188
149
  * Formats stack trace objects into Node-like stack trace.
189
150
  *
@@ -205,24 +166,13 @@ class SessionPool extends events_1.EventEmitter {
205
166
  * @type {number}
206
167
  */
207
168
  get available() {
208
- const reads = this._inventory["readonly" /* types.ReadOnly */];
209
- const writes = this._inventory["readwrite" /* types.ReadWrite */];
210
- return reads.length + writes.length;
169
+ return this._inventory.sessions.length;
211
170
  }
212
- /**
213
- * Current fraction of write-prepared sessions in the pool.
214
- * @type {number}
171
+ /** @deprecated Starting from v6.5.0 the same session can be reused for
172
+ * different types of transactions.
215
173
  */
216
174
  get currentWriteFraction() {
217
- if (this.available + this.pendingPrepare === 0) {
218
- // There are no sessions in the pool. Define the current write fraction as
219
- // 0.5. That means that if the user has configured a write fraction >= 0.5
220
- // the first session to be created will be a write session, while it will
221
- // otherwise be a read-only session.
222
- return 0.5;
223
- }
224
- const writes = this._inventory["readwrite" /* types.ReadWrite */].length + this.pendingPrepare;
225
- return writes / (this.available + this.pendingPrepare);
175
+ return 0;
226
176
  }
227
177
  /**
228
178
  * Total number of borrowed sessions.
@@ -238,14 +188,9 @@ class SessionPool extends events_1.EventEmitter {
238
188
  get isFull() {
239
189
  return this.size >= this.options.max;
240
190
  }
241
- /**
242
- * Total number of read sessions.
243
- * @type {number}
244
- */
191
+ /** @deprecated Use `size()` instead. */
245
192
  get reads() {
246
- const available = this._inventory["readonly" /* types.ReadOnly */].length;
247
- const borrowed = [...this._inventory.borrowed].filter(session => session.type === "readonly" /* types.ReadOnly */).length;
248
- return available + borrowed;
193
+ return this.size;
249
194
  }
250
195
  /**
251
196
  * Total size of pool.
@@ -254,52 +199,64 @@ class SessionPool extends events_1.EventEmitter {
254
199
  get size() {
255
200
  return this.available + this.borrowed;
256
201
  }
257
- /**
258
- * Total number of write sessions.
259
- * @type {number}
260
- */
202
+ /** @deprecated Use `size()` instead. */
261
203
  get writes() {
262
- const available = this._inventory["readwrite" /* types.ReadWrite */].length;
263
- const borrowed = [...this._inventory.borrowed].filter(session => session.type === "readwrite" /* types.ReadWrite */).length;
264
- return available + borrowed;
204
+ return this.size;
265
205
  }
266
- /**
267
- * Number of sessions currently being prepared for a read/write transaction
268
- * before being released into the pool. This number does not include the
269
- * number of sessions being prepared for a read/write transaction that have
270
- * already been checked out of the pool.
271
- * @type {number}
272
- */
206
+ /** @deprecated Starting v6.5.0 the pending prepare state is obsolete. */
273
207
  get pendingPrepare() {
274
- return this._pendingPrepare;
208
+ return 0;
275
209
  }
276
210
  /**
277
211
  * Number of sessions being created or prepared for a read/write transaction.
278
212
  * @type {number}
279
213
  */
280
214
  get totalPending() {
281
- return this._pending + this._pendingPrepare;
215
+ return this._pending;
282
216
  }
283
- /**
284
- * Current number of waiters for a read-only session.
285
- * @type {number}
286
- */
217
+ /** @deprecated Use totalWaiters instead. */
287
218
  get numReadWaiters() {
288
- return this._waiters["readonly" /* types.ReadOnly */];
219
+ return this.totalWaiters;
289
220
  }
290
- /**
291
- * Current number of waiters for a read/write session.
292
- * @type {number}
293
- */
221
+ /** @deprecated Use totalWaiters instead. */
294
222
  get numWriteWaiters() {
295
- return this._waiters["readwrite" /* types.ReadWrite */];
223
+ return this.totalWaiters;
296
224
  }
297
225
  /**
298
226
  * Sum of read and write waiters.
299
227
  * @type {number}
300
228
  */
301
229
  get totalWaiters() {
302
- return this.numReadWaiters + this.numWriteWaiters;
230
+ return this._waiters;
231
+ }
232
+ /**
233
+ * @constructor
234
+ * @param {Database} database The DB instance.
235
+ * @param {SessionPoolOptions} [options] Configuration options.
236
+ */
237
+ constructor(database, options) {
238
+ super();
239
+ this._pending = 0;
240
+ this._waiters = 0;
241
+ if (options && options.min && options.max && options.min > options.max) {
242
+ throw new TypeError('Min sessions may not be greater than max sessions.');
243
+ }
244
+ this.isOpen = false;
245
+ this.database = database;
246
+ this.options = Object.assign({}, DEFAULTS, options);
247
+ this.options.min = Math.min(this.options.min, this.options.max);
248
+ this._inventory = {
249
+ sessions: [],
250
+ borrowed: new Set(),
251
+ };
252
+ this._waiters = 0;
253
+ this._requests = new p_queue_1.default({
254
+ concurrency: this.options.concurrency,
255
+ });
256
+ this._acquires = new p_queue_1.default({
257
+ concurrency: 1,
258
+ });
259
+ this._traces = new Map();
303
260
  }
304
261
  /**
305
262
  * Closes and the pool.
@@ -309,8 +266,7 @@ class SessionPool extends events_1.EventEmitter {
309
266
  */
310
267
  close(callback) {
311
268
  const sessions = [
312
- ...this._inventory["readonly" /* types.ReadOnly */],
313
- ...this._inventory["readwrite" /* types.ReadWrite */],
269
+ ...this._inventory.sessions,
314
270
  ...this._inventory.borrowed,
315
271
  ];
316
272
  this.isOpen = false;
@@ -320,8 +276,7 @@ class SessionPool extends events_1.EventEmitter {
320
276
  this._requests.onIdle().then(() => {
321
277
  const leaks = this._getLeaks();
322
278
  let error;
323
- this._inventory["readonly" /* types.ReadOnly */] = [];
324
- this._inventory["readwrite" /* types.ReadWrite */] = [];
279
+ this._inventory.sessions = [];
325
280
  this._inventory.borrowed.clear();
326
281
  if (leaks.length) {
327
282
  error = new SessionLeakError(leaks);
@@ -332,18 +287,28 @@ class SessionPool extends events_1.EventEmitter {
332
287
  /**
333
288
  * Retrieve a read session.
334
289
  *
290
+ * @deprecated Use getSession instead.
335
291
  * @param {GetReadSessionCallback} callback The callback function.
336
292
  */
337
293
  getReadSession(callback) {
338
- this._acquire("readonly" /* types.ReadOnly */).then(session => callback(null, session), callback);
294
+ this.getSession((error, session) => callback(error, session));
339
295
  }
340
296
  /**
341
297
  * Retrieve a read/write session.
342
298
  *
299
+ * @deprecated use getSession instead.
343
300
  * @param {GetWriteSessionCallback} callback The callback function.
344
301
  */
345
302
  getWriteSession(callback) {
346
- this._acquire("readwrite" /* types.ReadWrite */).then(session => callback(null, session, session.txn), callback);
303
+ this.getSession(callback);
304
+ }
305
+ /**
306
+ * Retrieve a session.
307
+ *
308
+ * @param {GetSessionCallback} callback The callback function.
309
+ */
310
+ getSession(callback) {
311
+ this._acquire().then(session => callback(null, session, session.txn), callback);
347
312
  }
348
313
  /**
349
314
  * Opens the pool, filling it to the configured number of read and write
@@ -371,14 +336,14 @@ class SessionPool extends events_1.EventEmitter {
371
336
  });
372
337
  }
373
338
  /**
374
- * Releases session back into the pool. If the session is a write session it
375
- * will also prepare a new transaction before releasing it.
339
+ * Releases session back into the pool.
376
340
  *
377
341
  * @throws {Error} For unknown sessions.
378
342
  * @emits SessionPool#available
379
343
  * @emits SessionPool#error
380
- * @emits SessionPool#readonly-available
381
- * @emits SessionPool#readwrite-available
344
+ * @fires SessionPool#session-available
345
+ * @fires @deprecated SessionPool#readonly-available
346
+ * @fires @deprecated SessionPool#readwrite-available
382
347
  * @param {Session} session The session to release.
383
348
  */
384
349
  release(session) {
@@ -395,45 +360,23 @@ class SessionPool extends events_1.EventEmitter {
395
360
  return;
396
361
  }
397
362
  session.lastError = undefined;
398
- // Release it into the pool as a read-only session in the following cases:
399
- // 1. There are more waiters than there are sessions available. Releasing it
400
- // into the pool will ensure that a waiter will be unblocked as soon as
401
- // possible.
402
- // 2. The user has not set a write fraction, but this session has been used
403
- // as a read/write session. This is an indication that the application
404
- // needs read/write sessions, and the pool should try to keep that number
405
- // of read/write sessions dynamically.
406
- // 3. The user has set a write fraction and that fraction has been reached.
407
- const shouldBeWrite = (session.type === "readwrite" /* types.ReadWrite */ && this.options.writes === 0) ||
408
- (this.options.writes > 0 &&
409
- this.currentWriteFraction < this.options.writes);
410
- if (this.totalWaiters > this.available || !shouldBeWrite) {
411
- session.type = "readonly" /* types.ReadOnly */;
412
- this._release(session);
413
- return;
414
- }
415
363
  // Delete the trace associated with this session to mark the session as checked
416
364
  // back into the pool. This will prevent the session to be marked as leaked if
417
365
  // the pool is closed while the session is being prepared.
418
366
  this._traces.delete(session.id);
419
- this._pendingPrepare++;
420
- session.type = "readwrite" /* types.ReadWrite */;
421
- this._prepareTransaction(session)
422
- .catch(() => (session.type = "readonly" /* types.ReadOnly */))
423
- .then(() => {
424
- this._pendingPrepare--;
425
- this._release(session);
426
- });
367
+ // Release it into the pool as a session if there are more waiters than
368
+ // there are sessions available. Releasing it will unblock a waiter as soon
369
+ // as possible.
370
+ this._release(session);
427
371
  }
428
372
  /**
429
373
  * Attempts to borrow a session from the pool.
430
374
  *
431
375
  * @private
432
376
  *
433
- * @param {string} type The desired type to borrow.
434
377
  * @returns {Promise<Session>}
435
378
  */
436
- async _acquire(type) {
379
+ async _acquire() {
437
380
  if (!this.isOpen) {
438
381
  throw new google_gax_1.GoogleError("Database is closed." /* errors.Closed */);
439
382
  }
@@ -448,7 +391,7 @@ class SessionPool extends events_1.EventEmitter {
448
391
  if (elapsed >= timeout) {
449
392
  throw new google_gax_1.GoogleError("Timeout occurred while acquiring session." /* errors.Timeout */);
450
393
  }
451
- const session = await this._getSession(type, startTime);
394
+ const session = await this._getSession(startTime);
452
395
  if (this._isValidSession(session)) {
453
396
  return session;
454
397
  }
@@ -456,26 +399,7 @@ class SessionPool extends events_1.EventEmitter {
456
399
  return getSession();
457
400
  };
458
401
  const session = await this._acquires.add(getSession);
459
- if (type === "readwrite" /* types.ReadWrite */ && session.type === "readonly" /* types.ReadOnly */) {
460
- this._numInProcessPrepare++;
461
- try {
462
- await this._prepareTransaction(session);
463
- }
464
- catch (e) {
465
- if (isSessionNotFoundError(e)) {
466
- this._inventory.borrowed.delete(session);
467
- }
468
- else {
469
- this._release(session);
470
- }
471
- throw e;
472
- }
473
- }
474
- // Mark the session as the type that was requested. This ensures that the
475
- // fraction of read/write sessions in the pool is kept aligned with the
476
- // actual need if the user has not specified a write fraction in the session
477
- // pool options.
478
- session.type = type;
402
+ this._prepareTransaction(session);
479
403
  this._traces.set(session.id, frames);
480
404
  return session;
481
405
  }
@@ -487,22 +411,19 @@ class SessionPool extends events_1.EventEmitter {
487
411
  * @param {Session} session The session object.
488
412
  */
489
413
  _borrow(session) {
490
- const type = session.type;
491
- const index = this._inventory[type].indexOf(session);
414
+ const index = this._inventory.sessions.indexOf(session);
492
415
  this._inventory.borrowed.add(session);
493
- this._inventory[type].splice(index, 1);
416
+ this._inventory.sessions.splice(index, 1);
494
417
  }
495
418
  /**
496
- * Borrows the first session from specific group. This method may only be called if the inventory
497
- * actually contains a session of the desired type.
419
+ * Borrows the first session from the inventory.
498
420
  *
499
421
  * @private
500
422
  *
501
- * @param {string} type The desired session type.
502
423
  * @return {Session}
503
424
  */
504
- _borrowFrom(type) {
505
- const session = this._inventory[type].pop();
425
+ _borrowFrom() {
426
+ const session = this._inventory.sessions.pop();
506
427
  this._inventory.borrowed.add(session);
507
428
  return session;
508
429
  }
@@ -511,67 +432,53 @@ class SessionPool extends events_1.EventEmitter {
511
432
  *
512
433
  * @private
513
434
  *
514
- * @param {string} type The desired session type.
515
435
  * @returns {Promise<Session>}
516
436
  */
517
- _borrowNextAvailableSession(type) {
518
- const hasReads = !!this._inventory["readonly" /* types.ReadOnly */].length;
519
- if (type === "readonly" /* types.ReadOnly */ && hasReads) {
520
- return this._borrowFrom("readonly" /* types.ReadOnly */);
521
- }
522
- const hasWrites = !!this._inventory["readwrite" /* types.ReadWrite */].length;
523
- if (hasWrites) {
524
- return this._borrowFrom("readwrite" /* types.ReadWrite */);
525
- }
526
- return this._borrowFrom("readonly" /* types.ReadOnly */);
437
+ _borrowNextAvailableSession() {
438
+ return this._borrowFrom();
527
439
  }
528
440
  /**
529
- * Attempts to create a single session of a certain type.
441
+ * Attempts to create a single session.
530
442
  *
531
443
  * @private
532
444
  *
533
- * @param {string} type The desired type to create.
534
445
  * @returns {Promise}
535
446
  */
536
- _createSession(type) {
537
- const kind = type === "readonly" /* types.ReadOnly */ ? 'reads' : 'writes';
538
- const options = { [kind]: 1 };
539
- return this._createSessions(options);
447
+ _createSession() {
448
+ return this._createSessions(1);
540
449
  }
541
450
  /**
542
- * Batch creates sessions and prepares any necessary transactions.
451
+ * Batch creates sessions.
543
452
  *
544
453
  * @private
545
454
  *
546
- * @param {object} [options] Config specifying how many sessions to create.
455
+ * @param {number} [amount] Config specifying how many sessions to create.
547
456
  * @returns {Promise}
548
457
  * @emits SessionPool#createError
549
458
  */
550
- async _createSessions({ reads = 0, writes = 0, }) {
459
+ async _createSessions(amount) {
551
460
  const labels = this.options.labels;
552
- let needed = reads + writes;
553
- if (needed <= 0) {
461
+ if (amount <= 0) {
554
462
  return;
555
463
  }
556
- this._pending += needed;
464
+ this._pending += amount;
557
465
  // while we can request as many sessions be created as we want, the backend
558
466
  // will return at most 100 at a time, hence the need for a while loop.
559
- while (needed > 0) {
467
+ while (amount > 0) {
560
468
  let sessions = null;
561
469
  try {
562
470
  [sessions] = await this.database.batchCreateSessions({
563
- count: needed,
471
+ count: amount,
564
472
  labels,
565
473
  });
566
- needed -= sessions.length;
474
+ amount -= sessions.length;
567
475
  }
568
476
  catch (e) {
569
- this._pending -= needed;
477
+ this._pending -= amount;
570
478
  this.emit('createError', e);
571
479
  throw e;
572
480
  }
573
481
  sessions.forEach((session) => {
574
- session.type = writes-- > 0 ? "readwrite" /* types.ReadWrite */ : "readonly" /* types.ReadOnly */;
575
482
  setImmediate(() => {
576
483
  this._inventory.borrowed.add(session);
577
484
  this._pending -= 1;
@@ -614,9 +521,8 @@ class SessionPool extends events_1.EventEmitter {
614
521
  if (!session) {
615
522
  continue;
616
523
  }
617
- const type = session.type;
618
- const index = this._inventory[type].indexOf(session);
619
- this._inventory[type].splice(index, 1);
524
+ const index = this._inventory.sessions.indexOf(session);
525
+ this._inventory.sessions.splice(index, 1);
620
526
  this._destroy(session);
621
527
  }
622
528
  }
@@ -631,7 +537,7 @@ class SessionPool extends events_1.EventEmitter {
631
537
  return;
632
538
  }
633
539
  try {
634
- await this._createSessions({ reads: needed, writes: 0 });
540
+ await this._createSessions(needed);
635
541
  }
636
542
  catch (e) {
637
543
  this.emit('error', e);
@@ -646,10 +552,7 @@ class SessionPool extends events_1.EventEmitter {
646
552
  */
647
553
  _getIdleSessions() {
648
554
  const idlesAfter = this.options.idlesAfter * 60000;
649
- const sessions = [
650
- ...this._inventory["readonly" /* types.ReadOnly */],
651
- ...this._inventory["readwrite" /* types.ReadWrite */],
652
- ];
555
+ const sessions = this._inventory.sessions;
653
556
  return sessions.filter(session => {
654
557
  return Date.now() - session.lastUsed >= idlesAfter;
655
558
  });
@@ -663,48 +566,31 @@ class SessionPool extends events_1.EventEmitter {
663
566
  return [...this._traces.values()].map(SessionPool.formatTrace);
664
567
  }
665
568
  /**
666
- * Returns true if the pool has a session that is usable for the specified
667
- * type, i.e. if a read-only session is requested, it returns true if the
668
- * pool has a read-only or a read/write session. If a read/write session is
669
- * requested, the method only returns true if the pool has a read/write
670
- * session available.
671
- * @param type The type of session.
569
+ * Returns true if the pool has a usable session.
672
570
  * @private
673
571
  */
674
- _hasSessionUsableFor(type) {
675
- return (this._inventory[type].length > 0 ||
676
- this._inventory["readwrite" /* types.ReadWrite */].length > 0);
572
+ _hasSessionUsableFor() {
573
+ return this._inventory.sessions.length > 0;
677
574
  }
678
575
  /**
679
- * Attempts to get a session of a specific type. If the type is unavailable it
680
- * may try to use a different type.
576
+ * Attempts to get a session.
681
577
  *
682
578
  * @private
683
579
  *
684
- * @param {string} type The desired session type.
685
580
  * @param {number} startTime Timestamp to use when determining timeouts.
686
581
  * @returns {Promise<Session>}
687
582
  */
688
- async _getSession(type, startTime) {
689
- if (this._hasSessionUsableFor(type)) {
690
- return this._borrowNextAvailableSession(type);
691
- }
692
- // If a read/write session is requested and the pool has a read-only session
693
- // available, we should return that session unless there is a session
694
- // currently being prepared for read/write that is not already claimed by
695
- // another requester.
696
- if (type === "readwrite" /* types.ReadWrite */ &&
697
- this._hasSessionUsableFor("readonly" /* types.ReadOnly */) &&
698
- this.numWriteWaiters >= this.pendingPrepare) {
699
- return this._borrowNextAvailableSession(type);
583
+ async _getSession(startTime) {
584
+ if (this._hasSessionUsableFor()) {
585
+ return this._borrowNextAvailableSession();
700
586
  }
701
587
  if (this.isFull && this.options.fail) {
702
588
  throw new SessionPoolExhaustedError(this._getLeaks());
703
589
  }
704
590
  let removeOnceCloseListener;
705
591
  let removeListener;
706
- // Wait for the requested type of session to become available.
707
- const availableEvent = type + '-available';
592
+ // Wait for a session to become available.
593
+ const availableEvent = 'session-available';
708
594
  const promises = [
709
595
  new Promise((_, reject) => {
710
596
  const onceCloseListener = () => reject(new google_gax_1.GoogleError("Database is closed." /* errors.Closed */));
@@ -730,23 +616,23 @@ class SessionPool extends events_1.EventEmitter {
730
616
  // Only create a new session if there are more waiters than sessions already
731
617
  // being created. The current requester will be waiter number _numWaiters+1.
732
618
  if (!this.isFull && this.totalPending <= this.totalWaiters) {
733
- let reads = this.options.incStep
619
+ let amount = this.options.incStep
734
620
  ? this.options.incStep
735
621
  : DEFAULTS.incStep;
736
622
  // Create additional sessions if the configured minimum has not been reached.
737
623
  const min = this.options.min ? this.options.min : 0;
738
- if (this.size + this.totalPending + reads < min) {
739
- reads = min - this.size - this.totalPending;
624
+ if (this.size + this.totalPending + amount < min) {
625
+ amount = min - this.size - this.totalPending;
740
626
  }
741
627
  // Make sure we don't create more sessions than the pool should have.
742
- if (reads + this.size > this.options.max) {
743
- reads = this.options.max - this.size;
628
+ if (amount + this.size > this.options.max) {
629
+ amount = this.options.max - this.size;
744
630
  }
745
- if (reads > 0) {
746
- this._pending += reads;
631
+ if (amount > 0) {
632
+ this._pending += amount;
747
633
  promises.push(new Promise((_, reject) => {
748
- this._pending -= reads;
749
- this._createSessions({ reads, writes: 0 }).catch(reject);
634
+ this._pending -= amount;
635
+ this._createSessions(amount).catch(reject);
750
636
  }));
751
637
  }
752
638
  }
@@ -756,17 +642,17 @@ class SessionPool extends events_1.EventEmitter {
756
642
  removeErrorListener = this.removeListener.bind(this, 'createError', reject);
757
643
  }));
758
644
  try {
759
- this._waiters[type]++;
645
+ this._waiters++;
760
646
  await Promise.race(promises);
761
647
  }
762
648
  finally {
763
- this._waiters[type]--;
649
+ this._waiters--;
764
650
  removeOnceCloseListener();
765
651
  removeListener();
766
652
  removeErrorListener();
767
653
  removeTimeoutListener();
768
654
  }
769
- return this._borrowNextAvailableSession(type);
655
+ return this._borrowNextAvailableSession();
770
656
  }
771
657
  /**
772
658
  * Checks to see whether or not session is expired.
@@ -822,11 +708,9 @@ class SessionPool extends events_1.EventEmitter {
822
708
  *
823
709
  * @param {Session} session The session object.
824
710
  * @param {object} options The transaction options.
825
- * @returns {Promise}
826
711
  */
827
- async _prepareTransaction(session) {
712
+ _prepareTransaction(session) {
828
713
  const transaction = session.transaction(session.parent.queryOptions_);
829
- await transaction.begin();
830
714
  session.txn = transaction;
831
715
  }
832
716
  /**
@@ -835,32 +719,19 @@ class SessionPool extends events_1.EventEmitter {
835
719
  * @private
836
720
  *
837
721
  * @fires SessionPool#available
838
- * @fires SessionPool#readonly-available
839
- * @fires SessionPool#readwrite-available
722
+ * @fires SessionPool#session-available
723
+ * @fires @deprecated SessionPool#readonly-available
724
+ * @fires @deprecated SessionPool#readwrite-available
840
725
  * @param {Session} session The session object.
841
726
  */
842
727
  _release(session) {
843
- const type = session.type;
844
- this._inventory[type].push(session);
728
+ this._inventory.sessions.push(session);
845
729
  this._inventory.borrowed.delete(session);
846
730
  this._traces.delete(session.id);
847
731
  this.emit('available');
848
- // Determine the type of waiter to unblock.
849
- let emitType;
850
- if (type === "readonly" /* types.ReadOnly */ &&
851
- !this.numReadWaiters &&
852
- this.numWriteWaiters) {
853
- emitType = "readwrite" /* types.ReadWrite */;
854
- }
855
- else if (type === "readwrite" /* types.ReadWrite */ &&
856
- !this.numWriteWaiters &&
857
- this.numReadWaiters) {
858
- emitType = "readonly" /* types.ReadOnly */;
859
- }
860
- else {
861
- emitType = type;
862
- }
863
- this.emit(emitType + '-available');
732
+ this.emit('session-available');
733
+ this.emit('readonly-available');
734
+ this.emit('readwrite-available');
864
735
  }
865
736
  /**
866
737
  * Starts housekeeping (pinging/evicting) of idle sessions.