@google-cloud/spanner 8.0.0 → 8.2.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.
- package/README.md +2 -0
- package/build/protos/google/spanner/admin/database/v1/spanner_database_admin.proto +35 -0
- package/build/protos/google/spanner/v1/change_stream.proto +451 -0
- package/build/protos/google/spanner/v1/commit_response.proto +9 -4
- package/build/protos/google/spanner/v1/transaction.proto +40 -356
- package/build/protos/protos.d.ts +2087 -4
- package/build/protos/protos.js +6191 -349
- package/build/protos/protos.json +556 -25
- package/build/src/batch-transaction.js +2 -2
- package/build/src/codec.js +20 -21
- package/build/src/common-grpc/service.js +10 -10
- package/build/src/common.d.ts +1 -0
- package/build/src/common.js +9 -1
- package/build/src/database.d.ts +3 -2
- package/build/src/database.js +16 -14
- package/build/src/helper.d.ts +90 -0
- package/build/src/helper.js +154 -0
- package/build/src/index.d.ts +36 -1
- package/build/src/index.js +179 -8
- package/build/src/instrument.js +3 -2
- package/build/src/metrics/constants.d.ts +36 -0
- package/build/src/metrics/constants.js +106 -0
- package/build/src/metrics/external-types.d.ts +20 -0
- package/build/src/metrics/external-types.js +32 -0
- package/build/src/metrics/interceptor.d.ts +13 -0
- package/build/src/metrics/interceptor.js +87 -0
- package/build/src/metrics/metrics-tracer-factory.d.ts +165 -0
- package/build/src/metrics/metrics-tracer-factory.js +389 -0
- package/build/src/metrics/metrics-tracer.d.ts +204 -0
- package/build/src/metrics/metrics-tracer.js +371 -0
- package/build/src/metrics/spanner-metrics-exporter.d.ts +35 -0
- package/build/src/metrics/spanner-metrics-exporter.js +119 -0
- package/build/src/metrics/transform.d.ts +144 -0
- package/build/src/metrics/transform.js +272 -0
- package/build/src/multiplexed-session.d.ts +1 -1
- package/build/src/multiplexed-session.js +2 -4
- package/build/src/partial-result-stream.js +9 -5
- package/build/src/session-factory.d.ts +34 -0
- package/build/src/session-factory.js +30 -0
- package/build/src/session-pool.js +1 -2
- package/build/src/table.d.ts +2 -0
- package/build/src/table.js +5 -0
- package/build/src/transaction-runner.d.ts +6 -0
- package/build/src/transaction-runner.js +8 -0
- package/build/src/transaction.d.ts +44 -1
- package/build/src/transaction.js +202 -49
- package/build/src/v1/database_admin_client.d.ts +34 -0
- package/build/src/v1/database_admin_client.js +167 -1
- package/build/src/v1/database_admin_client_config.json +4 -0
- package/build/src/v1/instance_admin_client.d.ts +120 -0
- package/build/src/v1/instance_admin_client.js +312 -13
- package/build/src/v1/spanner_client.js +108 -0
- package/build/src/v1/spanner_proto_list.json +1 -0
- package/package.json +15 -8
package/build/src/transaction.js
CHANGED
|
@@ -21,17 +21,15 @@ const promisify_1 = require("@google-cloud/promisify");
|
|
|
21
21
|
const helper_1 = require("./helper");
|
|
22
22
|
const events_1 = require("events");
|
|
23
23
|
const google_gax_1 = require("google-gax");
|
|
24
|
-
const is = require("is");
|
|
25
24
|
const stream_1 = require("stream");
|
|
26
25
|
const codec_1 = require("./codec");
|
|
27
26
|
const partial_result_stream_1 = require("./partial-result-stream");
|
|
28
|
-
const instrument_1 = require("./instrument");
|
|
29
27
|
const protos_1 = require("../protos/protos");
|
|
30
28
|
const common_1 = require("./common");
|
|
31
29
|
const protos_2 = require("../protos/protos");
|
|
32
30
|
var IsolationLevel = protos_2.google.spanner.v1.TransactionOptions.IsolationLevel;
|
|
33
31
|
var ReadLockMode = protos_2.google.spanner.v1.TransactionOptions.ReadWrite.ReadLockMode;
|
|
34
|
-
const
|
|
32
|
+
const instrument_1 = require("./instrument");
|
|
35
33
|
const request_id_header_1 = require("./request_id_header");
|
|
36
34
|
const RETRY_INFO_TYPE = 'type.googleapis.com/google.rpc.retryinfo';
|
|
37
35
|
const RETRY_INFO_BIN = 'google.rpc.retryinfo-bin';
|
|
@@ -95,7 +93,9 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
95
93
|
_waitingRequests;
|
|
96
94
|
_inlineBeginStarted;
|
|
97
95
|
_useInRunner = false;
|
|
96
|
+
_latestPreCommitToken;
|
|
98
97
|
id;
|
|
98
|
+
multiplexedSessionPreviousTransactionId;
|
|
99
99
|
ended;
|
|
100
100
|
metadata;
|
|
101
101
|
readTimestamp;
|
|
@@ -109,6 +109,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
109
109
|
_observabilityOptions;
|
|
110
110
|
_traceConfig;
|
|
111
111
|
_dbName;
|
|
112
|
+
_mutationKey;
|
|
112
113
|
/**
|
|
113
114
|
* The transaction ID.
|
|
114
115
|
*
|
|
@@ -170,16 +171,130 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
170
171
|
opts: this._observabilityOptions,
|
|
171
172
|
dbName: this._dbName,
|
|
172
173
|
};
|
|
174
|
+
this._latestPreCommitToken = null;
|
|
175
|
+
this._mutationKey = null;
|
|
176
|
+
}
|
|
177
|
+
_updatePrecommitToken(resp) {
|
|
178
|
+
if (this._latestPreCommitToken === null ||
|
|
179
|
+
this._latestPreCommitToken === undefined ||
|
|
180
|
+
(resp.precommitToken &&
|
|
181
|
+
this._latestPreCommitToken.seqNum < resp.precommitToken.seqNum)) {
|
|
182
|
+
this._latestPreCommitToken = resp.precommitToken;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Selects a single representative mutation from a list to be used as the
|
|
187
|
+
* transaction's `mutationKey`.
|
|
188
|
+
*
|
|
189
|
+
* This key is required by Spanner and is sent in the `BeginTransactionRequest`
|
|
190
|
+
* for read-write transactions that only contain mutations. The selection follows
|
|
191
|
+
* a two-tiered heuristic to choose the most significant mutation.
|
|
192
|
+
*
|
|
193
|
+
* The selection heuristic is as follows:
|
|
194
|
+
*
|
|
195
|
+
* 1. Priority of Operation Type: High-priority mutations (`delete`, `update`,
|
|
196
|
+
* `replace`, `insertOrUpdate`) are always chosen over low-priority
|
|
197
|
+
* (`insert`) mutations.
|
|
198
|
+
*
|
|
199
|
+
* 2. Selection Strategy:
|
|
200
|
+
* - If any high-priority mutations exist, one is chosen randomly from
|
|
201
|
+
* that group, ignoring the number of rows.
|
|
202
|
+
* - If only `insert` mutations exist, the one(s) with the largest number
|
|
203
|
+
* of rows are identified, and one is chosen randomly from that subset.
|
|
204
|
+
*
|
|
205
|
+
* @protected
|
|
206
|
+
* @param mutations The list of mutations from which to select the key.
|
|
207
|
+
*/
|
|
208
|
+
_setMutationKey(mutations) {
|
|
209
|
+
// return if the list is empty
|
|
210
|
+
if (mutations.length === 0) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
// maintain a set of high priority keys
|
|
214
|
+
const HIGH_PRIORITY_KEYS = new Set([
|
|
215
|
+
'delete',
|
|
216
|
+
'update',
|
|
217
|
+
'replace',
|
|
218
|
+
'insertOrUpdate',
|
|
219
|
+
]);
|
|
220
|
+
// maintain a variable for low priority key
|
|
221
|
+
const LOW_PRIORITY_KEY = 'insert';
|
|
222
|
+
// Partition mutations into high and low priority groups.
|
|
223
|
+
const [highPriority, lowPriority] = mutations.reduce((acc, mutation) => {
|
|
224
|
+
const key = Object.keys(mutation)[0];
|
|
225
|
+
if (HIGH_PRIORITY_KEYS.has(key)) {
|
|
226
|
+
acc[0].push(mutation);
|
|
227
|
+
}
|
|
228
|
+
else if (key === LOW_PRIORITY_KEY) {
|
|
229
|
+
acc[1].push(mutation);
|
|
230
|
+
}
|
|
231
|
+
// return accumulated mutations list
|
|
232
|
+
return acc;
|
|
233
|
+
}, [[], []]);
|
|
234
|
+
// Apply the selection logic based on the rules.
|
|
235
|
+
if (highPriority.length > 0) {
|
|
236
|
+
// RULE 1: If high-priority keys exist, pick one randomly.
|
|
237
|
+
const randomIndex = Math.floor(Math.random() * highPriority.length);
|
|
238
|
+
this._mutationKey = highPriority[randomIndex];
|
|
239
|
+
}
|
|
240
|
+
else if (lowPriority.length > 0) {
|
|
241
|
+
// RULE 2: If only 'insert' key(s) exist, find the one with
|
|
242
|
+
// highest number of values
|
|
243
|
+
const { bestCandidates } = lowPriority.reduce((acc, mutation) => {
|
|
244
|
+
const size = mutation.insert?.values?.length || 0;
|
|
245
|
+
if (size > acc.maxSize) {
|
|
246
|
+
// New largest size found, start a new list
|
|
247
|
+
return { maxSize: size, bestCandidates: [mutation] };
|
|
248
|
+
}
|
|
249
|
+
if (size === acc.maxSize) {
|
|
250
|
+
// Same size as current max, add to list
|
|
251
|
+
acc.bestCandidates.push(mutation);
|
|
252
|
+
}
|
|
253
|
+
// return accumulated mutations list
|
|
254
|
+
return acc;
|
|
255
|
+
}, {
|
|
256
|
+
maxSize: -1,
|
|
257
|
+
bestCandidates: [],
|
|
258
|
+
});
|
|
259
|
+
// Pick randomly from the largest 'insert' mutation(s).
|
|
260
|
+
const randomIndex = Math.floor(Math.random() * bestCandidates.length);
|
|
261
|
+
this._mutationKey = bestCandidates[randomIndex];
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
// No mutations to select from.
|
|
265
|
+
this._mutationKey = null;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Modifies transaction selector to include the multiplexed session previous
|
|
270
|
+
* transaction id.
|
|
271
|
+
* This is essential for operations that use an `inline begin`.
|
|
272
|
+
* @protected
|
|
273
|
+
* @param transaction The transaction selector object that will be mutated
|
|
274
|
+
* to include the multiplexed session previous transaction id.
|
|
275
|
+
*/
|
|
276
|
+
_setPreviousTransactionId(transaction) {
|
|
277
|
+
transaction.begin.readWrite = Object.assign({}, transaction.begin.readWrite || {}, {
|
|
278
|
+
multiplexedSessionPreviousTransactionId: this.multiplexedSessionPreviousTransactionId,
|
|
279
|
+
});
|
|
173
280
|
}
|
|
174
281
|
begin(gaxOptionsOrCallback, cb) {
|
|
175
282
|
const gaxOpts = typeof gaxOptionsOrCallback === 'object' ? gaxOptionsOrCallback : {};
|
|
176
283
|
const callback = typeof gaxOptionsOrCallback === 'function' ? gaxOptionsOrCallback : cb;
|
|
177
284
|
const session = this.session.formattedName_;
|
|
178
285
|
const options = this._options;
|
|
286
|
+
if (this.multiplexedSessionPreviousTransactionId &&
|
|
287
|
+
this.session.parent.isMuxEnabledForRW_) {
|
|
288
|
+
options.readWrite.multiplexedSessionPreviousTransactionId =
|
|
289
|
+
this.multiplexedSessionPreviousTransactionId;
|
|
290
|
+
}
|
|
179
291
|
const reqOpts = {
|
|
180
292
|
session,
|
|
181
293
|
options,
|
|
182
294
|
};
|
|
295
|
+
if (this._mutationKey) {
|
|
296
|
+
reqOpts.mutationKey = this._mutationKey;
|
|
297
|
+
}
|
|
183
298
|
// Only hand crafted read-write transactions will be able to set a
|
|
184
299
|
// transaction tag for the BeginTransaction RPC. Also, this.requestOptions
|
|
185
300
|
// is only set in the constructor of Transaction, which is the constructor
|
|
@@ -193,7 +308,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
193
308
|
this._options.partitionedDml !== undefined)) {
|
|
194
309
|
(0, common_1.addLeaderAwareRoutingHeader)(headers);
|
|
195
310
|
}
|
|
196
|
-
return (0,
|
|
311
|
+
return (0, instrument_1.startTrace)('Snapshot.begin', {
|
|
197
312
|
transactionTag: this.requestOptions?.transactionTag,
|
|
198
313
|
...this._traceConfig,
|
|
199
314
|
}, span => {
|
|
@@ -206,10 +321,11 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
206
321
|
headers: (0, request_id_header_1.injectRequestIDIntoHeaders)(headers, this.session),
|
|
207
322
|
}, (err, resp) => {
|
|
208
323
|
if (err) {
|
|
209
|
-
(0,
|
|
324
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
210
325
|
}
|
|
211
326
|
else {
|
|
212
|
-
this.
|
|
327
|
+
this._updatePrecommitToken(resp);
|
|
328
|
+
this._update(resp, span);
|
|
213
329
|
}
|
|
214
330
|
span.end();
|
|
215
331
|
callback(err, resp);
|
|
@@ -399,6 +515,11 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
399
515
|
else {
|
|
400
516
|
transaction.singleUse = this._options;
|
|
401
517
|
}
|
|
518
|
+
if (!this.id &&
|
|
519
|
+
this._options.readWrite &&
|
|
520
|
+
this.session.parent.isMuxEnabledForRW_) {
|
|
521
|
+
this._setPreviousTransactionId(transaction);
|
|
522
|
+
}
|
|
402
523
|
const directedReadOptions = this._getDirectedReadOptions(request.directedReadOptions);
|
|
403
524
|
request = Object.assign({}, request);
|
|
404
525
|
delete request.gaxOptions;
|
|
@@ -430,7 +551,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
430
551
|
transactionTag: this.requestOptions?.transactionTag,
|
|
431
552
|
requestTag: requestOptions?.requestTag,
|
|
432
553
|
};
|
|
433
|
-
return (0,
|
|
554
|
+
return (0, instrument_1.startTrace)('Snapshot.createReadStream', traceConfig, span => {
|
|
434
555
|
let attempt = 0;
|
|
435
556
|
const database = this.session.parent;
|
|
436
557
|
const nthRequest = (0, request_id_header_1.nextNthRequest)(database);
|
|
@@ -470,12 +591,13 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
470
591
|
gaxOptions,
|
|
471
592
|
})
|
|
472
593
|
?.on('response', response => {
|
|
594
|
+
this._updatePrecommitToken(response);
|
|
473
595
|
if (response.metadata && response.metadata.transaction && !this.id) {
|
|
474
|
-
this._update(response.metadata.transaction);
|
|
596
|
+
this._update(response.metadata.transaction, span);
|
|
475
597
|
}
|
|
476
598
|
})
|
|
477
599
|
.on('error', err => {
|
|
478
|
-
(0,
|
|
600
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
479
601
|
const wasAborted = isErrorAborted(err);
|
|
480
602
|
if (!this.id && this._useInRunner && !wasAborted) {
|
|
481
603
|
// TODO: resolve https://github.com/googleapis/nodejs-spanner/issues/2170
|
|
@@ -492,14 +614,14 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
492
614
|
})
|
|
493
615
|
.on('end', err => {
|
|
494
616
|
if (err) {
|
|
495
|
-
(0,
|
|
617
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
496
618
|
}
|
|
497
619
|
span.end();
|
|
498
620
|
});
|
|
499
621
|
if (resultStream instanceof stream_1.Stream) {
|
|
500
622
|
(0, stream_1.finished)(resultStream, err => {
|
|
501
623
|
if (err) {
|
|
502
|
-
(0,
|
|
624
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
503
625
|
}
|
|
504
626
|
span.end();
|
|
505
627
|
});
|
|
@@ -571,14 +693,14 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
571
693
|
request = requestOrCallback;
|
|
572
694
|
callback = cb;
|
|
573
695
|
}
|
|
574
|
-
return (0,
|
|
696
|
+
return (0, instrument_1.startTrace)('Snapshot.read', {
|
|
575
697
|
tableName: table,
|
|
576
698
|
...this._traceConfig,
|
|
577
699
|
}, span => {
|
|
578
700
|
this.createReadStream(table, request)
|
|
579
701
|
.on('error', err => {
|
|
580
702
|
const e = err;
|
|
581
|
-
(0,
|
|
703
|
+
(0, instrument_1.setSpanError)(span, e);
|
|
582
704
|
span.end();
|
|
583
705
|
callback(e, null);
|
|
584
706
|
})
|
|
@@ -593,13 +715,13 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
593
715
|
const rows = [];
|
|
594
716
|
let stats;
|
|
595
717
|
let metadata;
|
|
596
|
-
(0,
|
|
718
|
+
(0, instrument_1.startTrace)('Snapshot.run', {
|
|
597
719
|
...query,
|
|
598
720
|
...this._traceConfig,
|
|
599
721
|
}, span => {
|
|
600
722
|
return this.runStream(query)
|
|
601
723
|
.on('error', (err, rows, stats, metadata) => {
|
|
602
|
-
(0,
|
|
724
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
603
725
|
span.end();
|
|
604
726
|
callback(err, rows, stats, metadata);
|
|
605
727
|
})
|
|
@@ -607,7 +729,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
607
729
|
if (response.metadata) {
|
|
608
730
|
metadata = response.metadata;
|
|
609
731
|
if (metadata.transaction && !this.id) {
|
|
610
|
-
this._update(metadata.transaction);
|
|
732
|
+
this._update(metadata.transaction, span);
|
|
611
733
|
}
|
|
612
734
|
}
|
|
613
735
|
})
|
|
@@ -740,6 +862,11 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
740
862
|
else {
|
|
741
863
|
transaction.singleUse = this._options;
|
|
742
864
|
}
|
|
865
|
+
if (!this.id &&
|
|
866
|
+
this._options.readWrite &&
|
|
867
|
+
this.session.parent.isMuxEnabledForRW_) {
|
|
868
|
+
this._setPreviousTransactionId(transaction);
|
|
869
|
+
}
|
|
743
870
|
delete query.gaxOptions;
|
|
744
871
|
delete query.json;
|
|
745
872
|
delete query.jsonOptions;
|
|
@@ -770,7 +897,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
770
897
|
...query,
|
|
771
898
|
...this._traceConfig,
|
|
772
899
|
};
|
|
773
|
-
return (0,
|
|
900
|
+
return (0, instrument_1.startTrace)('Snapshot.runStream', traceConfig, span => {
|
|
774
901
|
let attempt = 0;
|
|
775
902
|
const database = this.session.parent;
|
|
776
903
|
const nthRequest = (0, request_id_header_1.nextNthRequest)(database);
|
|
@@ -796,7 +923,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
796
923
|
}
|
|
797
924
|
catch (e) {
|
|
798
925
|
const errorStream = new stream_1.PassThrough();
|
|
799
|
-
(0,
|
|
926
|
+
(0, instrument_1.setSpanErrorAndException)(span, e);
|
|
800
927
|
span.end();
|
|
801
928
|
setImmediate(() => errorStream.destroy(e));
|
|
802
929
|
return errorStream;
|
|
@@ -818,12 +945,13 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
818
945
|
gaxOptions,
|
|
819
946
|
})
|
|
820
947
|
.on('response', response => {
|
|
948
|
+
this._updatePrecommitToken(response);
|
|
821
949
|
if (response.metadata && response.metadata.transaction && !this.id) {
|
|
822
|
-
this._update(response.metadata.transaction);
|
|
950
|
+
this._update(response.metadata.transaction, span);
|
|
823
951
|
}
|
|
824
952
|
})
|
|
825
953
|
.on('error', err => {
|
|
826
|
-
(0,
|
|
954
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
827
955
|
const wasAborted = isErrorAborted(err);
|
|
828
956
|
if (!this.id && this._useInRunner && !wasAborted) {
|
|
829
957
|
span.addEvent('Stream broken. Safe to retry');
|
|
@@ -841,14 +969,14 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
841
969
|
})
|
|
842
970
|
.on('end', err => {
|
|
843
971
|
if (err) {
|
|
844
|
-
(0,
|
|
972
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
845
973
|
}
|
|
846
974
|
span.end();
|
|
847
975
|
});
|
|
848
976
|
if (resultStream instanceof stream_1.Stream) {
|
|
849
977
|
(0, stream_1.finished)(resultStream, err => {
|
|
850
978
|
if (err) {
|
|
851
|
-
(0,
|
|
979
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
852
980
|
}
|
|
853
981
|
span.end();
|
|
854
982
|
});
|
|
@@ -889,7 +1017,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
889
1017
|
return encodedRange;
|
|
890
1018
|
});
|
|
891
1019
|
}
|
|
892
|
-
if (
|
|
1020
|
+
if ((0, helper_1.isEmpty)(keySet)) {
|
|
893
1021
|
keySet.all = true;
|
|
894
1022
|
}
|
|
895
1023
|
return keySet;
|
|
@@ -920,7 +1048,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
920
1048
|
}
|
|
921
1049
|
// If we didn't detect a convenience format, we'll just assume that
|
|
922
1050
|
// they passed in a protobuf timestamp.
|
|
923
|
-
if (
|
|
1051
|
+
if ((0, helper_1.isEmpty)(readOnly)) {
|
|
924
1052
|
Object.assign(readOnly, options);
|
|
925
1053
|
}
|
|
926
1054
|
readOnly.returnReadTimestamp = returnReadTimestamp;
|
|
@@ -950,7 +1078,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
950
1078
|
});
|
|
951
1079
|
params.fields = fields;
|
|
952
1080
|
}
|
|
953
|
-
if (!
|
|
1081
|
+
if (!(0, helper_1.isEmpty)(typeMap)) {
|
|
954
1082
|
Object.keys(typeMap).forEach(param => {
|
|
955
1083
|
const type = typeMap[param];
|
|
956
1084
|
paramTypes[param] = codec_1.codec.createTypeObject(type);
|
|
@@ -978,11 +1106,10 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
978
1106
|
*
|
|
979
1107
|
* @param {spannerClient.spanner.v1.ITransaction} resp Response object.
|
|
980
1108
|
*/
|
|
981
|
-
_update(resp) {
|
|
1109
|
+
_update(resp, span) {
|
|
982
1110
|
const { id, readTimestamp } = resp;
|
|
983
1111
|
this.id = id;
|
|
984
1112
|
this.metadata = resp;
|
|
985
|
-
const span = (0, instrument_1.getActiveOrNoopSpan)();
|
|
986
1113
|
span.addEvent('Transaction Creation Done', { id: this.id.toString() });
|
|
987
1114
|
if (readTimestamp) {
|
|
988
1115
|
this.readTimestampProto = readTimestamp;
|
|
@@ -1057,7 +1184,7 @@ class Dml extends Snapshot {
|
|
|
1057
1184
|
if (typeof query === 'string') {
|
|
1058
1185
|
query = { sql: query };
|
|
1059
1186
|
}
|
|
1060
|
-
return (0,
|
|
1187
|
+
return (0, instrument_1.startTrace)('Dml.runUpdate', {
|
|
1061
1188
|
...query,
|
|
1062
1189
|
...this._traceConfig,
|
|
1063
1190
|
transactionTag: this.requestOptions?.transactionTag,
|
|
@@ -1069,7 +1196,7 @@ class Dml extends Snapshot {
|
|
|
1069
1196
|
rowCount = Math.floor(stats[stats.rowCount]);
|
|
1070
1197
|
}
|
|
1071
1198
|
if (err) {
|
|
1072
|
-
(0,
|
|
1199
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
1073
1200
|
}
|
|
1074
1201
|
span.end();
|
|
1075
1202
|
callback(err, rowCount);
|
|
@@ -1133,6 +1260,7 @@ class Transaction extends Dml {
|
|
|
1133
1260
|
commitTimestamp;
|
|
1134
1261
|
commitTimestampProto;
|
|
1135
1262
|
_queuedMutations;
|
|
1263
|
+
_retryCommit;
|
|
1136
1264
|
/**
|
|
1137
1265
|
* Timestamp at which the transaction was committed. Will be populated once
|
|
1138
1266
|
* {@link Transaction#commit} is called.
|
|
@@ -1179,6 +1307,7 @@ class Transaction extends Dml {
|
|
|
1179
1307
|
this._options = { readWrite: options };
|
|
1180
1308
|
this._options.isolationLevel = IsolationLevel.ISOLATION_LEVEL_UNSPECIFIED;
|
|
1181
1309
|
this.requestOptions = requestOptions;
|
|
1310
|
+
this._retryCommit = false;
|
|
1182
1311
|
}
|
|
1183
1312
|
batchUpdate(queries, optionsOrCallback, cb) {
|
|
1184
1313
|
const options = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
|
|
@@ -1211,6 +1340,11 @@ class Transaction extends Dml {
|
|
|
1211
1340
|
else {
|
|
1212
1341
|
transaction.begin = this._options;
|
|
1213
1342
|
}
|
|
1343
|
+
if (!this.id &&
|
|
1344
|
+
this._options.readWrite &&
|
|
1345
|
+
this.session.parent.isMuxEnabledForRW_) {
|
|
1346
|
+
this._setPreviousTransactionId(transaction);
|
|
1347
|
+
}
|
|
1214
1348
|
const requestOptionsWithTag = this.configureTagOptions(false, this.requestOptions?.transactionTag ?? undefined, options.requestOptions);
|
|
1215
1349
|
const reqOpts = {
|
|
1216
1350
|
session: this.session.formattedName_,
|
|
@@ -1229,7 +1363,7 @@ class Transaction extends Dml {
|
|
|
1229
1363
|
transactionTag: requestOptionsWithTag?.transactionTag,
|
|
1230
1364
|
requestTag: options?.requestOptions?.requestTag,
|
|
1231
1365
|
};
|
|
1232
|
-
return (0,
|
|
1366
|
+
return (0, instrument_1.startTrace)('Transaction.batchUpdate', traceConfig, span => {
|
|
1233
1367
|
this.request({
|
|
1234
1368
|
client: 'SpannerClient',
|
|
1235
1369
|
method: 'executeBatchDml',
|
|
@@ -1241,15 +1375,16 @@ class Transaction extends Dml {
|
|
|
1241
1375
|
if (err) {
|
|
1242
1376
|
const rowCounts = [];
|
|
1243
1377
|
batchUpdateError = Object.assign(err, { rowCounts });
|
|
1244
|
-
(0,
|
|
1378
|
+
(0, instrument_1.setSpanError)(span, batchUpdateError);
|
|
1245
1379
|
span.end();
|
|
1246
1380
|
callback(batchUpdateError, rowCounts, resp);
|
|
1247
1381
|
return;
|
|
1248
1382
|
}
|
|
1383
|
+
this._updatePrecommitToken(resp);
|
|
1249
1384
|
const { resultSets, status } = resp;
|
|
1250
1385
|
for (const resultSet of resultSets) {
|
|
1251
1386
|
if (!this.id && resultSet.metadata?.transaction) {
|
|
1252
|
-
this._update(resultSet.metadata.transaction);
|
|
1387
|
+
this._update(resultSet.metadata.transaction, span);
|
|
1253
1388
|
}
|
|
1254
1389
|
}
|
|
1255
1390
|
const rowCounts = resultSets.map(({ stats }) => {
|
|
@@ -1264,7 +1399,7 @@ class Transaction extends Dml {
|
|
|
1264
1399
|
metadata: Transaction.extractKnownMetadata(status.details),
|
|
1265
1400
|
rowCounts,
|
|
1266
1401
|
});
|
|
1267
|
-
(0,
|
|
1402
|
+
(0, instrument_1.setSpanError)(span, batchUpdateError);
|
|
1268
1403
|
}
|
|
1269
1404
|
span.end();
|
|
1270
1405
|
callback(batchUpdateError, rowCounts, resp);
|
|
@@ -1299,9 +1434,15 @@ class Transaction extends Dml {
|
|
|
1299
1434
|
const gaxOpts = 'gaxOptions' in options ? options.gaxOptions : options;
|
|
1300
1435
|
const mutations = this._queuedMutations;
|
|
1301
1436
|
const session = this.session.formattedName_;
|
|
1437
|
+
const precommitToken = this._latestPreCommitToken;
|
|
1302
1438
|
const requestOptions = options.requestOptions;
|
|
1303
|
-
const reqOpts = {
|
|
1304
|
-
|
|
1439
|
+
const reqOpts = {
|
|
1440
|
+
mutations,
|
|
1441
|
+
session,
|
|
1442
|
+
requestOptions,
|
|
1443
|
+
precommitToken,
|
|
1444
|
+
};
|
|
1445
|
+
return (0, instrument_1.startTrace)('Transaction.commit', {
|
|
1305
1446
|
transactionTag: this.requestOptions?.transactionTag,
|
|
1306
1447
|
...this._traceConfig,
|
|
1307
1448
|
}, span => {
|
|
@@ -1312,16 +1453,19 @@ class Transaction extends Dml {
|
|
|
1312
1453
|
reqOpts.singleUseTransaction = this._options;
|
|
1313
1454
|
}
|
|
1314
1455
|
else {
|
|
1456
|
+
if (this.session.parent.isMuxEnabledForRW_) {
|
|
1457
|
+
this._setMutationKey(mutations);
|
|
1458
|
+
}
|
|
1315
1459
|
this.begin().then(() => {
|
|
1316
1460
|
this.commit(options, (err, resp) => {
|
|
1317
1461
|
if (err) {
|
|
1318
|
-
(0,
|
|
1462
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
1319
1463
|
}
|
|
1320
1464
|
span.end();
|
|
1321
1465
|
callback(err, resp);
|
|
1322
1466
|
});
|
|
1323
1467
|
}, err => {
|
|
1324
|
-
(0,
|
|
1468
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
1325
1469
|
span.end();
|
|
1326
1470
|
callback(err, null);
|
|
1327
1471
|
});
|
|
@@ -1349,10 +1493,17 @@ class Transaction extends Dml {
|
|
|
1349
1493
|
gaxOpts: gaxOpts,
|
|
1350
1494
|
headers: (0, request_id_header_1.injectRequestIDIntoHeaders)(headers, this.session, (0, request_id_header_1.nextNthRequest)(database), 1),
|
|
1351
1495
|
}, (err, resp) => {
|
|
1496
|
+
if (resp &&
|
|
1497
|
+
'MultiplexedSessionRetry' in resp &&
|
|
1498
|
+
!this._retryCommit) {
|
|
1499
|
+
this._retryCommit = true;
|
|
1500
|
+
this._updatePrecommitToken(resp);
|
|
1501
|
+
return this.commit(options, callback);
|
|
1502
|
+
}
|
|
1352
1503
|
this.end();
|
|
1353
1504
|
if (err) {
|
|
1354
1505
|
span.addEvent('Commit failed');
|
|
1355
|
-
(0,
|
|
1506
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
1356
1507
|
}
|
|
1357
1508
|
else {
|
|
1358
1509
|
span.addEvent('Commit Done');
|
|
@@ -1591,7 +1742,7 @@ class Transaction extends Dml {
|
|
|
1591
1742
|
rollback(gaxOptionsOrCallback, cb) {
|
|
1592
1743
|
const gaxOpts = typeof gaxOptionsOrCallback === 'object' ? gaxOptionsOrCallback : {};
|
|
1593
1744
|
const callback = typeof gaxOptionsOrCallback === 'function' ? gaxOptionsOrCallback : cb;
|
|
1594
|
-
return (0,
|
|
1745
|
+
return (0, instrument_1.startTrace)('Transaction.rollback', this._traceConfig, span => {
|
|
1595
1746
|
if (!this.id) {
|
|
1596
1747
|
span.addEvent('Transaction ID is unknown, nothing to rollback.');
|
|
1597
1748
|
span.end();
|
|
@@ -1616,7 +1767,7 @@ class Transaction extends Dml {
|
|
|
1616
1767
|
headers: headers,
|
|
1617
1768
|
}, (err) => {
|
|
1618
1769
|
if (err) {
|
|
1619
|
-
(0,
|
|
1770
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
1620
1771
|
}
|
|
1621
1772
|
span.end();
|
|
1622
1773
|
this.end();
|
|
@@ -1741,6 +1892,8 @@ class Transaction extends Dml {
|
|
|
1741
1892
|
* (when any needed locks are acquired). The validation process succeeds only
|
|
1742
1893
|
* if there are no conflicting committed transactions (that committed
|
|
1743
1894
|
* mutations to the read data at a commit timestamp after the read timestamp).
|
|
1895
|
+
*
|
|
1896
|
+
* @deprecated Set readLockMode through setReadWriteTransactionOptions instead.
|
|
1744
1897
|
*/
|
|
1745
1898
|
useOptimisticLock() {
|
|
1746
1899
|
this._options.readWrite.readLockMode = ReadLockMode.OPTIMISTIC;
|
|
@@ -1757,12 +1910,6 @@ class Transaction extends Dml {
|
|
|
1757
1910
|
this._options.excludeTxnFromChangeStreams = true;
|
|
1758
1911
|
}
|
|
1759
1912
|
setReadWriteTransactionOptions(options) {
|
|
1760
|
-
/**
|
|
1761
|
-
* Set optimistic concurrency control for the transaction.
|
|
1762
|
-
*/
|
|
1763
|
-
if (options?.optimisticLock) {
|
|
1764
|
-
this._options.readWrite.readLockMode = ReadLockMode.OPTIMISTIC;
|
|
1765
|
-
}
|
|
1766
1913
|
/**
|
|
1767
1914
|
* Set option excludeTxnFromChangeStreams=true to exclude read/write transactions
|
|
1768
1915
|
* from being tracked in change streams.
|
|
@@ -1771,11 +1918,17 @@ class Transaction extends Dml {
|
|
|
1771
1918
|
this._options.excludeTxnFromChangeStreams = true;
|
|
1772
1919
|
}
|
|
1773
1920
|
/**
|
|
1774
|
-
* Set isolation level
|
|
1921
|
+
* Set isolation level.
|
|
1775
1922
|
*/
|
|
1776
1923
|
this._options.isolationLevel = options?.isolationLevel
|
|
1777
1924
|
? options?.isolationLevel
|
|
1778
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;
|
|
1779
1932
|
}
|
|
1780
1933
|
}
|
|
1781
1934
|
exports.Transaction = Transaction;
|
|
@@ -2017,13 +2170,13 @@ class PartitionedDml extends Dml {
|
|
|
2017
2170
|
this._options.excludeTxnFromChangeStreams = true;
|
|
2018
2171
|
}
|
|
2019
2172
|
runUpdate(query, callback) {
|
|
2020
|
-
return (0,
|
|
2173
|
+
return (0, instrument_1.startTrace)('PartitionedDml.runUpdate', {
|
|
2021
2174
|
...query,
|
|
2022
2175
|
...this._traceConfig,
|
|
2023
2176
|
}, span => {
|
|
2024
2177
|
super.runUpdate(query, (err, count) => {
|
|
2025
2178
|
if (err) {
|
|
2026
|
-
(0,
|
|
2179
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
2027
2180
|
}
|
|
2028
2181
|
this.end();
|
|
2029
2182
|
span.end();
|
|
@@ -513,6 +513,36 @@ export declare class DatabaseAdminClient {
|
|
|
513
513
|
]>;
|
|
514
514
|
deleteBackupSchedule(request: protos.google.spanner.admin.database.v1.IDeleteBackupScheduleRequest, options: CallOptions, callback: Callback<protos.google.protobuf.IEmpty, protos.google.spanner.admin.database.v1.IDeleteBackupScheduleRequest | null | undefined, {} | null | undefined>): void;
|
|
515
515
|
deleteBackupSchedule(request: protos.google.spanner.admin.database.v1.IDeleteBackupScheduleRequest, callback: Callback<protos.google.protobuf.IEmpty, protos.google.spanner.admin.database.v1.IDeleteBackupScheduleRequest | null | undefined, {} | null | undefined>): void;
|
|
516
|
+
/**
|
|
517
|
+
* This is an internal API called by Spanner Graph jobs. You should never need
|
|
518
|
+
* to call this API directly.
|
|
519
|
+
*
|
|
520
|
+
* @param {Object} request
|
|
521
|
+
* The request object that will be sent.
|
|
522
|
+
* @param {string} request.database
|
|
523
|
+
* Internal field, do not use directly.
|
|
524
|
+
* @param {string} request.operationId
|
|
525
|
+
* Internal field, do not use directly.
|
|
526
|
+
* @param {string} request.vmIdentityToken
|
|
527
|
+
* Internal field, do not use directly.
|
|
528
|
+
* @param {number} [request.progress]
|
|
529
|
+
* Internal field, do not use directly.
|
|
530
|
+
* @param {google.rpc.Status} [request.status]
|
|
531
|
+
* Internal field, do not use directly.
|
|
532
|
+
* @param {object} [options]
|
|
533
|
+
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
|
|
534
|
+
* @returns {Promise} - The promise which resolves to an array.
|
|
535
|
+
* The first element of the array is an object representing {@link protos.google.spanner.admin.database.v1.InternalUpdateGraphOperationResponse|InternalUpdateGraphOperationResponse}.
|
|
536
|
+
* Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation }
|
|
537
|
+
* for more details and examples.
|
|
538
|
+
*/
|
|
539
|
+
internalUpdateGraphOperation(request?: protos.google.spanner.admin.database.v1.IInternalUpdateGraphOperationRequest, options?: CallOptions): Promise<[
|
|
540
|
+
protos.google.spanner.admin.database.v1.IInternalUpdateGraphOperationResponse,
|
|
541
|
+
(protos.google.spanner.admin.database.v1.IInternalUpdateGraphOperationRequest | undefined),
|
|
542
|
+
{} | undefined
|
|
543
|
+
]>;
|
|
544
|
+
internalUpdateGraphOperation(request: protos.google.spanner.admin.database.v1.IInternalUpdateGraphOperationRequest, options: CallOptions, callback: Callback<protos.google.spanner.admin.database.v1.IInternalUpdateGraphOperationResponse, protos.google.spanner.admin.database.v1.IInternalUpdateGraphOperationRequest | null | undefined, {} | null | undefined>): void;
|
|
545
|
+
internalUpdateGraphOperation(request: protos.google.spanner.admin.database.v1.IInternalUpdateGraphOperationRequest, callback: Callback<protos.google.spanner.admin.database.v1.IInternalUpdateGraphOperationResponse, protos.google.spanner.admin.database.v1.IInternalUpdateGraphOperationRequest | null | undefined, {} | null | undefined>): void;
|
|
516
546
|
/**
|
|
517
547
|
* Creates a new Cloud Spanner database and starts to prepare it for serving.
|
|
518
548
|
* The returned {@link protos.google.longrunning.Operation|long-running operation} will
|
|
@@ -713,6 +743,10 @@ export declare class DatabaseAdminClient {
|
|
|
713
743
|
* ```
|
|
714
744
|
* For more details, see protobuffer [self
|
|
715
745
|
* description](https://developers.google.com/protocol-buffers/docs/techniques#self-description).
|
|
746
|
+
* @param {boolean} [request.throughputMode]
|
|
747
|
+
* Optional. This field is exposed to be used by the Spanner Migration Tool.
|
|
748
|
+
* For more details, see
|
|
749
|
+
* [SMT](https://github.com/GoogleCloudPlatform/spanner-migration-tool).
|
|
716
750
|
* @param {object} [options]
|
|
717
751
|
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
|
|
718
752
|
* @returns {Promise} - The promise which resolves to an array.
|