@google-cloud/spanner 8.13.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 (44) hide show
  1. package/README.md +1 -16
  2. package/build/src/batch-transaction.js +15 -12
  3. package/build/src/codec.d.ts +18 -30
  4. package/build/src/codec.js +197 -79
  5. package/build/src/common.d.ts +14 -0
  6. package/build/src/common.js +28 -3
  7. package/build/src/database.d.ts +31 -41
  8. package/build/src/database.js +147 -315
  9. package/build/src/helper.d.ts +12 -0
  10. package/build/src/helper.js +44 -0
  11. package/build/src/index.d.ts +24 -8
  12. package/build/src/index.js +303 -147
  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 +13 -6
  18. package/build/src/metrics/constants.js +24 -14
  19. package/build/src/metrics/external-types.d.ts +14 -0
  20. package/build/src/metrics/interceptor.js +39 -44
  21. package/build/src/metrics/metrics-tracer-factory.d.ts +25 -14
  22. package/build/src/metrics/metrics-tracer-factory.js +119 -78
  23. package/build/src/metrics/metrics-tracer.d.ts +19 -6
  24. package/build/src/metrics/metrics-tracer.js +147 -55
  25. package/build/src/metrics/spanner-metrics-exporter.js +4 -0
  26. package/build/src/metrics/transform.d.ts +3 -4
  27. package/build/src/metrics/transform.js +16 -10
  28. package/build/src/multiplexed-session.d.ts +26 -2
  29. package/build/src/multiplexed-session.js +39 -11
  30. package/build/src/partial-result-stream.d.ts +26 -33
  31. package/build/src/partial-result-stream.js +263 -283
  32. package/build/src/request-stream-coordinator.d.ts +88 -0
  33. package/build/src/request-stream-coordinator.js +229 -0
  34. package/build/src/request_id_header.d.ts +6 -4
  35. package/build/src/request_id_header.js +24 -24
  36. package/build/src/session-factory.d.ts +62 -60
  37. package/build/src/session-factory.js +46 -86
  38. package/build/src/session-pool.d.ts +97 -227
  39. package/build/src/session-pool.js +74 -547
  40. package/build/src/session.js +1 -1
  41. package/build/src/transaction-runner.js +1 -12
  42. package/build/src/transaction.d.ts +21 -5
  43. package/build/src/transaction.js +107 -136
  44. package/package.json +28 -37
@@ -21,21 +21,16 @@ const session_pool_1 = require("./session-pool");
21
21
  const common = require('./common-grpc/service-object');
22
22
  /**
23
23
  * Creates a SessionFactory object to manage the creation of
24
- * session-pool and multiplexed session.
24
+ * multiplexed session.
25
25
  *
26
26
  * @class
27
27
  *
28
28
  * @param {Database} database Database object.
29
29
  * @param {String} name Name of the database.
30
- * @param {SessionPoolOptions|SessionPoolInterface} options Session pool
31
- * configuration options or custom pool inteface.
32
30
  */
33
31
  class SessionFactory extends common.GrpcServiceObject {
34
- multiplexedSession_;
35
32
  pool_;
36
- isMultiplexed;
37
- isMultiplexedPartitionOps;
38
- isMultiplexedRW;
33
+ multiplexedSession_;
39
34
  constructor(database, name, poolOptions) {
40
35
  super({
41
36
  parent: database,
@@ -49,125 +44,90 @@ class SessionFactory extends common.GrpcServiceObject {
49
44
  // initialize multiplexed session
50
45
  this.multiplexedSession_ = new multiplexed_session_1.MultiplexedSession(database);
51
46
  this.multiplexedSession_.createSession();
52
- // set the isMultiplexed property to false if multiplexed session is disabled, otherwise set the property to true
53
- this.isMultiplexed = !(process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS === 'false');
54
- // set the isMultiplexedPartitionedOps property to false if multiplexed session is disabled for paritioned ops, otherwise set the property to true
55
- this.isMultiplexedPartitionOps = !(process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS === 'false' &&
56
- process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_PARTITIONED_OPS ===
57
- 'false');
58
- // set the isMultiplexedRW property to false if multiplexed session is disabled for read/write, otherwise set the property to true
59
- this.isMultiplexedRW = !(process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS === 'false' &&
60
- process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW === 'false');
61
- // Regular sessions should only be created if mux is disabled.
62
- if (!this.isMultiplexed) {
63
- this.pool_.on('error', this.emit.bind(database, 'error'));
64
- this.pool_.open();
65
- }
66
47
  }
67
48
  /**
68
- * Retrieves a session, either a regular session or a multiplexed session, based on the environment variable configuration.
49
+ * Synchronously returns a cached multiplexed session if available,
50
+ * otherwise null.
69
51
  *
70
- * If the environment variable `GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS` is set to `false`, the method will attempt to
71
- * retrieve a regular session. Otherwise, it will return a multiplexed session.
52
+ * @returns {Session|null} The cached multiplexed session or null.
53
+ */
54
+ getSessionSync() {
55
+ return this.multiplexedSession_?.getSessionSync?.() ?? null;
56
+ }
57
+ /**
58
+ * Retrieves a multiplexed session.
72
59
  *
73
60
  * @param {GetSessionCallback} callback The callback function.
74
61
  */
75
62
  getSession(callback) {
76
- const sessionHandler = this.isMultiplexed
77
- ? this.multiplexedSession_
78
- : this.pool_;
79
- sessionHandler.getSession((err, session, transaction) => callback(err, session, transaction));
63
+ this.multiplexedSession_.getSession(callback);
80
64
  }
81
65
  /**
82
- * Retrieves a session for partitioned operations, selecting the appropriate session type
83
- * based on whether multiplexed sessions are disabled or not.
84
- *
85
- * If multiplexed sessions are disabled for partitioned ops this methods delegates the request to `getSession()`, which returns
86
- * either a multiplexed session or a regular session based on the env configuration.
87
- *
88
- * If the multiplexed sessions are disabled, a session will get retrieved from the regular session pool.
89
- * Otherwise a multiplexed session will be used.
66
+ * Retrieves a session for partitioned operations.
90
67
  *
68
+ * @deprecated Use {@link SessionFactory#getSession} instead.
91
69
  * @param {GetSessionCallback} callback The callback function.
92
70
  */
93
71
  getSessionForPartitionedOps(callback) {
94
- this.isMultiplexedPartitionOps
95
- ? this.getSession(callback)
96
- : this.pool_.getSession(callback);
72
+ this.getSession(callback);
97
73
  }
98
74
  /**
99
- * Retrieves a session for read write operations, selecting the appropriate session type
100
- * based on whether multiplexed sessions are enabled.
101
- *
102
- * If multiplexed sessions are disabled for read write this methods delegates the request to `getSession()`, which returns
103
- * either a multiplexed session or a regular session based on the env configuration.
104
- *
105
- * If the multiplexed sessions are disabled, a session will get retrieved from the regular session pool.
106
- * Otherise a multiplexed session will be used.
75
+ * Retrieves a session for read/write operations.
107
76
  *
77
+ * @deprecated Use {@link SessionFactory#getSession} instead.
108
78
  * @param {GetSessionCallback} callback The callback function.
109
79
  */
110
80
  getSessionForReadWrite(callback) {
111
- if (this.isMultiplexedRW) {
112
- this.getSession((error, session, transaction) => {
113
- if (error || !session) {
114
- callback(error ?? new Error('No session found'), null);
115
- return;
116
- }
117
- const database = session.parent;
118
- const activeTransaction = transaction ?? session.transaction(database.queryOptions_);
119
- callback(null, session, activeTransaction);
120
- });
121
- }
122
- else {
123
- this.pool_.getSession(callback);
124
- }
81
+ this.getSession((error, session, transaction) => {
82
+ if (error || !session) {
83
+ callback(error ?? new Error('No session found'), null);
84
+ return;
85
+ }
86
+ const database = session.parent;
87
+ const activeTransaction = transaction ?? session.transaction(database?.queryOptions_);
88
+ callback(null, session, activeTransaction);
89
+ });
125
90
  }
126
91
  /**
127
92
  * Returns the regular session pool object.
128
93
  *
94
+ * @deprecated Session pool is deprecated and will be removed in a future release.
129
95
  * @returns {SessionPoolInterface} The session pool used by current instance.
130
96
  */
131
97
  getPool() {
132
98
  return this.pool_;
133
99
  }
134
100
  /**
135
- * Releases a regular session back to the session pool.
101
+ * No-op release method retained for backwards compatibility.
136
102
  *
137
- * This methods does not release a multiplexed session.
138
- *
139
- * It returns a session to the pool after it is no longer needed.
140
- * It is a no-op for multiplexed sessions.
141
- *
142
- * @param {Session} session - The session to be released. This should be an instance of `Session` that was
143
- * previously acquired from the session pool.
144
- *
145
- * @throws {Error} If the session is invalid or cannot be released.
103
+ * @deprecated Multiplexed sessions do not require releasing back to a pool.
104
+ * @param {Session} _session The session object.
146
105
  */
147
- release(session) {
148
- if (!session.metadata?.multiplexed) {
149
- this.pool_.release(session);
150
- }
151
- }
106
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
107
+ release(_session) { }
152
108
  /**
153
- * Returns if a multiplexed is enabled or not.
154
- *
155
- * This method returns true if multiplexed session is enabled, otherwise returns false
109
+ * Checks whether multiplexed session is enabled.
156
110
  *
157
- * @returns {boolean}
111
+ * @deprecated Multiplexed sessions are always enabled.
112
+ * @returns {boolean} Always returns `true`.
158
113
  */
159
114
  isMultiplexedEnabled() {
160
- return this.isMultiplexed;
115
+ return true;
161
116
  }
162
117
  /**
163
- * Returns if a multiplexed is enabled or not for read write transaction.
118
+ * Checks whether multiplexed session is enabled for read/write transactions.
164
119
  *
165
- * This method returns true if multiplexed session is enabled for read write transactions, otherwise returns false
166
- *
167
- * @returns {boolean}
120
+ * @deprecated Multiplexed sessions are always enabled for read/write transactions.
121
+ * @returns {boolean} Always returns `true`.
168
122
  */
169
123
  isMultiplexedEnabledForRW() {
170
- return this.isMultiplexedRW;
124
+ return true;
125
+ }
126
+ /**
127
+ * Closes the session factory and stops background maintenance.
128
+ */
129
+ close() {
130
+ this.multiplexedSession_?.close?.();
171
131
  }
172
132
  }
173
133
  exports.SessionFactory = SessionFactory;