@google-cloud/spanner 8.1.0 → 8.2.1

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.
@@ -46,6 +46,7 @@ Object.defineProperty(exports, "InstanceConfig", { enumerable: true, get: functi
46
46
  const google_gax_1 = require("google-gax");
47
47
  const protos_1 = require("../protos/protos");
48
48
  var IsolationLevel = protos_1.google.spanner.v1.TransactionOptions.IsolationLevel;
49
+ var ReadLockMode = protos_1.google.spanner.v1.TransactionOptions.ReadWrite.ReadLockMode;
49
50
  const common_1 = require("./common");
50
51
  const session_1 = require("./session");
51
52
  Object.defineProperty(exports, "Session", { enumerable: true, get: function () { return session_1.Session; } });
@@ -159,7 +160,7 @@ class Spanner extends service_1.GrpcService {
159
160
  defaultTransactionOptions;
160
161
  _observabilityOptions;
161
162
  _universeDomain;
162
- _isEmulatorEnabled;
163
+ _isInSecureCredentials;
163
164
  static _isAFEServerTimingEnabled;
164
165
  _nthClientId;
165
166
  /**
@@ -255,6 +256,7 @@ class Spanner extends service_1.GrpcService {
255
256
  ? options.defaultTransactionOptions
256
257
  : {
257
258
  isolationLevel: IsolationLevel.ISOLATION_LEVEL_UNSPECIFIED,
259
+ readLockMode: ReadLockMode.READ_LOCK_MODE_UNSPECIFIED,
258
260
  };
259
261
  delete options.defaultTransactionOptions;
260
262
  if (options?.universe_domain &&
@@ -262,12 +264,10 @@ class Spanner extends service_1.GrpcService {
262
264
  options?.universe_domain !== options?.universeDomain) {
263
265
  throw new Error('Please set either universe_domain or universeDomain, but not both.');
264
266
  }
265
- let isEmulatorEnabled = false;
266
267
  const emulatorHost = Spanner.getSpannerEmulatorHost();
267
268
  if (emulatorHost &&
268
269
  emulatorHost.endpoint &&
269
270
  emulatorHost.endpoint.length > 0) {
270
- isEmulatorEnabled = true;
271
271
  options.servicePath = emulatorHost.endpoint;
272
272
  options.port = emulatorHost.port;
273
273
  options.sslCreds = google_gax_1.grpc.credentials.createInsecure();
@@ -290,7 +290,7 @@ class Spanner extends service_1.GrpcService {
290
290
  if (options.routeToLeaderEnabled === false) {
291
291
  this.routeToLeaderEnabled = false;
292
292
  }
293
- this._isEmulatorEnabled = isEmulatorEnabled;
293
+ this._isInSecureCredentials = options.sslCreds?._isSecure() === false;
294
294
  this.options = options;
295
295
  this.auth = new google_auth_library_1.GoogleAuth(this.options);
296
296
  this.clients_ = new Map();
@@ -305,7 +305,7 @@ class Spanner extends service_1.GrpcService {
305
305
  (0, instrument_1.ensureInitialContextManagerSet)();
306
306
  this._nthClientId = (0, request_id_header_1.nextSpannerClientId)();
307
307
  this._universeDomain = universeEndpoint;
308
- this.configureMetrics_();
308
+ this.configureMetrics_(options.disableBuiltInMetrics);
309
309
  }
310
310
  get universeDomain() {
311
311
  return this._universeDomain;
@@ -760,9 +760,10 @@ class Spanner extends service_1.GrpcService {
760
760
  /**
761
761
  * Setup the OpenTelemetry metrics capturing for service metrics to Google Cloud Monitoring.
762
762
  */
763
- configureMetrics_() {
763
+ configureMetrics_(disableBuiltInMetrics) {
764
764
  const metricsEnabled = process.env.SPANNER_DISABLE_BUILTIN_METRICS !== 'true' &&
765
- !this._isEmulatorEnabled;
765
+ !disableBuiltInMetrics &&
766
+ !this._isInSecureCredentials;
766
767
  metrics_tracer_factory_1.MetricsTracerFactory.enabled = metricsEnabled;
767
768
  if (metricsEnabled) {
768
769
  const factory = metrics_tracer_factory_1.MetricsTracerFactory.getInstance(this.projectId);
@@ -66,7 +66,9 @@ const MetricInterceptor = (options, nextCall) => {
66
66
  metricsTracer?.recordAfeLatency(status.code);
67
67
  }
68
68
  else {
69
- metricsTracer?.recordAfeConnectivityErrorCount(status.code);
69
+ // Disable afe_connectivity_error_count metric as AFE header is disabled in backend
70
+ // currently.
71
+ // metricsTracer?.recordAfeConnectivityErrorCount(status.code);
70
72
  }
71
73
  },
72
74
  };
@@ -106,7 +106,7 @@ export declare class MultiplexedSession extends EventEmitter implements Multiple
106
106
  */
107
107
  getSession(callback: GetSessionCallback): void;
108
108
  /**
109
- * Acquires a session asynchronously, and prepares the transaction for the session.
109
+ * Acquires a session asynchronously.
110
110
  *
111
111
  * Once a session is successfully acquired, it returns the session object (which may be `null` if unsuccessful).
112
112
  *
@@ -131,10 +131,10 @@ class MultiplexedSession extends events_1.EventEmitter {
131
131
  *
132
132
  */
133
133
  getSession(callback) {
134
- this._acquire().then(session => callback(null, session, session?.txn), callback);
134
+ this._acquire().then(session => callback(null, session, session.transaction(session.parent.queryOptions_)), callback);
135
135
  }
136
136
  /**
137
- * Acquires a session asynchronously, and prepares the transaction for the session.
137
+ * Acquires a session asynchronously.
138
138
  *
139
139
  * Once a session is successfully acquired, it returns the session object (which may be `null` if unsuccessful).
140
140
  *
@@ -144,8 +144,6 @@ class MultiplexedSession extends events_1.EventEmitter {
144
144
  */
145
145
  async _acquire() {
146
146
  const session = await this._getSession();
147
- // Prepare a transaction for a session
148
- session.txn = session.transaction(session.parent.queryOptions_);
149
147
  return session;
150
148
  }
151
149
  /**
@@ -23,6 +23,7 @@ import IRequestOptions = databaseAdmin.spanner.v1.IRequestOptions;
23
23
  import { ObservabilityOptions } from './instrument';
24
24
  import { google } from '../protos/protos';
25
25
  import IsolationLevel = google.spanner.v1.TransactionOptions.IsolationLevel;
26
+ import ReadLockMode = google.spanner.v1.TransactionOptions.ReadWrite.ReadLockMode;
26
27
  export type Key = string | string[];
27
28
  export type CreateTableResponse = [
28
29
  Table,
@@ -36,6 +37,7 @@ interface MutateRowsOptions extends CommitOptions {
36
37
  requestOptions?: Omit<IRequestOptions, 'requestTag'>;
37
38
  excludeTxnFromChangeStreams?: boolean;
38
39
  isolationLevel?: IsolationLevel;
40
+ readLockMode?: ReadLockMode;
39
41
  }
40
42
  export type DeleteRowsCallback = CommitCallback;
41
43
  export type DeleteRowsResponse = CommitResponse;
@@ -21,6 +21,7 @@ const through = require("through2");
21
21
  const instrument_1 = require("./instrument");
22
22
  const protos_1 = require("../protos/protos");
23
23
  var IsolationLevel = protos_1.google.spanner.v1.TransactionOptions.IsolationLevel;
24
+ var ReadLockMode = protos_1.google.spanner.v1.TransactionOptions.ReadWrite.ReadLockMode;
24
25
  const GOOGLE_STANDARD_SQL = 'GOOGLE_STANDARD_SQL';
25
26
  const POSTGRESQL = 'POSTGRESQL';
26
27
  /**
@@ -253,10 +254,14 @@ class Table {
253
254
  const isolationLevel = 'isolationLevel' in options
254
255
  ? options.isolationLevel
255
256
  : IsolationLevel.ISOLATION_LEVEL_UNSPECIFIED;
257
+ const readLockMode = 'readLockMode' in options
258
+ ? options.readLockMode
259
+ : ReadLockMode.READ_LOCK_MODE_UNSPECIFIED;
256
260
  this.database.runTransaction({
257
261
  requestOptions: requestOptions,
258
262
  excludeTxnFromChangeStreams: excludeTxnFromChangeStreams,
259
263
  isolationLevel: isolationLevel,
264
+ readLockMode: readLockMode,
260
265
  }, (err, transaction) => {
261
266
  if (err) {
262
267
  (0, instrument_1.setSpanError)(span, err);
@@ -20,6 +20,7 @@ import { NormalCallback } from './common';
20
20
  import { google } from '../protos/protos';
21
21
  import IRequestOptions = google.spanner.v1.IRequestOptions;
22
22
  import IsolationLevel = google.spanner.v1.TransactionOptions.IsolationLevel;
23
+ import ReadLockMode = google.spanner.v1.TransactionOptions.ReadWrite.ReadLockMode;
23
24
  /**
24
25
  * @typedef {object} RunTransactionOptions
25
26
  * @property {number} [timeout] The maximum amount of time (in ms) that a
@@ -28,9 +29,13 @@ import IsolationLevel = google.spanner.v1.TransactionOptions.IsolationLevel;
28
29
  export interface RunTransactionOptions {
29
30
  timeout?: number;
30
31
  requestOptions?: Pick<IRequestOptions, 'transactionTag'>;
32
+ /**
33
+ * @deprecated Use readLockMode instead.
34
+ */
31
35
  optimisticLock?: boolean;
32
36
  excludeTxnFromChangeStreams?: boolean;
33
37
  isolationLevel?: IsolationLevel;
38
+ readLockMode?: ReadLockMode;
34
39
  }
35
40
  /**
36
41
  * A function to execute in the context of a transaction.
@@ -24,6 +24,7 @@ const through = require("through2");
24
24
  const session_pool_1 = require("./session-pool");
25
25
  const protos_1 = require("../protos/protos");
26
26
  var IsolationLevel = protos_1.google.spanner.v1.TransactionOptions.IsolationLevel;
27
+ var ReadLockMode = protos_1.google.spanner.v1.TransactionOptions.ReadWrite.ReadLockMode;
27
28
  // eslint-disable-next-line @typescript-eslint/no-var-requires
28
29
  const jsonProtos = require('../protos/protos.json');
29
30
  const RETRY_INFO = 'google.rpc.retryinfo-bin';
@@ -79,6 +80,7 @@ class Runner {
79
80
  const defaults = {
80
81
  timeout: 3600000,
81
82
  isolationLevel: IsolationLevel.ISOLATION_LEVEL_UNSPECIFIED,
83
+ readLockMode: ReadLockMode.READ_LOCK_MODE_UNSPECIFIED,
82
84
  };
83
85
  this.options = Object.assign(defaults, options);
84
86
  }
@@ -1546,6 +1546,8 @@ export declare class Transaction extends Dml {
1546
1546
  * (when any needed locks are acquired). The validation process succeeds only
1547
1547
  * if there are no conflicting committed transactions (that committed
1548
1548
  * mutations to the read data at a commit timestamp after the read timestamp).
1549
+ *
1550
+ * @deprecated Set readLockMode through setReadWriteTransactionOptions instead.
1549
1551
  */
1550
1552
  useOptimisticLock(): void;
1551
1553
  /**
@@ -177,7 +177,8 @@ class Snapshot extends events_1.EventEmitter {
177
177
  _updatePrecommitToken(resp) {
178
178
  if (this._latestPreCommitToken === null ||
179
179
  this._latestPreCommitToken === undefined ||
180
- this._latestPreCommitToken.seqNum < resp.precommitToken.seqNum) {
180
+ (resp.precommitToken &&
181
+ this._latestPreCommitToken.seqNum < resp.precommitToken.seqNum)) {
181
182
  this._latestPreCommitToken = resp.precommitToken;
182
183
  }
183
184
  }
@@ -1891,6 +1892,8 @@ class Transaction extends Dml {
1891
1892
  * (when any needed locks are acquired). The validation process succeeds only
1892
1893
  * if there are no conflicting committed transactions (that committed
1893
1894
  * mutations to the read data at a commit timestamp after the read timestamp).
1895
+ *
1896
+ * @deprecated Set readLockMode through setReadWriteTransactionOptions instead.
1894
1897
  */
1895
1898
  useOptimisticLock() {
1896
1899
  this._options.readWrite.readLockMode = ReadLockMode.OPTIMISTIC;
@@ -1907,12 +1910,6 @@ class Transaction extends Dml {
1907
1910
  this._options.excludeTxnFromChangeStreams = true;
1908
1911
  }
1909
1912
  setReadWriteTransactionOptions(options) {
1910
- /**
1911
- * Set optimistic concurrency control for the transaction.
1912
- */
1913
- if (options?.optimisticLock) {
1914
- this._options.readWrite.readLockMode = ReadLockMode.OPTIMISTIC;
1915
- }
1916
1913
  /**
1917
1914
  * Set option excludeTxnFromChangeStreams=true to exclude read/write transactions
1918
1915
  * from being tracked in change streams.
@@ -1921,11 +1918,17 @@ class Transaction extends Dml {
1921
1918
  this._options.excludeTxnFromChangeStreams = true;
1922
1919
  }
1923
1920
  /**
1924
- * Set isolation level .
1921
+ * Set isolation level.
1925
1922
  */
1926
1923
  this._options.isolationLevel = options?.isolationLevel
1927
1924
  ? options?.isolationLevel
1928
1925
  : this._getSpanner().defaultTransactionOptions.isolationLevel;
1926
+ /**
1927
+ * Set read lock mode.
1928
+ */
1929
+ this._options.readWrite.readLockMode = options?.readLockMode
1930
+ ? options?.readLockMode
1931
+ : this._getSpanner().defaultTransactionOptions.readLockMode;
1929
1932
  }
1930
1933
  }
1931
1934
  exports.Transaction = Transaction;