@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
@@ -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,136 +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
- * Synchronously returns a cached multiplexed session if multiplexed sessions
69
- * are enabled and one is available, otherwise null.
49
+ * Synchronously returns a cached multiplexed session if available,
50
+ * otherwise null.
70
51
  *
71
52
  * @returns {Session|null} The cached multiplexed session or null.
72
53
  */
73
54
  getSessionSync() {
74
- return this.isMultiplexed
75
- ? (this.multiplexedSession_?.getSessionSync?.() ?? null)
76
- : null;
55
+ return this.multiplexedSession_?.getSessionSync?.() ?? null;
77
56
  }
78
57
  /**
79
- * Retrieves a session, either a regular session or a multiplexed session, based on the environment variable configuration.
80
- *
81
- * If the environment variable `GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS` is set to `false`, the method will attempt to
82
- * retrieve a regular session. Otherwise, it will return a multiplexed session.
58
+ * Retrieves a multiplexed session.
83
59
  *
84
60
  * @param {GetSessionCallback} callback The callback function.
85
61
  */
86
62
  getSession(callback) {
87
- const sessionHandler = this.isMultiplexed
88
- ? this.multiplexedSession_
89
- : this.pool_;
90
- sessionHandler.getSession(callback);
63
+ this.multiplexedSession_.getSession(callback);
91
64
  }
92
65
  /**
93
- * Retrieves a session for partitioned operations, selecting the appropriate session type
94
- * based on whether multiplexed sessions are disabled or not.
95
- *
96
- * If multiplexed sessions are disabled for partitioned ops this methods delegates the request to `getSession()`, which returns
97
- * either a multiplexed session or a regular session based on the env configuration.
98
- *
99
- * If the multiplexed sessions are disabled, a session will get retrieved from the regular session pool.
100
- * Otherwise a multiplexed session will be used.
66
+ * Retrieves a session for partitioned operations.
101
67
  *
68
+ * @deprecated Use {@link SessionFactory#getSession} instead.
102
69
  * @param {GetSessionCallback} callback The callback function.
103
70
  */
104
71
  getSessionForPartitionedOps(callback) {
105
- this.isMultiplexedPartitionOps
106
- ? this.getSession(callback)
107
- : this.pool_.getSession(callback);
72
+ this.getSession(callback);
108
73
  }
109
74
  /**
110
- * Retrieves a session for read write operations, selecting the appropriate session type
111
- * based on whether multiplexed sessions are enabled.
112
- *
113
- * If multiplexed sessions are disabled for read write this methods delegates the request to `getSession()`, which returns
114
- * either a multiplexed session or a regular session based on the env configuration.
115
- *
116
- * If the multiplexed sessions are disabled, a session will get retrieved from the regular session pool.
117
- * Otherise a multiplexed session will be used.
75
+ * Retrieves a session for read/write operations.
118
76
  *
77
+ * @deprecated Use {@link SessionFactory#getSession} instead.
119
78
  * @param {GetSessionCallback} callback The callback function.
120
79
  */
121
80
  getSessionForReadWrite(callback) {
122
- if (this.isMultiplexedRW) {
123
- this.getSession((error, session, transaction) => {
124
- if (error || !session) {
125
- callback(error ?? new Error('No session found'), null);
126
- return;
127
- }
128
- const database = session.parent;
129
- const activeTransaction = transaction ?? session.transaction(database.queryOptions_);
130
- callback(null, session, activeTransaction);
131
- });
132
- }
133
- else {
134
- this.pool_.getSession(callback);
135
- }
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
+ });
136
90
  }
137
91
  /**
138
92
  * Returns the regular session pool object.
139
93
  *
94
+ * @deprecated Session pool is deprecated and will be removed in a future release.
140
95
  * @returns {SessionPoolInterface} The session pool used by current instance.
141
96
  */
142
97
  getPool() {
143
98
  return this.pool_;
144
99
  }
145
100
  /**
146
- * Releases a regular session back to the session pool.
147
- *
148
- * This methods does not release a multiplexed session.
101
+ * No-op release method retained for backwards compatibility.
149
102
  *
150
- * It returns a session to the pool after it is no longer needed.
151
- * It is a no-op for multiplexed sessions.
152
- *
153
- * @param {Session} session - The session to be released. This should be an instance of `Session` that was
154
- * previously acquired from the session pool.
155
- *
156
- * @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.
157
105
  */
158
- release(session) {
159
- if (!session.metadata?.multiplexed) {
160
- this.pool_.release(session);
161
- }
162
- }
106
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
107
+ release(_session) { }
163
108
  /**
164
- * Returns if a multiplexed is enabled or not.
165
- *
166
- * This method returns true if multiplexed session is enabled, otherwise returns false
109
+ * Checks whether multiplexed session is enabled.
167
110
  *
168
- * @returns {boolean}
111
+ * @deprecated Multiplexed sessions are always enabled.
112
+ * @returns {boolean} Always returns `true`.
169
113
  */
170
114
  isMultiplexedEnabled() {
171
- return this.isMultiplexed;
115
+ return true;
172
116
  }
173
117
  /**
174
- * Returns if a multiplexed is enabled or not for read write transaction.
118
+ * Checks whether multiplexed session is enabled for read/write transactions.
175
119
  *
176
- * This method returns true if multiplexed session is enabled for read write transactions, otherwise returns false
177
- *
178
- * @returns {boolean}
120
+ * @deprecated Multiplexed sessions are always enabled for read/write transactions.
121
+ * @returns {boolean} Always returns `true`.
179
122
  */
180
123
  isMultiplexedEnabledForRW() {
181
- return this.isMultiplexedRW;
124
+ return true;
125
+ }
126
+ /**
127
+ * Closes the session factory and stops background maintenance.
128
+ */
129
+ close() {
130
+ this.multiplexedSession_?.close?.();
182
131
  }
183
132
  }
184
133
  exports.SessionFactory = SessionFactory;