@google-cloud/spanner 8.0.0 → 8.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.
- 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 +1521 -0
- package/build/protos/protos.js +3906 -0
- package/build/protos/protos.json +317 -1
- 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 +1 -0
- package/build/src/database.js +2 -0
- package/build/src/helper.d.ts +90 -0
- package/build/src/helper.js +154 -0
- package/build/src/index.d.ts +33 -0
- package/build/src/index.js +178 -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/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/transaction-runner.d.ts +1 -0
- package/build/src/transaction-runner.js +6 -0
- package/build/src/transaction.d.ts +42 -1
- package/build/src/transaction.js +192 -42
- 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 +12 -5
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,129 @@ 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
|
+
this._latestPreCommitToken.seqNum < resp.precommitToken.seqNum) {
|
|
181
|
+
this._latestPreCommitToken = resp.precommitToken;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Selects a single representative mutation from a list to be used as the
|
|
186
|
+
* transaction's `mutationKey`.
|
|
187
|
+
*
|
|
188
|
+
* This key is required by Spanner and is sent in the `BeginTransactionRequest`
|
|
189
|
+
* for read-write transactions that only contain mutations. The selection follows
|
|
190
|
+
* a two-tiered heuristic to choose the most significant mutation.
|
|
191
|
+
*
|
|
192
|
+
* The selection heuristic is as follows:
|
|
193
|
+
*
|
|
194
|
+
* 1. Priority of Operation Type: High-priority mutations (`delete`, `update`,
|
|
195
|
+
* `replace`, `insertOrUpdate`) are always chosen over low-priority
|
|
196
|
+
* (`insert`) mutations.
|
|
197
|
+
*
|
|
198
|
+
* 2. Selection Strategy:
|
|
199
|
+
* - If any high-priority mutations exist, one is chosen randomly from
|
|
200
|
+
* that group, ignoring the number of rows.
|
|
201
|
+
* - If only `insert` mutations exist, the one(s) with the largest number
|
|
202
|
+
* of rows are identified, and one is chosen randomly from that subset.
|
|
203
|
+
*
|
|
204
|
+
* @protected
|
|
205
|
+
* @param mutations The list of mutations from which to select the key.
|
|
206
|
+
*/
|
|
207
|
+
_setMutationKey(mutations) {
|
|
208
|
+
// return if the list is empty
|
|
209
|
+
if (mutations.length === 0) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
// maintain a set of high priority keys
|
|
213
|
+
const HIGH_PRIORITY_KEYS = new Set([
|
|
214
|
+
'delete',
|
|
215
|
+
'update',
|
|
216
|
+
'replace',
|
|
217
|
+
'insertOrUpdate',
|
|
218
|
+
]);
|
|
219
|
+
// maintain a variable for low priority key
|
|
220
|
+
const LOW_PRIORITY_KEY = 'insert';
|
|
221
|
+
// Partition mutations into high and low priority groups.
|
|
222
|
+
const [highPriority, lowPriority] = mutations.reduce((acc, mutation) => {
|
|
223
|
+
const key = Object.keys(mutation)[0];
|
|
224
|
+
if (HIGH_PRIORITY_KEYS.has(key)) {
|
|
225
|
+
acc[0].push(mutation);
|
|
226
|
+
}
|
|
227
|
+
else if (key === LOW_PRIORITY_KEY) {
|
|
228
|
+
acc[1].push(mutation);
|
|
229
|
+
}
|
|
230
|
+
// return accumulated mutations list
|
|
231
|
+
return acc;
|
|
232
|
+
}, [[], []]);
|
|
233
|
+
// Apply the selection logic based on the rules.
|
|
234
|
+
if (highPriority.length > 0) {
|
|
235
|
+
// RULE 1: If high-priority keys exist, pick one randomly.
|
|
236
|
+
const randomIndex = Math.floor(Math.random() * highPriority.length);
|
|
237
|
+
this._mutationKey = highPriority[randomIndex];
|
|
238
|
+
}
|
|
239
|
+
else if (lowPriority.length > 0) {
|
|
240
|
+
// RULE 2: If only 'insert' key(s) exist, find the one with
|
|
241
|
+
// highest number of values
|
|
242
|
+
const { bestCandidates } = lowPriority.reduce((acc, mutation) => {
|
|
243
|
+
const size = mutation.insert?.values?.length || 0;
|
|
244
|
+
if (size > acc.maxSize) {
|
|
245
|
+
// New largest size found, start a new list
|
|
246
|
+
return { maxSize: size, bestCandidates: [mutation] };
|
|
247
|
+
}
|
|
248
|
+
if (size === acc.maxSize) {
|
|
249
|
+
// Same size as current max, add to list
|
|
250
|
+
acc.bestCandidates.push(mutation);
|
|
251
|
+
}
|
|
252
|
+
// return accumulated mutations list
|
|
253
|
+
return acc;
|
|
254
|
+
}, {
|
|
255
|
+
maxSize: -1,
|
|
256
|
+
bestCandidates: [],
|
|
257
|
+
});
|
|
258
|
+
// Pick randomly from the largest 'insert' mutation(s).
|
|
259
|
+
const randomIndex = Math.floor(Math.random() * bestCandidates.length);
|
|
260
|
+
this._mutationKey = bestCandidates[randomIndex];
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
// No mutations to select from.
|
|
264
|
+
this._mutationKey = null;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Modifies transaction selector to include the multiplexed session previous
|
|
269
|
+
* transaction id.
|
|
270
|
+
* This is essential for operations that use an `inline begin`.
|
|
271
|
+
* @protected
|
|
272
|
+
* @param transaction The transaction selector object that will be mutated
|
|
273
|
+
* to include the multiplexed session previous transaction id.
|
|
274
|
+
*/
|
|
275
|
+
_setPreviousTransactionId(transaction) {
|
|
276
|
+
transaction.begin.readWrite = Object.assign({}, transaction.begin.readWrite || {}, {
|
|
277
|
+
multiplexedSessionPreviousTransactionId: this.multiplexedSessionPreviousTransactionId,
|
|
278
|
+
});
|
|
173
279
|
}
|
|
174
280
|
begin(gaxOptionsOrCallback, cb) {
|
|
175
281
|
const gaxOpts = typeof gaxOptionsOrCallback === 'object' ? gaxOptionsOrCallback : {};
|
|
176
282
|
const callback = typeof gaxOptionsOrCallback === 'function' ? gaxOptionsOrCallback : cb;
|
|
177
283
|
const session = this.session.formattedName_;
|
|
178
284
|
const options = this._options;
|
|
285
|
+
if (this.multiplexedSessionPreviousTransactionId &&
|
|
286
|
+
this.session.parent.isMuxEnabledForRW_) {
|
|
287
|
+
options.readWrite.multiplexedSessionPreviousTransactionId =
|
|
288
|
+
this.multiplexedSessionPreviousTransactionId;
|
|
289
|
+
}
|
|
179
290
|
const reqOpts = {
|
|
180
291
|
session,
|
|
181
292
|
options,
|
|
182
293
|
};
|
|
294
|
+
if (this._mutationKey) {
|
|
295
|
+
reqOpts.mutationKey = this._mutationKey;
|
|
296
|
+
}
|
|
183
297
|
// Only hand crafted read-write transactions will be able to set a
|
|
184
298
|
// transaction tag for the BeginTransaction RPC. Also, this.requestOptions
|
|
185
299
|
// is only set in the constructor of Transaction, which is the constructor
|
|
@@ -193,7 +307,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
193
307
|
this._options.partitionedDml !== undefined)) {
|
|
194
308
|
(0, common_1.addLeaderAwareRoutingHeader)(headers);
|
|
195
309
|
}
|
|
196
|
-
return (0,
|
|
310
|
+
return (0, instrument_1.startTrace)('Snapshot.begin', {
|
|
197
311
|
transactionTag: this.requestOptions?.transactionTag,
|
|
198
312
|
...this._traceConfig,
|
|
199
313
|
}, span => {
|
|
@@ -206,10 +320,11 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
206
320
|
headers: (0, request_id_header_1.injectRequestIDIntoHeaders)(headers, this.session),
|
|
207
321
|
}, (err, resp) => {
|
|
208
322
|
if (err) {
|
|
209
|
-
(0,
|
|
323
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
210
324
|
}
|
|
211
325
|
else {
|
|
212
|
-
this.
|
|
326
|
+
this._updatePrecommitToken(resp);
|
|
327
|
+
this._update(resp, span);
|
|
213
328
|
}
|
|
214
329
|
span.end();
|
|
215
330
|
callback(err, resp);
|
|
@@ -399,6 +514,11 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
399
514
|
else {
|
|
400
515
|
transaction.singleUse = this._options;
|
|
401
516
|
}
|
|
517
|
+
if (!this.id &&
|
|
518
|
+
this._options.readWrite &&
|
|
519
|
+
this.session.parent.isMuxEnabledForRW_) {
|
|
520
|
+
this._setPreviousTransactionId(transaction);
|
|
521
|
+
}
|
|
402
522
|
const directedReadOptions = this._getDirectedReadOptions(request.directedReadOptions);
|
|
403
523
|
request = Object.assign({}, request);
|
|
404
524
|
delete request.gaxOptions;
|
|
@@ -430,7 +550,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
430
550
|
transactionTag: this.requestOptions?.transactionTag,
|
|
431
551
|
requestTag: requestOptions?.requestTag,
|
|
432
552
|
};
|
|
433
|
-
return (0,
|
|
553
|
+
return (0, instrument_1.startTrace)('Snapshot.createReadStream', traceConfig, span => {
|
|
434
554
|
let attempt = 0;
|
|
435
555
|
const database = this.session.parent;
|
|
436
556
|
const nthRequest = (0, request_id_header_1.nextNthRequest)(database);
|
|
@@ -470,12 +590,13 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
470
590
|
gaxOptions,
|
|
471
591
|
})
|
|
472
592
|
?.on('response', response => {
|
|
593
|
+
this._updatePrecommitToken(response);
|
|
473
594
|
if (response.metadata && response.metadata.transaction && !this.id) {
|
|
474
|
-
this._update(response.metadata.transaction);
|
|
595
|
+
this._update(response.metadata.transaction, span);
|
|
475
596
|
}
|
|
476
597
|
})
|
|
477
598
|
.on('error', err => {
|
|
478
|
-
(0,
|
|
599
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
479
600
|
const wasAborted = isErrorAborted(err);
|
|
480
601
|
if (!this.id && this._useInRunner && !wasAborted) {
|
|
481
602
|
// TODO: resolve https://github.com/googleapis/nodejs-spanner/issues/2170
|
|
@@ -492,14 +613,14 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
492
613
|
})
|
|
493
614
|
.on('end', err => {
|
|
494
615
|
if (err) {
|
|
495
|
-
(0,
|
|
616
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
496
617
|
}
|
|
497
618
|
span.end();
|
|
498
619
|
});
|
|
499
620
|
if (resultStream instanceof stream_1.Stream) {
|
|
500
621
|
(0, stream_1.finished)(resultStream, err => {
|
|
501
622
|
if (err) {
|
|
502
|
-
(0,
|
|
623
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
503
624
|
}
|
|
504
625
|
span.end();
|
|
505
626
|
});
|
|
@@ -571,14 +692,14 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
571
692
|
request = requestOrCallback;
|
|
572
693
|
callback = cb;
|
|
573
694
|
}
|
|
574
|
-
return (0,
|
|
695
|
+
return (0, instrument_1.startTrace)('Snapshot.read', {
|
|
575
696
|
tableName: table,
|
|
576
697
|
...this._traceConfig,
|
|
577
698
|
}, span => {
|
|
578
699
|
this.createReadStream(table, request)
|
|
579
700
|
.on('error', err => {
|
|
580
701
|
const e = err;
|
|
581
|
-
(0,
|
|
702
|
+
(0, instrument_1.setSpanError)(span, e);
|
|
582
703
|
span.end();
|
|
583
704
|
callback(e, null);
|
|
584
705
|
})
|
|
@@ -593,13 +714,13 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
593
714
|
const rows = [];
|
|
594
715
|
let stats;
|
|
595
716
|
let metadata;
|
|
596
|
-
(0,
|
|
717
|
+
(0, instrument_1.startTrace)('Snapshot.run', {
|
|
597
718
|
...query,
|
|
598
719
|
...this._traceConfig,
|
|
599
720
|
}, span => {
|
|
600
721
|
return this.runStream(query)
|
|
601
722
|
.on('error', (err, rows, stats, metadata) => {
|
|
602
|
-
(0,
|
|
723
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
603
724
|
span.end();
|
|
604
725
|
callback(err, rows, stats, metadata);
|
|
605
726
|
})
|
|
@@ -607,7 +728,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
607
728
|
if (response.metadata) {
|
|
608
729
|
metadata = response.metadata;
|
|
609
730
|
if (metadata.transaction && !this.id) {
|
|
610
|
-
this._update(metadata.transaction);
|
|
731
|
+
this._update(metadata.transaction, span);
|
|
611
732
|
}
|
|
612
733
|
}
|
|
613
734
|
})
|
|
@@ -740,6 +861,11 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
740
861
|
else {
|
|
741
862
|
transaction.singleUse = this._options;
|
|
742
863
|
}
|
|
864
|
+
if (!this.id &&
|
|
865
|
+
this._options.readWrite &&
|
|
866
|
+
this.session.parent.isMuxEnabledForRW_) {
|
|
867
|
+
this._setPreviousTransactionId(transaction);
|
|
868
|
+
}
|
|
743
869
|
delete query.gaxOptions;
|
|
744
870
|
delete query.json;
|
|
745
871
|
delete query.jsonOptions;
|
|
@@ -770,7 +896,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
770
896
|
...query,
|
|
771
897
|
...this._traceConfig,
|
|
772
898
|
};
|
|
773
|
-
return (0,
|
|
899
|
+
return (0, instrument_1.startTrace)('Snapshot.runStream', traceConfig, span => {
|
|
774
900
|
let attempt = 0;
|
|
775
901
|
const database = this.session.parent;
|
|
776
902
|
const nthRequest = (0, request_id_header_1.nextNthRequest)(database);
|
|
@@ -796,7 +922,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
796
922
|
}
|
|
797
923
|
catch (e) {
|
|
798
924
|
const errorStream = new stream_1.PassThrough();
|
|
799
|
-
(0,
|
|
925
|
+
(0, instrument_1.setSpanErrorAndException)(span, e);
|
|
800
926
|
span.end();
|
|
801
927
|
setImmediate(() => errorStream.destroy(e));
|
|
802
928
|
return errorStream;
|
|
@@ -818,12 +944,13 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
818
944
|
gaxOptions,
|
|
819
945
|
})
|
|
820
946
|
.on('response', response => {
|
|
947
|
+
this._updatePrecommitToken(response);
|
|
821
948
|
if (response.metadata && response.metadata.transaction && !this.id) {
|
|
822
|
-
this._update(response.metadata.transaction);
|
|
949
|
+
this._update(response.metadata.transaction, span);
|
|
823
950
|
}
|
|
824
951
|
})
|
|
825
952
|
.on('error', err => {
|
|
826
|
-
(0,
|
|
953
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
827
954
|
const wasAborted = isErrorAborted(err);
|
|
828
955
|
if (!this.id && this._useInRunner && !wasAborted) {
|
|
829
956
|
span.addEvent('Stream broken. Safe to retry');
|
|
@@ -841,14 +968,14 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
841
968
|
})
|
|
842
969
|
.on('end', err => {
|
|
843
970
|
if (err) {
|
|
844
|
-
(0,
|
|
971
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
845
972
|
}
|
|
846
973
|
span.end();
|
|
847
974
|
});
|
|
848
975
|
if (resultStream instanceof stream_1.Stream) {
|
|
849
976
|
(0, stream_1.finished)(resultStream, err => {
|
|
850
977
|
if (err) {
|
|
851
|
-
(0,
|
|
978
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
852
979
|
}
|
|
853
980
|
span.end();
|
|
854
981
|
});
|
|
@@ -889,7 +1016,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
889
1016
|
return encodedRange;
|
|
890
1017
|
});
|
|
891
1018
|
}
|
|
892
|
-
if (
|
|
1019
|
+
if ((0, helper_1.isEmpty)(keySet)) {
|
|
893
1020
|
keySet.all = true;
|
|
894
1021
|
}
|
|
895
1022
|
return keySet;
|
|
@@ -920,7 +1047,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
920
1047
|
}
|
|
921
1048
|
// If we didn't detect a convenience format, we'll just assume that
|
|
922
1049
|
// they passed in a protobuf timestamp.
|
|
923
|
-
if (
|
|
1050
|
+
if ((0, helper_1.isEmpty)(readOnly)) {
|
|
924
1051
|
Object.assign(readOnly, options);
|
|
925
1052
|
}
|
|
926
1053
|
readOnly.returnReadTimestamp = returnReadTimestamp;
|
|
@@ -950,7 +1077,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
950
1077
|
});
|
|
951
1078
|
params.fields = fields;
|
|
952
1079
|
}
|
|
953
|
-
if (!
|
|
1080
|
+
if (!(0, helper_1.isEmpty)(typeMap)) {
|
|
954
1081
|
Object.keys(typeMap).forEach(param => {
|
|
955
1082
|
const type = typeMap[param];
|
|
956
1083
|
paramTypes[param] = codec_1.codec.createTypeObject(type);
|
|
@@ -978,11 +1105,10 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
978
1105
|
*
|
|
979
1106
|
* @param {spannerClient.spanner.v1.ITransaction} resp Response object.
|
|
980
1107
|
*/
|
|
981
|
-
_update(resp) {
|
|
1108
|
+
_update(resp, span) {
|
|
982
1109
|
const { id, readTimestamp } = resp;
|
|
983
1110
|
this.id = id;
|
|
984
1111
|
this.metadata = resp;
|
|
985
|
-
const span = (0, instrument_1.getActiveOrNoopSpan)();
|
|
986
1112
|
span.addEvent('Transaction Creation Done', { id: this.id.toString() });
|
|
987
1113
|
if (readTimestamp) {
|
|
988
1114
|
this.readTimestampProto = readTimestamp;
|
|
@@ -1057,7 +1183,7 @@ class Dml extends Snapshot {
|
|
|
1057
1183
|
if (typeof query === 'string') {
|
|
1058
1184
|
query = { sql: query };
|
|
1059
1185
|
}
|
|
1060
|
-
return (0,
|
|
1186
|
+
return (0, instrument_1.startTrace)('Dml.runUpdate', {
|
|
1061
1187
|
...query,
|
|
1062
1188
|
...this._traceConfig,
|
|
1063
1189
|
transactionTag: this.requestOptions?.transactionTag,
|
|
@@ -1069,7 +1195,7 @@ class Dml extends Snapshot {
|
|
|
1069
1195
|
rowCount = Math.floor(stats[stats.rowCount]);
|
|
1070
1196
|
}
|
|
1071
1197
|
if (err) {
|
|
1072
|
-
(0,
|
|
1198
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
1073
1199
|
}
|
|
1074
1200
|
span.end();
|
|
1075
1201
|
callback(err, rowCount);
|
|
@@ -1133,6 +1259,7 @@ class Transaction extends Dml {
|
|
|
1133
1259
|
commitTimestamp;
|
|
1134
1260
|
commitTimestampProto;
|
|
1135
1261
|
_queuedMutations;
|
|
1262
|
+
_retryCommit;
|
|
1136
1263
|
/**
|
|
1137
1264
|
* Timestamp at which the transaction was committed. Will be populated once
|
|
1138
1265
|
* {@link Transaction#commit} is called.
|
|
@@ -1179,6 +1306,7 @@ class Transaction extends Dml {
|
|
|
1179
1306
|
this._options = { readWrite: options };
|
|
1180
1307
|
this._options.isolationLevel = IsolationLevel.ISOLATION_LEVEL_UNSPECIFIED;
|
|
1181
1308
|
this.requestOptions = requestOptions;
|
|
1309
|
+
this._retryCommit = false;
|
|
1182
1310
|
}
|
|
1183
1311
|
batchUpdate(queries, optionsOrCallback, cb) {
|
|
1184
1312
|
const options = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
|
|
@@ -1211,6 +1339,11 @@ class Transaction extends Dml {
|
|
|
1211
1339
|
else {
|
|
1212
1340
|
transaction.begin = this._options;
|
|
1213
1341
|
}
|
|
1342
|
+
if (!this.id &&
|
|
1343
|
+
this._options.readWrite &&
|
|
1344
|
+
this.session.parent.isMuxEnabledForRW_) {
|
|
1345
|
+
this._setPreviousTransactionId(transaction);
|
|
1346
|
+
}
|
|
1214
1347
|
const requestOptionsWithTag = this.configureTagOptions(false, this.requestOptions?.transactionTag ?? undefined, options.requestOptions);
|
|
1215
1348
|
const reqOpts = {
|
|
1216
1349
|
session: this.session.formattedName_,
|
|
@@ -1229,7 +1362,7 @@ class Transaction extends Dml {
|
|
|
1229
1362
|
transactionTag: requestOptionsWithTag?.transactionTag,
|
|
1230
1363
|
requestTag: options?.requestOptions?.requestTag,
|
|
1231
1364
|
};
|
|
1232
|
-
return (0,
|
|
1365
|
+
return (0, instrument_1.startTrace)('Transaction.batchUpdate', traceConfig, span => {
|
|
1233
1366
|
this.request({
|
|
1234
1367
|
client: 'SpannerClient',
|
|
1235
1368
|
method: 'executeBatchDml',
|
|
@@ -1241,15 +1374,16 @@ class Transaction extends Dml {
|
|
|
1241
1374
|
if (err) {
|
|
1242
1375
|
const rowCounts = [];
|
|
1243
1376
|
batchUpdateError = Object.assign(err, { rowCounts });
|
|
1244
|
-
(0,
|
|
1377
|
+
(0, instrument_1.setSpanError)(span, batchUpdateError);
|
|
1245
1378
|
span.end();
|
|
1246
1379
|
callback(batchUpdateError, rowCounts, resp);
|
|
1247
1380
|
return;
|
|
1248
1381
|
}
|
|
1382
|
+
this._updatePrecommitToken(resp);
|
|
1249
1383
|
const { resultSets, status } = resp;
|
|
1250
1384
|
for (const resultSet of resultSets) {
|
|
1251
1385
|
if (!this.id && resultSet.metadata?.transaction) {
|
|
1252
|
-
this._update(resultSet.metadata.transaction);
|
|
1386
|
+
this._update(resultSet.metadata.transaction, span);
|
|
1253
1387
|
}
|
|
1254
1388
|
}
|
|
1255
1389
|
const rowCounts = resultSets.map(({ stats }) => {
|
|
@@ -1264,7 +1398,7 @@ class Transaction extends Dml {
|
|
|
1264
1398
|
metadata: Transaction.extractKnownMetadata(status.details),
|
|
1265
1399
|
rowCounts,
|
|
1266
1400
|
});
|
|
1267
|
-
(0,
|
|
1401
|
+
(0, instrument_1.setSpanError)(span, batchUpdateError);
|
|
1268
1402
|
}
|
|
1269
1403
|
span.end();
|
|
1270
1404
|
callback(batchUpdateError, rowCounts, resp);
|
|
@@ -1299,9 +1433,15 @@ class Transaction extends Dml {
|
|
|
1299
1433
|
const gaxOpts = 'gaxOptions' in options ? options.gaxOptions : options;
|
|
1300
1434
|
const mutations = this._queuedMutations;
|
|
1301
1435
|
const session = this.session.formattedName_;
|
|
1436
|
+
const precommitToken = this._latestPreCommitToken;
|
|
1302
1437
|
const requestOptions = options.requestOptions;
|
|
1303
|
-
const reqOpts = {
|
|
1304
|
-
|
|
1438
|
+
const reqOpts = {
|
|
1439
|
+
mutations,
|
|
1440
|
+
session,
|
|
1441
|
+
requestOptions,
|
|
1442
|
+
precommitToken,
|
|
1443
|
+
};
|
|
1444
|
+
return (0, instrument_1.startTrace)('Transaction.commit', {
|
|
1305
1445
|
transactionTag: this.requestOptions?.transactionTag,
|
|
1306
1446
|
...this._traceConfig,
|
|
1307
1447
|
}, span => {
|
|
@@ -1312,16 +1452,19 @@ class Transaction extends Dml {
|
|
|
1312
1452
|
reqOpts.singleUseTransaction = this._options;
|
|
1313
1453
|
}
|
|
1314
1454
|
else {
|
|
1455
|
+
if (this.session.parent.isMuxEnabledForRW_) {
|
|
1456
|
+
this._setMutationKey(mutations);
|
|
1457
|
+
}
|
|
1315
1458
|
this.begin().then(() => {
|
|
1316
1459
|
this.commit(options, (err, resp) => {
|
|
1317
1460
|
if (err) {
|
|
1318
|
-
(0,
|
|
1461
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
1319
1462
|
}
|
|
1320
1463
|
span.end();
|
|
1321
1464
|
callback(err, resp);
|
|
1322
1465
|
});
|
|
1323
1466
|
}, err => {
|
|
1324
|
-
(0,
|
|
1467
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
1325
1468
|
span.end();
|
|
1326
1469
|
callback(err, null);
|
|
1327
1470
|
});
|
|
@@ -1349,10 +1492,17 @@ class Transaction extends Dml {
|
|
|
1349
1492
|
gaxOpts: gaxOpts,
|
|
1350
1493
|
headers: (0, request_id_header_1.injectRequestIDIntoHeaders)(headers, this.session, (0, request_id_header_1.nextNthRequest)(database), 1),
|
|
1351
1494
|
}, (err, resp) => {
|
|
1495
|
+
if (resp &&
|
|
1496
|
+
'MultiplexedSessionRetry' in resp &&
|
|
1497
|
+
!this._retryCommit) {
|
|
1498
|
+
this._retryCommit = true;
|
|
1499
|
+
this._updatePrecommitToken(resp);
|
|
1500
|
+
return this.commit(options, callback);
|
|
1501
|
+
}
|
|
1352
1502
|
this.end();
|
|
1353
1503
|
if (err) {
|
|
1354
1504
|
span.addEvent('Commit failed');
|
|
1355
|
-
(0,
|
|
1505
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
1356
1506
|
}
|
|
1357
1507
|
else {
|
|
1358
1508
|
span.addEvent('Commit Done');
|
|
@@ -1591,7 +1741,7 @@ class Transaction extends Dml {
|
|
|
1591
1741
|
rollback(gaxOptionsOrCallback, cb) {
|
|
1592
1742
|
const gaxOpts = typeof gaxOptionsOrCallback === 'object' ? gaxOptionsOrCallback : {};
|
|
1593
1743
|
const callback = typeof gaxOptionsOrCallback === 'function' ? gaxOptionsOrCallback : cb;
|
|
1594
|
-
return (0,
|
|
1744
|
+
return (0, instrument_1.startTrace)('Transaction.rollback', this._traceConfig, span => {
|
|
1595
1745
|
if (!this.id) {
|
|
1596
1746
|
span.addEvent('Transaction ID is unknown, nothing to rollback.');
|
|
1597
1747
|
span.end();
|
|
@@ -1616,7 +1766,7 @@ class Transaction extends Dml {
|
|
|
1616
1766
|
headers: headers,
|
|
1617
1767
|
}, (err) => {
|
|
1618
1768
|
if (err) {
|
|
1619
|
-
(0,
|
|
1769
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
1620
1770
|
}
|
|
1621
1771
|
span.end();
|
|
1622
1772
|
this.end();
|
|
@@ -2017,13 +2167,13 @@ class PartitionedDml extends Dml {
|
|
|
2017
2167
|
this._options.excludeTxnFromChangeStreams = true;
|
|
2018
2168
|
}
|
|
2019
2169
|
runUpdate(query, callback) {
|
|
2020
|
-
return (0,
|
|
2170
|
+
return (0, instrument_1.startTrace)('PartitionedDml.runUpdate', {
|
|
2021
2171
|
...query,
|
|
2022
2172
|
...this._traceConfig,
|
|
2023
2173
|
}, span => {
|
|
2024
2174
|
super.runUpdate(query, (err, count) => {
|
|
2025
2175
|
if (err) {
|
|
2026
|
-
(0,
|
|
2176
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
2027
2177
|
}
|
|
2028
2178
|
this.end();
|
|
2029
2179
|
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.
|