@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
@@ -233,7 +233,7 @@ class Session extends common.GrpcServiceObject {
233
233
  const reqOpts = {
234
234
  name: this.formattedName_,
235
235
  };
236
- const headers = this.commonHeaders_;
236
+ const headers = { ...this.commonHeaders_ };
237
237
  if (this._getSpanner().routeToLeaderEnabled) {
238
238
  (0, common_1.addLeaderAwareRoutingHeader)(headers);
239
239
  }
@@ -20,7 +20,6 @@ exports.isRetryableInternalError = isRetryableInternalError;
20
20
  const promisify_1 = require("@google-cloud/promisify");
21
21
  const google_gax_1 = require("google-gax");
22
22
  const through = require("through2");
23
- const session_pool_1 = require("./session-pool");
24
23
  const spanner_api_1 = require("@google-cloud/spanner-api");
25
24
  var google = spanner_api_1.protos.google;
26
25
  var IsolationLevel = google.spanner.v1.TransactionOptions.IsolationLevel;
@@ -104,20 +103,13 @@ class Runner {
104
103
  const nanosInMs = Math.floor(retryDelay.nanos) / 1e6;
105
104
  return secondsInMs + nanosInMs;
106
105
  }
107
- // A 'Session not found' error without any specific retry info should not
108
- // cause any delay between retries.
109
- if ((0, session_pool_1.isSessionNotFoundError)(err)) {
110
- return 0;
111
- }
112
106
  // Max backoff should be 32 seconds.
113
107
  return (Math.pow(2, Math.min(this.attempts, 5)) * 1000 +
114
108
  Math.floor(Math.random() * 1000));
115
109
  }
116
110
  /** Returns whether the given error should cause a transaction retry. */
117
111
  shouldRetry(err) {
118
- return (RETRYABLE.includes(err.code) ||
119
- (0, session_pool_1.isSessionNotFoundError)(err) ||
120
- isRetryableInternalError(err));
112
+ return RETRYABLE.includes(err.code) || isRetryableInternalError(err);
121
113
  }
122
114
  /**
123
115
  * Retrieves a transaction to run against.
@@ -167,9 +159,6 @@ class Runner {
167
159
  finally {
168
160
  this.multiplexedSessionPreviousTransactionId = transaction.id;
169
161
  }
170
- // Note that if the error is a 'Session not found' error, it will be
171
- // thrown here. We do this to bubble this error up to the caller who is
172
- // responsible for retrying the transaction on a different session.
173
162
  if (!RETRYABLE.includes(lastError.code) &&
174
163
  !isRetryableInternalError(lastError)) {
175
164
  throw lastError;
@@ -869,11 +869,11 @@ export declare class Snapshot extends EventEmitter {
869
869
  * @property {object} [gaxOptions] Request configuration options,
870
870
  * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
871
871
  * for more details.
872
- * @property {number} [maxResumeRetries] The maximum number of times that the
873
- * stream will retry to push data downstream, when the downstream indicates
874
- * that it is not ready for any more data. Increase this value if you
875
- * experience 'Stream is still not ready to receive data' errors as a
876
- * result of a slow writer in your receiving stream.
872
+ * @property {number} [maxResumeRetries] The maximum number of times that the
873
+ * query will retry on retryable errors (such as UNAVAILABLE). Only
874
+ * applicable to non-streaming queries executed via {@link Snapshot#run}.
875
+ * For streaming queries ({@link Snapshot#runStream}), this option is
876
+ * deprecated as backpressure is managed automatically.
877
877
  * @property {object} [directedReadOptions]
878
878
  * Indicates which replicas or regions should be used for non-transactional reads or queries.
879
879
  */
@@ -372,8 +372,10 @@ class Snapshot extends events_1.EventEmitter {
372
372
  const callback = typeof gaxOptionsOrCallback === 'function' ? gaxOptionsOrCallback : cb;
373
373
  const session = this.session.formattedName_;
374
374
  const options = this._options;
375
- if (this.multiplexedSessionPreviousTransactionId &&
376
- this.session.parent.isMuxEnabledForRW_) {
375
+ if (this._options.readWrite) {
376
+ this._inlineBeginStarted = true;
377
+ }
378
+ if (this.multiplexedSessionPreviousTransactionId) {
377
379
  options.readWrite.multiplexedSessionPreviousTransactionId =
378
380
  this.multiplexedSessionPreviousTransactionId;
379
381
  }
@@ -391,12 +393,6 @@ class Snapshot extends events_1.EventEmitter {
391
393
  if (this.requestOptions) {
392
394
  reqOpts.requestOptions = this.requestOptions;
393
395
  }
394
- const headers = this.commonHeaders_;
395
- if (this._getSpanner().routeToLeaderEnabled &&
396
- (this._options.readWrite !== undefined ||
397
- this._options.partitionedDml !== undefined)) {
398
- (0, common_1.addLeaderAwareRoutingHeader)(headers);
399
- }
400
396
  return (0, instrument_1.startTrace)('Snapshot.begin', {
401
397
  transactionTag: this.requestOptions?.transactionTag,
402
398
  ...this._traceConfig,
@@ -407,10 +403,12 @@ class Snapshot extends events_1.EventEmitter {
407
403
  method: 'beginTransaction',
408
404
  reqOpts,
409
405
  gaxOpts,
410
- headers: (0, request_id_header_1.injectRequestIDIntoHeaders)(headers, this.session),
406
+ headers: (0, request_id_header_1.injectRequestIDIntoHeaders)(this.commonHeaders_, this.session),
411
407
  }, (err, resp) => {
412
408
  if (err) {
409
+ this._inlineBeginStarted = false;
413
410
  (0, instrument_1.setSpanError)(span, err);
411
+ this._releaseWaitingRequests(err);
414
412
  }
415
413
  else {
416
414
  this._updatePrecommitToken(resp);
@@ -592,7 +590,9 @@ class Snapshot extends events_1.EventEmitter {
592
590
  * ```
593
591
  */
594
592
  createReadStream(table, request = {}) {
595
- const { gaxOptions, json, jsonOptions, maxResumeRetries, requestOptions, columnsMetadata, } = request;
593
+ const { gaxOptions, json, jsonOptions, maxResumeRetries, requestOptions, columnsMetadata, keys: _omittedKeys, ranges: _omittedRanges, directedReadOptions: rawDirectedReadOptions, ...cleanRequest } = request;
594
+ void _omittedKeys;
595
+ void _omittedRanges;
596
596
  const keySet = Snapshot.encodeKeySet(request);
597
597
  const transaction = {};
598
598
  if (this.id) {
@@ -604,23 +604,11 @@ class Snapshot extends events_1.EventEmitter {
604
604
  else {
605
605
  transaction.singleUse = this._options;
606
606
  }
607
- if (!this.id &&
608
- this._options.readWrite &&
609
- this.session.parent.isMuxEnabledForRW_) {
607
+ if (!this.id && this._options.readWrite) {
610
608
  this._setPreviousTransactionId(transaction);
611
609
  }
612
- const directedReadOptions = this._getDirectedReadOptions(request.directedReadOptions);
613
- request = Object.assign({}, request);
614
- delete request.gaxOptions;
615
- delete request.json;
616
- delete request.jsonOptions;
617
- delete request.maxResumeRetries;
618
- delete request.keys;
619
- delete request.ranges;
620
- delete request.requestOptions;
621
- delete request.directedReadOptions;
622
- delete request.columnsMetadata;
623
- const reqOpts = Object.assign(request, {
610
+ const directedReadOptions = this._getDirectedReadOptions(rawDirectedReadOptions);
611
+ const reqOpts = Object.assign({}, cleanRequest, {
624
612
  session: this.session.formattedName_,
625
613
  requestOptions: this.configureTagOptions(typeof transaction.singleUse !== 'undefined', this.requestOptions?.transactionTag ?? undefined, requestOptions),
626
614
  directedReadOptions: directedReadOptions,
@@ -628,12 +616,6 @@ class Snapshot extends events_1.EventEmitter {
628
616
  table,
629
617
  keySet,
630
618
  });
631
- const headers = this.commonHeaders_;
632
- if (this._getSpanner().routeToLeaderEnabled &&
633
- (this._options.readWrite !== undefined ||
634
- this._options.partitionedDml !== undefined)) {
635
- (0, common_1.addLeaderAwareRoutingHeader)(headers);
636
- }
637
619
  const traceConfig = {
638
620
  ...this._traceConfig,
639
621
  tableName: table,
@@ -669,7 +651,7 @@ class Snapshot extends events_1.EventEmitter {
669
651
  method: 'streamingRead',
670
652
  reqOpts: Object.assign({}, reqOpts, { resumeToken }),
671
653
  gaxOpts: gaxOptions,
672
- headers: (0, request_id_header_1.injectRequestIDIntoHeaders)(headers, this.session, nthRequest, attempt),
654
+ headers: (0, request_id_header_1.injectRequestIDIntoHeaders)(this.commonHeaders_, this.session, nthRequest, attempt),
673
655
  });
674
656
  };
675
657
  const resultStream = (0, partial_result_stream_1.partialResultStream)(this._wrapWithIdWaiter(makeRequest), {
@@ -798,6 +780,8 @@ class Snapshot extends events_1.EventEmitter {
798
780
  return (0, instrument_1.startTrace)('Snapshot.read', {
799
781
  tableName: table,
800
782
  ...this._traceConfig,
783
+ transactionTag: this.requestOptions?.transactionTag,
784
+ requestTag: request?.requestOptions?.requestTag,
801
785
  }, span => {
802
786
  this.createReadStream(table, request)
803
787
  .on('error', err => {
@@ -831,8 +815,9 @@ class Snapshot extends events_1.EventEmitter {
831
815
  let stats;
832
816
  let metadata;
833
817
  (0, instrument_1.startTrace)('Snapshot.run', {
834
- ...query,
835
818
  ...this._traceConfig,
819
+ transactionTag: this.requestOptions?.transactionTag,
820
+ ...(0, instrument_1.getQueryTraceConfig)(query),
836
821
  }, span => {
837
822
  this.runStream(query)
838
823
  .on('error', err => {
@@ -890,9 +875,7 @@ class Snapshot extends events_1.EventEmitter {
890
875
  else {
891
876
  transaction.singleUse = this._options;
892
877
  }
893
- if (!this.id &&
894
- this._options.readWrite &&
895
- this.session.parent.isMuxEnabledForRW_) {
878
+ if (!this.id && this._options.readWrite) {
896
879
  this._setPreviousTransactionId(transaction);
897
880
  }
898
881
  formattedRequest = Object.assign({}, rawQuery, {
@@ -905,17 +888,10 @@ class Snapshot extends events_1.EventEmitter {
905
888
  paramTypes,
906
889
  });
907
890
  };
908
- const headers = Object.assign({}, this.commonHeaders_);
909
- if (this._getSpanner().routeToLeaderEnabled &&
910
- (this._options.readWrite !== undefined ||
911
- this._options.partitionedDml !== undefined)) {
912
- (0, common_1.addLeaderAwareRoutingHeader)(headers);
913
- }
914
891
  const traceConfig = {
915
- transactionTag: this.requestOptions?.transactionTag,
916
- requestTag: requestOptions?.requestTag,
917
- ...query,
918
892
  ...this._traceConfig,
893
+ transactionTag: this.requestOptions?.transactionTag,
894
+ ...(0, instrument_1.getQueryTraceConfig)(queryInput),
919
895
  };
920
896
  const executeWithSpans = (fn) => {
921
897
  const startRunSpan = options?.startRunSpan !== false;
@@ -983,7 +959,7 @@ class Snapshot extends events_1.EventEmitter {
983
959
  return errorStream;
984
960
  }
985
961
  }
986
- const injectedHeaders = (0, request_id_header_1.injectRequestIDIntoHeaders)(headers, this.session, nthRequest, attempt);
962
+ const injectedHeaders = (0, request_id_header_1.injectRequestIDIntoHeaders)(this.commonHeaders_, this.session, nthRequest, attempt);
987
963
  const requestId = injectedHeaders[request_id_header_1.X_GOOG_SPANNER_REQUEST_ID_HEADER];
988
964
  if (runSpan && requestId) {
989
965
  runSpan.setAttribute(request_id_header_1.X_GOOG_SPANNER_REQUEST_ID_SPAN_ATTR, requestId);
@@ -1172,11 +1148,11 @@ class Snapshot extends events_1.EventEmitter {
1172
1148
  * @property {object} [gaxOptions] Request configuration options,
1173
1149
  * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
1174
1150
  * for more details.
1175
- * @property {number} [maxResumeRetries] The maximum number of times that the
1176
- * stream will retry to push data downstream, when the downstream indicates
1177
- * that it is not ready for any more data. Increase this value if you
1178
- * experience 'Stream is still not ready to receive data' errors as a
1179
- * result of a slow writer in your receiving stream.
1151
+ * @property {number} [maxResumeRetries] The maximum number of times that the
1152
+ * query will retry on retryable errors (such as UNAVAILABLE). Only
1153
+ * applicable to non-streaming queries executed via {@link Snapshot#run}.
1154
+ * For streaming queries ({@link Snapshot#runStream}), this option is
1155
+ * deprecated as backpressure is managed automatically.
1180
1156
  * @property {object} [directedReadOptions]
1181
1157
  * Indicates which replicas or regions should be used for non-transactional reads or queries.
1182
1158
  */
@@ -1240,17 +1216,19 @@ class Snapshot extends events_1.EventEmitter {
1240
1216
  * ```
1241
1217
  */
1242
1218
  runStream(query) {
1243
- if (typeof query === 'string') {
1244
- query = { sql: query };
1245
- }
1246
- query = Object.assign({}, query);
1247
- query.queryOptions = Object.assign(Object.assign({}, this.queryOptions), query.queryOptions);
1248
- const { gaxOptions, json, jsonOptions, maxResumeRetries, requestOptions, columnsMetadata, } = query;
1219
+ const originalQuery = typeof query === 'string' ? { sql: query } : query;
1220
+ const queryOptions = Object.assign({}, this.queryOptions, originalQuery.queryOptions);
1221
+ const { gaxOptions, json, jsonOptions, maxResumeRetries, requestOptions, columnsMetadata, types: _omittedTypes, directedReadOptions: rawDirectedReadOptions, ...cleanQuery } = originalQuery;
1222
+ void _omittedTypes;
1249
1223
  let reqOpts;
1250
- const directedReadOptions = this._getDirectedReadOptions(query.directedReadOptions);
1224
+ const directedReadOptions = this._getDirectedReadOptions(rawDirectedReadOptions);
1225
+ const statementSeqno = this._seqno++;
1226
+ let encodedParams;
1251
1227
  const sanitizeRequest = () => {
1252
- query = query;
1253
- const { params, paramTypes } = Snapshot.encodeParams(query);
1228
+ if (!encodedParams) {
1229
+ encodedParams = Snapshot.encodeParams(originalQuery);
1230
+ }
1231
+ const { params, paramTypes } = encodedParams;
1254
1232
  const transaction = {};
1255
1233
  if (this.id) {
1256
1234
  transaction.id = this.id;
@@ -1261,22 +1239,13 @@ class Snapshot extends events_1.EventEmitter {
1261
1239
  else {
1262
1240
  transaction.singleUse = this._options;
1263
1241
  }
1264
- if (!this.id &&
1265
- this._options.readWrite &&
1266
- this.session.parent.isMuxEnabledForRW_) {
1242
+ if (!this.id && this._options.readWrite) {
1267
1243
  this._setPreviousTransactionId(transaction);
1268
1244
  }
1269
- delete query.gaxOptions;
1270
- delete query.json;
1271
- delete query.jsonOptions;
1272
- delete query.maxResumeRetries;
1273
- delete query.requestOptions;
1274
- delete query.types;
1275
- delete query.directedReadOptions;
1276
- delete query.columnsMetadata;
1277
- reqOpts = Object.assign(query, {
1245
+ reqOpts = Object.assign({}, cleanQuery, {
1278
1246
  session: this.session.formattedName_,
1279
- seqno: this._seqno++,
1247
+ seqno: statementSeqno,
1248
+ queryOptions,
1280
1249
  requestOptions: this.configureTagOptions(typeof transaction.singleUse !== 'undefined', this.requestOptions?.transactionTag ?? undefined, requestOptions),
1281
1250
  directedReadOptions: directedReadOptions,
1282
1251
  transaction,
@@ -1284,17 +1253,10 @@ class Snapshot extends events_1.EventEmitter {
1284
1253
  paramTypes,
1285
1254
  });
1286
1255
  };
1287
- const headers = this.commonHeaders_;
1288
- if (this._getSpanner().routeToLeaderEnabled &&
1289
- (this._options.readWrite !== undefined ||
1290
- this._options.partitionedDml !== undefined)) {
1291
- (0, common_1.addLeaderAwareRoutingHeader)(headers);
1292
- }
1293
1256
  const traceConfig = {
1294
- transactionTag: this.requestOptions?.transactionTag,
1295
- requestTag: requestOptions?.requestTag,
1296
- ...query,
1297
1257
  ...this._traceConfig,
1258
+ transactionTag: this.requestOptions?.transactionTag,
1259
+ ...(0, instrument_1.getQueryTraceConfig)(originalQuery),
1298
1260
  };
1299
1261
  return (0, instrument_1.startTrace)('Snapshot.runStream', traceConfig, span => {
1300
1262
  let attempt = 0;
@@ -1333,7 +1295,7 @@ class Snapshot extends events_1.EventEmitter {
1333
1295
  method: 'executeStreamingSql',
1334
1296
  reqOpts: Object.assign({}, reqOpts, { resumeToken }),
1335
1297
  gaxOpts: gaxOptions,
1336
- headers: (0, request_id_header_1.injectRequestIDIntoHeaders)(headers, this.session, nthRequest, attempt),
1298
+ headers: (0, request_id_header_1.injectRequestIDIntoHeaders)(this.commonHeaders_, this.session, nthRequest, attempt),
1337
1299
  });
1338
1300
  };
1339
1301
  const resultStream = (0, partial_result_stream_1.partialResultStream)(this._wrapWithIdWaiter(makeRequest), {
@@ -1389,9 +1351,9 @@ class Snapshot extends events_1.EventEmitter {
1389
1351
  */
1390
1352
  configureTagOptions(singleUse, transactionTag, requestOptions = {}) {
1391
1353
  if (!singleUse && transactionTag) {
1392
- requestOptions.transactionTag = transactionTag;
1354
+ return Object.assign({}, requestOptions, { transactionTag });
1393
1355
  }
1394
- return requestOptions;
1356
+ return Object.assign({}, requestOptions);
1395
1357
  }
1396
1358
  /**
1397
1359
  * Transforms convenience options `keys` and `ranges` into a KeySet object.
@@ -1403,7 +1365,7 @@ class Snapshot extends events_1.EventEmitter {
1403
1365
  * @returns {object}
1404
1366
  */
1405
1367
  static encodeKeySet(request) {
1406
- const keySet = request.keySet || {};
1368
+ const keySet = Object.assign({}, request.keySet);
1407
1369
  if (request.keys) {
1408
1370
  keySet.keys = (0, helper_1.toArray)(request.keys).map(codec_1.codec.convertToListValue);
1409
1371
  }
@@ -1463,10 +1425,18 @@ class Snapshot extends events_1.EventEmitter {
1463
1425
  * @returns {object}
1464
1426
  */
1465
1427
  static encodeParams(request) {
1428
+ if (!request.params && !request.types && !request.paramTypes) {
1429
+ return {
1430
+ params: { fields: {} },
1431
+ paramTypes: {},
1432
+ };
1433
+ }
1466
1434
  const isUuidUntyped = codec_1.codec.isUuidUntypedEnv();
1467
- const typeMap = request.types || {};
1468
- const params = { fields: request.params?.fields || {} };
1469
- const paramTypes = request.paramTypes || {};
1435
+ const typeMap = Object.assign({}, request.types);
1436
+ const params = {
1437
+ fields: Object.assign({}, request.params?.fields),
1438
+ };
1439
+ const paramTypes = Object.assign({}, request.paramTypes);
1470
1440
  if (request.params && !request.params.fields) {
1471
1441
  const fields = {};
1472
1442
  Object.keys(request.params).forEach(param => {
@@ -1578,7 +1548,7 @@ class Snapshot extends events_1.EventEmitter {
1578
1548
  * @returns {Spanner}
1579
1549
  */
1580
1550
  _getSpanner() {
1581
- return this.session.parent.parent.parent;
1551
+ return this.session?.parent?.parent?.parent;
1582
1552
  }
1583
1553
  }
1584
1554
  exports.Snapshot = Snapshot;
@@ -1603,10 +1573,9 @@ class Dml extends Snapshot {
1603
1573
  query = { sql: query };
1604
1574
  }
1605
1575
  return (0, instrument_1.startTrace)('Dml.runUpdate', {
1606
- ...query,
1607
1576
  ...this._traceConfig,
1608
1577
  transactionTag: this.requestOptions?.transactionTag,
1609
- requestTag: query.requestOptions?.requestTag,
1578
+ ...(0, instrument_1.getQueryTraceConfig)(query),
1610
1579
  }, span => {
1611
1580
  this.run(query, (err, rows, stats) => {
1612
1581
  let rowCount = 0;
@@ -1726,6 +1695,9 @@ class Transaction extends Dml {
1726
1695
  this._options.isolationLevel = IsolationLevel.ISOLATION_LEVEL_UNSPECIFIED;
1727
1696
  this.requestOptions = requestOptions;
1728
1697
  this._retryCommit = false;
1698
+ if (this._getSpanner()?.routeToLeaderEnabled) {
1699
+ (0, common_1.addLeaderAwareRoutingHeader)(this.commonHeaders_);
1700
+ }
1729
1701
  }
1730
1702
  batchUpdate(queries, optionsOrCallback, cb) {
1731
1703
  const options = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
@@ -1758,9 +1730,7 @@ class Transaction extends Dml {
1758
1730
  else {
1759
1731
  transaction.begin = this._options;
1760
1732
  }
1761
- if (!this.id &&
1762
- this._options.readWrite &&
1763
- this.session.parent.isMuxEnabledForRW_) {
1733
+ if (!this.id && this._options.readWrite) {
1764
1734
  this._setPreviousTransactionId(transaction);
1765
1735
  }
1766
1736
  const requestOptionsWithTag = this.configureTagOptions(false, this.requestOptions?.transactionTag ?? undefined, options.requestOptions);
@@ -1773,9 +1743,6 @@ class Transaction extends Dml {
1773
1743
  };
1774
1744
  const database = this.session.parent;
1775
1745
  const headers = (0, request_id_header_1.injectRequestIDIntoHeaders)(this.commonHeaders_, this.session, (0, request_id_header_1.nextNthRequest)(database), 1);
1776
- if (this._getSpanner().routeToLeaderEnabled) {
1777
- (0, common_1.addLeaderAwareRoutingHeader)(headers);
1778
- }
1779
1746
  const traceConfig = {
1780
1747
  ...this._traceConfig,
1781
1748
  transactionTag: requestOptionsWithTag?.transactionTag,
@@ -1871,9 +1838,7 @@ class Transaction extends Dml {
1871
1838
  reqOpts.singleUseTransaction = this._options;
1872
1839
  }
1873
1840
  else {
1874
- if (this.session.parent.isMuxEnabledForRW_) {
1875
- this._setMutationKey(mutations);
1876
- }
1841
+ this._setMutationKey(mutations);
1877
1842
  this.begin()
1878
1843
  .then(() => {
1879
1844
  this.commit(options, (err, resp) => {
@@ -1901,10 +1866,6 @@ class Transaction extends Dml {
1901
1866
  reqOpts.maxCommitDelay = options.maxCommitDelay;
1902
1867
  }
1903
1868
  reqOpts.requestOptions = Object.assign(requestOptions || {}, this.requestOptions);
1904
- const headers = this.commonHeaders_;
1905
- if (this._getSpanner().routeToLeaderEnabled) {
1906
- (0, common_1.addLeaderAwareRoutingHeader)(headers);
1907
- }
1908
1869
  span.addEvent('Starting Commit');
1909
1870
  const database = this.session.parent;
1910
1871
  if (this._affinityKey) {
@@ -1920,7 +1881,7 @@ class Transaction extends Dml {
1920
1881
  method: 'commit',
1921
1882
  reqOpts,
1922
1883
  gaxOpts,
1923
- headers: (0, request_id_header_1.injectRequestIDIntoHeaders)(headers, this.session, (0, request_id_header_1.nextNthRequest)(database), 1),
1884
+ headers: (0, request_id_header_1.injectRequestIDIntoHeaders)(this.commonHeaders_, this.session, (0, request_id_header_1.nextNthRequest)(database), 1),
1924
1885
  }, (err, resp) => {
1925
1886
  if (resp &&
1926
1887
  'MultiplexedSessionRetry' in resp &&
@@ -2204,10 +2165,6 @@ class Transaction extends Dml {
2204
2165
  session,
2205
2166
  transactionId,
2206
2167
  };
2207
- const headers = this.commonHeaders_;
2208
- if (this._getSpanner().routeToLeaderEnabled) {
2209
- (0, common_1.addLeaderAwareRoutingHeader)(headers);
2210
- }
2211
2168
  if (this._affinityKey) {
2212
2169
  if (!gaxOpts || Object.keys(gaxOpts).length === 0) {
2213
2170
  gaxOpts = this._unbindGaxOpts;
@@ -2221,7 +2178,7 @@ class Transaction extends Dml {
2221
2178
  method: 'rollback',
2222
2179
  reqOpts,
2223
2180
  gaxOpts,
2224
- headers: headers,
2181
+ headers: { ...this.commonHeaders_ },
2225
2182
  }, (err) => {
2226
2183
  if (err) {
2227
2184
  (0, instrument_1.setSpanError)(span, err);
@@ -2692,6 +2649,9 @@ class PartitionedDml extends Dml {
2692
2649
  constructor(session, options = {}) {
2693
2650
  super(session);
2694
2651
  this._options = { partitionedDml: options };
2652
+ if (this._getSpanner()?.routeToLeaderEnabled) {
2653
+ (0, common_1.addLeaderAwareRoutingHeader)(this.commonHeaders_);
2654
+ }
2695
2655
  }
2696
2656
  /**
2697
2657
  * Use option excludeTxnFromChangeStreams to exclude partitionedDml
@@ -2706,8 +2666,8 @@ class PartitionedDml extends Dml {
2706
2666
  }
2707
2667
  runUpdate(query, callback) {
2708
2668
  return (0, instrument_1.startTrace)('PartitionedDml.runUpdate', {
2709
- ...query,
2710
2669
  ...this._traceConfig,
2670
+ ...(0, instrument_1.getQueryTraceConfig)(query),
2711
2671
  }, span => {
2712
2672
  super.runUpdate(query, (err, count) => {
2713
2673
  if (err) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@google-cloud/spanner",
3
3
  "description": "Cloud Spanner Client Library for Node.js",
4
- "version": "9.0.0",
4
+ "version": "9.1.0",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Google Inc.",
7
7
  "engines": {
@@ -34,10 +34,10 @@
34
34
  "docs": "jsdoc -c .jsdoc.js",
35
35
  "predocs": "pnpm run compile",
36
36
  "lint": "gts check",
37
- "system-test": "mocha build/system-test --timeout 1600000",
38
- "observability-test": "mocha build/observability-test --timeout 1600000",
39
- "cleanup": "mocha scripts/cleanup.js --timeout 30000",
40
- "test": "mocha build/test build/test/common build/observability-test",
37
+ "system-test": "node ../../bin/run-test.cjs build/system-test --timeout 1600000",
38
+ "observability-test": "node ../../bin/run-test.cjs --proxyquire-shim build/observability-test --timeout 1600000",
39
+ "cleanup": "node ../../bin/run-test.cjs scripts/cleanup.js --timeout 30000",
40
+ "test": "node ../../bin/run-test.cjs --proxyquire-shim build/test build/test/common build/observability-test",
41
41
  "ycsb": "node ./benchmark/ycsb.js run -P ./benchmark/workloada -p table=usertable -p cloudspanner.instance=ycsb-instance -p operationcount=100 -p cloudspanner.database=ycsb",
42
42
  "fix": "gts fix",
43
43
  "clean": "gts clean",
@@ -48,7 +48,7 @@
48
48
  "preobservability-test": "pnpm run compile",
49
49
  "benchwrapper": "node bin/benchwrapper.js",
50
50
  "precompile": "gts clean",
51
- "coverage": "c8 mocha build/test build/test/common && c8 report --check-coverage"
51
+ "coverage": "node ../../bin/run-test.cjs build/test build/test/common && c8 report --check-coverage"
52
52
  },
53
53
  "dependencies": {
54
54
  "@babel/core": "7.27.7",
@@ -69,7 +69,6 @@
69
69
  "@opentelemetry/sdk-metrics": "^2.11.0",
70
70
  "@opentelemetry/semantic-conventions": "^1.30.0",
71
71
  "@types/big.js": "^6.2.2",
72
- "@types/stack-trace": "^0.0.33",
73
72
  "big.js": "^7.0.0",
74
73
  "duplexify": "^4.1.3",
75
74
  "extend": "^3.0.2",
@@ -77,10 +76,8 @@
77
76
  "google-gax": "^6.0.0",
78
77
  "grpc-gcp": "^1.0.1",
79
78
  "lodash.snakecase": "^4.1.1",
80
- "p-queue": "^6.0.2",
81
79
  "protobufjs": "^7.4.0",
82
80
  "retry-request": "^9.0.0",
83
- "stack-trace": "0.0.10",
84
81
  "stream-events": "^1.0.5",
85
82
  "teeny-request": "^11.0.0",
86
83
  "through2": "^4.0.2"
@@ -110,6 +107,7 @@
110
107
  "dedent": "^1.5.3",
111
108
  "execa": "^5.0.0",
112
109
  "gapic-tools": "^2.0.0",
110
+ "google-test-utils": "^0.2.0",
113
111
  "grpc-health-check": "^2.1.0",
114
112
  "gts": "^6.0.2",
115
113
  "jsdoc": "^4.0.4",
@@ -122,6 +120,7 @@
122
120
  "ncp": "^2.0.0",
123
121
  "nise": "^6.1.1",
124
122
  "p-limit": "^3.0.1",
123
+ "p-queue": "^6.0.2",
125
124
  "path-to-regexp": "^8.2.0",
126
125
  "proxyquire": "^2.1.3",
127
126
  "sinon": "21.0.3",
@@ -133,7 +132,7 @@
133
132
  },
134
133
  "overrides": {
135
134
  "@sinonjs/fake-timers": "15.2.1",
136
- "brace-expansion": "5.0.7",
135
+ "brace-expansion": "5.0.12",
137
136
  "@eslint-community/eslint-utils": "<4.10.0"
138
137
  },
139
138
  "homepage": "https://github.com/googleapis/google-cloud-node/tree/main/handwritten/spanner"