@google-cloud/spanner 9.0.0 → 9.1.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.
Files changed (40) hide show
  1. package/README.md +1 -16
  2. package/build/src/batch-transaction.js +15 -12
  3. package/build/src/codec.d.ts +6 -0
  4. package/build/src/codec.js +99 -34
  5. package/build/src/common.d.ts +14 -0
  6. package/build/src/common.js +27 -1
  7. package/build/src/database.d.ts +31 -41
  8. package/build/src/database.js +122 -313
  9. package/build/src/helper.d.ts +12 -0
  10. package/build/src/helper.js +44 -0
  11. package/build/src/index.d.ts +16 -8
  12. package/build/src/index.js +210 -90
  13. package/build/src/instance.d.ts +15 -2
  14. package/build/src/instance.js +11 -2
  15. package/build/src/instrument.d.ts +12 -1
  16. package/build/src/instrument.js +13 -0
  17. package/build/src/metrics/constants.d.ts +6 -0
  18. package/build/src/metrics/constants.js +6 -1
  19. package/build/src/metrics/interceptor.js +32 -28
  20. package/build/src/metrics/metrics-tracer-factory.d.ts +6 -11
  21. package/build/src/metrics/metrics-tracer-factory.js +62 -64
  22. package/build/src/metrics/metrics-tracer.d.ts +19 -6
  23. package/build/src/metrics/metrics-tracer.js +147 -55
  24. package/build/src/multiplexed-session.d.ts +13 -2
  25. package/build/src/multiplexed-session.js +20 -4
  26. package/build/src/partial-result-stream.d.ts +26 -33
  27. package/build/src/partial-result-stream.js +263 -283
  28. package/build/src/request-stream-coordinator.d.ts +88 -0
  29. package/build/src/request-stream-coordinator.js +229 -0
  30. package/build/src/request_id_header.d.ts +6 -4
  31. package/build/src/request_id_header.js +24 -24
  32. package/build/src/session-factory.d.ts +52 -63
  33. package/build/src/session-factory.js +41 -92
  34. package/build/src/session-pool.d.ts +97 -227
  35. package/build/src/session-pool.js +74 -547
  36. package/build/src/session.js +1 -1
  37. package/build/src/transaction-runner.js +1 -12
  38. package/build/src/transaction.d.ts +5 -5
  39. package/build/src/transaction.js +72 -112
  40. package/package.json +9 -10
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Copyright 2016 Google Inc. All Rights Reserved.
2
+ * Copyright 2017 Google Inc. All Rights Reserved.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -14,29 +14,46 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { EventEmitter } from 'events';
17
- import PQueue from 'p-queue';
18
17
  import { Database } from './database';
19
18
  import { Session } from './session';
20
19
  import { Transaction } from './transaction';
21
20
  import { NormalCallback } from './common';
22
21
  import { GoogleError, grpc } from 'google-gax';
23
- import trace = require('stack-trace');
24
- import { ObservabilityOptions } from './instrument';
25
22
  import { GetSessionCallback } from './session-factory';
26
23
  /**
24
+ * The subset of a `stack-trace` frame used by {@link SessionPool.formatTrace}.
25
+ */
26
+ interface StackFrame {
27
+ getFunctionName(): string | null;
28
+ getMethodName(): string | null;
29
+ getFileName(): string | null;
30
+ getLineNumber(): number | null;
31
+ getColumnNumber(): number | null;
32
+ }
33
+ /**
34
+ * @deprecated Session pool is deprecated and will be removed in a future release.
35
+ Multiplexed sessions are now used for all operations by default, eliminating
36
+ the need for session pooling.
27
37
  * @callback SessionPoolCloseCallback
28
38
  * @param {?Error} error Closing error, if any.
29
39
  */
30
40
  export interface SessionPoolCloseCallback {
31
41
  (error?: SessionLeakError): void;
32
42
  }
33
- /** @deprecated. Use GetSessionCallback instead. */
43
+ /** @deprecated Session pool is deprecated and will be removed in a future release.
44
+ Multiplexed sessions are now used for all operations by default, eliminating
45
+ the need for session pooling. */
34
46
  export type GetReadSessionCallback = NormalCallback<Session>;
35
- /** @deprecated. Use GetSessionCallback instead. */
47
+ /** * @deprecated Session pool is deprecated and will be removed in a future release.
48
+ Multiplexed sessions are now used for all operations by default, eliminating
49
+ the need for session pooling. */
36
50
  export interface GetWriteSessionCallback {
37
51
  (err: Error | null, session?: Session | null, transaction?: Transaction | null): void;
38
52
  }
39
- /**
53
+ /** * @deprecated Session pool is deprecated and will be removed in a future release.
54
+ Multiplexed sessions are now used for all operations by default, eliminating
55
+ the need for session pooling.
56
+
40
57
  * Interface for implementing custom session pooling logic, it should extend the
41
58
  * {@link https://nodejs.org/api/events.html|EventEmitter} class and emit any
42
59
  * asynchronous errors via an error event.
@@ -50,65 +67,71 @@ export interface GetWriteSessionCallback {
50
67
  */
51
68
  export interface SessionPoolInterface extends EventEmitter {
52
69
  /**
53
- * Will be called via {@link Database#close}. Indicates that the pool should
54
- * perform any necessary teardown actions to its resources.
70
+ * When called should return a session that can be used for all types of
71
+ * transactions and operations.
55
72
  *
56
- * @name SessionPoolInterface#close
57
- * @param {SessionPoolCloseCallback} callback The callback function.
73
+ * @name SessionPoolInterface#getSession
74
+ * @param {GetSessionCallback} callback The callback function.
58
75
  */
76
+ getSession(callback: GetSessionCallback): void;
59
77
  /**
60
- * Will be called by the Database object, should be used to start creating
61
- * sessions/etc.
78
+ *To be called when closing the pool.
62
79
  *
63
- * @name SessionPoolInterface#open
80
+ * @name SessionPoolInterface#close
81
+ * @param {SessionPoolCloseCallback} callback The callback function.
64
82
  */
83
+ close(callback: SessionPoolCloseCallback): void;
65
84
  /**
66
- * When called returns a session.
85
+ * @deprecated Use getSession instead.
67
86
  *
68
- * @name SessionPoolInterface#getSession
69
- * @param {GetSessionCallback} callback The callback function.
70
- */
71
- /**
72
- * When called returns a session.
87
+ * When called returns a session that can be used for read-only transactions
88
+ * and single-use reads/queries.
73
89
  *
74
- * @deprecated Use getSession instead.
75
90
  * @name SessionPoolInterface#getReadSession
76
91
  * @param {GetReadSessionCallback} callback The callback function.
77
92
  */
93
+ getReadSession(callback: GetReadSessionCallback): void;
78
94
  /**
79
- * When called returns a session.
80
- *
81
95
  * @deprecated Use getSession instead.
96
+ *
97
+ * When called returns a session with a pre-allocated read/write transaction.
98
+ *
82
99
  * @name SessionPoolInterface#getWriteSession
83
100
  * @param {GetWriteSessionCallback} callback The callback function.
84
101
  */
102
+ getWriteSession(callback: GetWriteSessionCallback): void;
103
+ /**
104
+ * To be called when opening the pool.
105
+ *
106
+ * @name SessionPoolInterface#open
107
+ */
108
+ open(): void;
85
109
  /**
86
110
  * To be called when releasing a session back into the pool.
87
111
  *
88
112
  * @name SessionPoolInterface#release
89
113
  * @param {Session} session The session to be released.
90
114
  */
91
- close(callback: SessionPoolCloseCallback): void;
92
- open(): void;
93
- getSession(callback: GetSessionCallback): void;
94
- getReadSession(callback: GetReadSessionCallback): void;
95
- getWriteSession(callback: GetWriteSessionCallback): void;
96
115
  release(session: Session): void;
97
116
  }
98
117
  /**
99
118
  * Session pool configuration options.
100
119
  *
120
+ * @deprecated Session pool is deprecated and will be removed in a future release.
121
+ Multiplexed sessions are now used for all operations by default, eliminating
122
+ the need for session pooling.
123
+ *
101
124
  * @typedef {object} SessionPoolOptions
102
125
  * @property {number} [acquireTimeout=Infinity] Time in milliseconds before
103
126
  * giving up trying to acquire a session. If the specified value is
104
127
  * `Infinity`, a timeout will not occur.
105
- * @property {number} [concurrency=Infinity] How many concurrent requests the pool is
106
- * allowed to make.
107
- * @property {boolean} [fail=false] If set to true, an error will be thrown when
128
+ * @property {number} [concurrency=Infinity] How many concurrent requests the
129
+ * pool is allowed to make.
130
+ * @property {boolean} [fail=false] If set to true, an error will be thrown if
108
131
  * there are no available sessions for a request.
109
132
  * @property {number} [idlesAfter=10] How long until a resource becomes idle, in
110
133
  * minutes.
111
- * @property {number} [keepAlive=30] How often to ping idle sessions, in
134
+ * @property {number} [keepAlive=30] How often to ping idle resources, in
112
135
  * minutes. Must be less than 1 hour.
113
136
  * @property {Object<string, string>} [labels] Labels to apply to any session
114
137
  * created by the pool.
@@ -118,9 +141,8 @@ export interface SessionPoolInterface extends EventEmitter {
118
141
  * the pool at any given time.
119
142
  * @property {number} [min=25] Minimum number of resources to keep in the pool at
120
143
  * any given time.
121
- * @property {number} [writes=0.0]. Deprecated.
122
- * @property {number} [incStep=25] The number of new sessions to create when at
123
- * least one more session is needed.
144
+ * @property {number} [incStep=25] Number of sessions to create in one batch when
145
+ * at least one more session is needed.
124
146
  */
125
147
  export interface SessionPoolOptions {
126
148
  acquireTimeout?: number;
@@ -137,10 +159,6 @@ export interface SessionPoolOptions {
137
159
  max?: number;
138
160
  maxIdle?: number;
139
161
  min?: number;
140
- /**
141
- * @deprecated. Starting from v6.5.0 the same session can be reused for
142
- * different types of transactions.
143
- */
144
162
  writes?: number;
145
163
  incStep?: number;
146
164
  /**
@@ -151,6 +169,7 @@ export interface SessionPoolOptions {
151
169
  /**
152
170
  * Error to be thrown when attempting to release unknown resources.
153
171
  *
172
+ * @deprecated Session pool is deprecated and will be removed in a future release.
154
173
  * @private
155
174
  */
156
175
  export declare class ReleaseError extends GoogleError {
@@ -160,35 +179,39 @@ export declare class ReleaseError extends GoogleError {
160
179
  /**
161
180
  * Error to be thrown when session leaks are detected.
162
181
  *
182
+ * @deprecated Session pool is deprecated and will be removed in a future release.
163
183
  * @private
164
184
  */
165
185
  export declare class SessionLeakError extends GoogleError {
166
186
  messages: string[];
167
- constructor(leaks: string[]);
187
+ constructor(leaks?: string[]);
168
188
  }
169
189
  /**
170
190
  * Error to be thrown when the session pool is exhausted.
191
+ *
192
+ * @deprecated Session pool is deprecated and will be removed in a future release.
171
193
  */
172
194
  export declare class SessionPoolExhaustedError extends GoogleError {
173
195
  messages: string[];
174
- constructor(leaks: string[]);
196
+ constructor(leaks?: string[]);
175
197
  }
176
198
  /**
177
199
  * Checks whether the given error is a 'Session not found' error.
200
+ * @deprecated Session pool is deprecated and will be removed in a future release.
178
201
  * @param error the error to check
179
202
  * @return true if the error is a 'Session not found' error, and otherwise false.
180
203
  */
181
204
  export declare function isSessionNotFoundError(error: grpc.ServiceError | undefined): boolean;
182
- interface SessionInventory {
183
- sessions: Session[];
184
- borrowed: Set<Session>;
185
- }
186
- /** @deprecated. */
205
+ /** @deprecated Session pool is deprecated and will be removed in a future release. */
187
206
  export interface CreateSessionsOptions {
188
207
  writes?: number;
189
208
  reads?: number;
190
209
  }
191
210
  /**
211
+ * * @deprecated Session pool is deprecated and will be removed in a future release.
212
+ Multiplexed sessions are now used for all operations by default, eliminating
213
+ the need for session pooling.
214
+
192
215
  * Class used to manage connections to Spanner.
193
216
  *
194
217
  * **You don't need to use this class directly, connections will be handled for
@@ -201,32 +224,28 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
201
224
  database: Database;
202
225
  isOpen: boolean;
203
226
  options: SessionPoolOptions;
204
- _acquires: PQueue;
205
- _evictHandle: NodeJS.Timer;
206
- _inventory: SessionInventory;
207
- _onClose: Promise<void>;
208
- _pending: number;
209
- _waiters: number;
210
- _pingHandle: NodeJS.Timer;
211
- _requests: PQueue;
212
- _traces: Map<string, trace.StackFrame[]>;
213
- _observabilityOptions?: ObservabilityOptions;
214
227
  /**
215
228
  * Formats stack trace objects into Node-like stack trace.
216
229
  *
230
+ * @deprecated Session pool is deprecated and will be removed in a future release.
217
231
  * @param {object[]} trace The trace object.
218
232
  * @return {string}
219
233
  */
220
- static formatTrace(frames: trace.StackFrame[]): string;
221
- /**
222
- * Total number of available sessions.
223
- * @type {number}
224
- */
234
+ static formatTrace(frames: StackFrame[]): string;
235
+ /** @deprecated Use totalWaiters instead. */
225
236
  get available(): number;
226
237
  /** @deprecated Starting from v6.5.0 the same session can be reused for
227
238
  * different types of transactions.
228
239
  */
229
240
  get currentWriteFraction(): number;
241
+ /** @deprecated Starting from v6.5.0 the same session can be reused for
242
+ * different types of transactions.
243
+ */
244
+ get availableReads(): number;
245
+ /** @deprecated Starting from v6.5.0 the same session can be reused for
246
+ * different types of transactions.
247
+ */
248
+ get availableWrites(): number;
230
249
  /**
231
250
  * Total number of borrowed sessions.
232
251
  * @type {number}
@@ -240,7 +259,7 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
240
259
  /** @deprecated Use `size()` instead. */
241
260
  get reads(): number;
242
261
  /**
243
- * Total size of pool.
262
+ * Total number of sessions in the pool.
244
263
  * @type {number}
245
264
  */
246
265
  get size(): number;
@@ -248,8 +267,12 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
248
267
  get writes(): number;
249
268
  /** @deprecated Starting v6.5.0 the pending prepare state is obsolete. */
250
269
  get pendingPrepare(): number;
270
+ /** @deprecated Use totalPending instead. */
271
+ get numPendingReads(): number;
272
+ /** @deprecated Use totalPending instead. */
273
+ get numPendingWrites(): number;
251
274
  /**
252
- * Number of sessions being created or prepared for a read/write transaction.
275
+ * Total number of sessions currently being created by the pool.
253
276
  * @type {number}
254
277
  */
255
278
  get totalPending(): number;
@@ -258,7 +281,7 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
258
281
  /** @deprecated Use totalWaiters instead. */
259
282
  get numWriteWaiters(): number;
260
283
  /**
261
- * Sum of read and write waiters.
284
+ * Total number of waiters for a session from the pool.
262
285
  * @type {number}
263
286
  */
264
287
  get totalWaiters(): number;
@@ -269,7 +292,7 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
269
292
  */
270
293
  constructor(database: Database, options?: SessionPoolOptions);
271
294
  /**
272
- * Closes and the pool.
295
+ * Closes the pool.
273
296
  *
274
297
  * @emits SessionPool#close
275
298
  * @param {SessionPoolCloseCallback} callback The callback function.
@@ -279,18 +302,24 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
279
302
  * Retrieve a read session.
280
303
  *
281
304
  * @deprecated Use getSession instead.
305
+ *
282
306
  * @param {GetReadSessionCallback} callback The callback function.
283
307
  */
284
308
  getReadSession(callback: GetReadSessionCallback): void;
285
309
  /**
286
310
  * Retrieve a read/write session.
287
311
  *
288
- * @deprecated use getSession instead.
312
+ * @deprecated Use getSession instead.
313
+ *
289
314
  * @param {GetWriteSessionCallback} callback The callback function.
290
315
  */
291
316
  getWriteSession(callback: GetWriteSessionCallback): void;
292
317
  /**
293
- * Retrieve a session.
318
+ * Retrieve a session for read or read/write operations.
319
+ *
320
+ * Session pooling has been replaced by multiplexed sessions, so this returns
321
+ * the database's shared multiplexed session, together with a new read/write
322
+ * transaction, instead of a pooled session.
294
323
  *
295
324
  * @param {GetSessionCallback} callback The callback function.
296
325
  */
@@ -308,170 +337,11 @@ export declare class SessionPool extends EventEmitter implements SessionPoolInte
308
337
  *
309
338
  * @throws {Error} For unknown sessions.
310
339
  * @emits SessionPool#available
311
- * @emits SessionPool#error
312
- * @fires SessionPool#session-available
340
+ * @emits SessionPool#session-available
313
341
  * @fires @deprecated SessionPool#readonly-available
314
342
  * @fires @deprecated SessionPool#readwrite-available
315
343
  * @param {Session} session The session to release.
316
344
  */
317
345
  release(session: Session): void;
318
- /**
319
- * Attempts to borrow a session from the pool.
320
- *
321
- * @private
322
- *
323
- * @returns {Promise<Session>}
324
- */
325
- _acquire(): Promise<Session>;
326
- /**
327
- * Moves a session into the borrowed group.
328
- *
329
- * @private
330
- *
331
- * @param {Session} session The session object.
332
- */
333
- _borrow(session: Session): void;
334
- /**
335
- * Borrows the first session from the inventory.
336
- *
337
- * @private
338
- *
339
- * @return {Session}
340
- */
341
- _borrowFrom(): Session;
342
- /**
343
- * Grabs the next available session.
344
- *
345
- * @private
346
- *
347
- * @returns {Promise<Session>}
348
- */
349
- _borrowNextAvailableSession(): Session;
350
- /**
351
- * Attempts to create a single session.
352
- *
353
- * @private
354
- *
355
- * @returns {Promise}
356
- */
357
- _createSession(): Promise<void>;
358
- /**
359
- * Batch creates sessions.
360
- *
361
- * @private
362
- *
363
- * @param {number} [amount] Config specifying how many sessions to create.
364
- * @returns {Promise}
365
- * @emits SessionPool#createError
366
- */
367
- _createSessions(amount: number): Promise<void>;
368
- /**
369
- * Attempts to delete a session, optionally creating a new one of the same
370
- * type if the pool is still open and we're under the configured min value.
371
- *
372
- * @private
373
- *
374
- * @fires SessionPool#error
375
- * @param {Session} session The session to delete.
376
- * @returns {Promise}
377
- */
378
- _destroy(session: Session): Promise<void>;
379
- /**
380
- * Deletes idle sessions that exceed the maxIdle configuration.
381
- *
382
- * @private
383
- */
384
- _evictIdleSessions(): void;
385
- /**
386
- * Fills the pool with the minimum number of sessions.
387
- *
388
- * @return {Promise}
389
- */
390
- _fill(): Promise<void>;
391
- /**
392
- * Retrieves a list of all the idle sessions.
393
- *
394
- * @private
395
- *
396
- * @returns {Session[]}
397
- */
398
- _getIdleSessions(): Session[];
399
- /**
400
- * Returns stack traces for sessions that have not been released.
401
- *
402
- * @return {string[]}
403
- */
404
- _getLeaks(): string[];
405
- /**
406
- * Returns true if the pool has a usable session.
407
- * @private
408
- */
409
- _hasSessionUsableFor(): boolean;
410
- /**
411
- * Attempts to get a session.
412
- *
413
- * @private
414
- *
415
- * @param {number} startTime Timestamp to use when determining timeouts.
416
- * @returns {Promise<Session>}
417
- */
418
- _getSession(startTime: number): Promise<Session>;
419
- /**
420
- * Checks to see whether or not session is expired.
421
- *
422
- * @param {Session} session The session to check.
423
- * @returns {boolean}
424
- */
425
- _isValidSession(session: Session): boolean;
426
- /**
427
- * Pings an individual session.
428
- *
429
- * @private
430
- *
431
- * @param {Session} session The session to ping.
432
- * @returns {Promise}
433
- */
434
- _ping(session: Session): Promise<void>;
435
- /**
436
- * Makes a keep alive request to all the idle sessions.
437
- *
438
- * @private
439
- *
440
- * @returns {Promise}
441
- */
442
- _pingIdleSessions(): Promise<void>;
443
- /**
444
- * Creates a transaction for a session.
445
- *
446
- * @private
447
- *
448
- * @param {Session} session The session object.
449
- * @param {object} options The transaction options.
450
- */
451
- _prepareTransaction(session: Session): void;
452
- /**
453
- * Releases a session back into the pool.
454
- *
455
- * @private
456
- *
457
- * @fires SessionPool#available
458
- * @fires SessionPool#session-available
459
- * @fires @deprecated SessionPool#readonly-available
460
- * @fires @deprecated SessionPool#readwrite-available
461
- * @param {Session} session The session object.
462
- */
463
- _release(session: Session): void;
464
- /**
465
- * Starts housekeeping (pinging/evicting) of idle sessions.
466
- *
467
- * @private
468
- */
469
- _startHouseKeeping(): void;
470
- /**
471
- * Stops housekeeping.
472
- *
473
- * @private
474
- */
475
- _stopHouseKeeping(): void;
476
346
  }
477
347
  export {};