@google-cloud/spanner 8.8.0 → 8.9.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/build/src/batch-transaction.js +3 -4
- package/build/src/database.js +35 -26
- package/build/src/index.d.ts +2 -1
- package/build/src/index.js +94 -54
- package/build/src/instance-config.js +1 -2
- package/build/src/instance.js +66 -48
- package/build/src/session.js +1 -2
- package/build/src/transaction.d.ts +3 -0
- package/build/src/transaction.js +99 -5
- package/package.json +1 -1
|
@@ -18,7 +18,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
exports.BatchTransaction = void 0;
|
|
19
19
|
const precise_date_1 = require("@google-cloud/precise-date");
|
|
20
20
|
const promisify_1 = require("@google-cloud/promisify");
|
|
21
|
-
const extend = require("extend");
|
|
22
21
|
const transaction_1 = require("./transaction");
|
|
23
22
|
const common_1 = require("../src/common");
|
|
24
23
|
const instrument_1 = require("./instrument");
|
|
@@ -129,11 +128,11 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
129
128
|
dbName: this.getDBName(),
|
|
130
129
|
};
|
|
131
130
|
return (0, instrument_1.startTrace)('BatchTransaction.createPartitions_', traceConfig, span => {
|
|
132
|
-
const query =
|
|
131
|
+
const query = Object.assign({}, config.reqOpts, {
|
|
133
132
|
session: this.session.formattedName_,
|
|
134
133
|
transaction: { id: this.id },
|
|
135
134
|
});
|
|
136
|
-
config.reqOpts =
|
|
135
|
+
config.reqOpts = Object.assign({}, query);
|
|
137
136
|
const headers = {
|
|
138
137
|
[common_1.CLOUD_RESOURCE_HEADER]: this.session.parent
|
|
139
138
|
.formattedName_,
|
|
@@ -148,7 +147,7 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
148
147
|
return;
|
|
149
148
|
}
|
|
150
149
|
const partitions = resp.partitions.map(partition => {
|
|
151
|
-
return
|
|
150
|
+
return Object.assign({}, query, partition);
|
|
152
151
|
});
|
|
153
152
|
if (resp.transaction) {
|
|
154
153
|
const { id, readTimestamp } = resp.transaction;
|
package/build/src/database.js
CHANGED
|
@@ -201,7 +201,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
201
201
|
const gaxOpts = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
|
|
202
202
|
const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
|
|
203
203
|
const reqOpts = {
|
|
204
|
-
database:
|
|
204
|
+
database: Object.assign({
|
|
205
205
|
name: this.formattedName_,
|
|
206
206
|
}, metadata),
|
|
207
207
|
updateMask: {
|
|
@@ -360,7 +360,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
360
360
|
createSession(optionsOrCallback, cb) {
|
|
361
361
|
const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
|
|
362
362
|
const options = typeof optionsOrCallback === 'object' && optionsOrCallback
|
|
363
|
-
?
|
|
363
|
+
? Object.assign({}, optionsOrCallback)
|
|
364
364
|
: {};
|
|
365
365
|
const reqOpts = {
|
|
366
366
|
database: this.formattedName_,
|
|
@@ -596,19 +596,22 @@ class Database extends common.GrpcServiceObject {
|
|
|
596
596
|
? optionsOrCallback
|
|
597
597
|
: {};
|
|
598
598
|
const gaxOpts = extend(true, {}, options.gaxOptions);
|
|
599
|
-
|
|
599
|
+
const reqOpts = Object.assign({}, options, {
|
|
600
600
|
database: this.formattedName_,
|
|
601
601
|
});
|
|
602
602
|
delete reqOpts.gaxOptions;
|
|
603
603
|
// Copy over pageSize and pageToken values from gaxOptions.
|
|
604
604
|
// However values set on options take precedence.
|
|
605
605
|
if (gaxOpts) {
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
606
|
+
const gax = gaxOpts;
|
|
607
|
+
if (gax.pageSize !== undefined) {
|
|
608
|
+
reqOpts.pageSize ??= gax.pageSize;
|
|
609
|
+
delete gax.pageSize;
|
|
610
|
+
}
|
|
611
|
+
if (gax.pageToken !== undefined) {
|
|
612
|
+
reqOpts.pageToken ??= gax.pageToken;
|
|
613
|
+
delete gax.pageToken;
|
|
614
|
+
}
|
|
612
615
|
}
|
|
613
616
|
const headers = this._metadataWithRequestId(this._nextNthRequest(), 1, this.commonHeaders_);
|
|
614
617
|
return (0, instrument_1.startTrace)('Database.getSessions', this._traceConfig, span => {
|
|
@@ -633,7 +636,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
633
636
|
}
|
|
634
637
|
span.end();
|
|
635
638
|
const nextQuery = nextPageRequest
|
|
636
|
-
?
|
|
639
|
+
? Object.assign({}, options, nextPageRequest)
|
|
637
640
|
: null;
|
|
638
641
|
callback(err, sessionInstances, nextQuery, ...args);
|
|
639
642
|
});
|
|
@@ -681,19 +684,22 @@ class Database extends common.GrpcServiceObject {
|
|
|
681
684
|
*/
|
|
682
685
|
getSessionsStream(options = {}) {
|
|
683
686
|
const gaxOpts = extend(true, {}, options.gaxOptions);
|
|
684
|
-
|
|
687
|
+
const reqOpts = Object.assign({}, options, {
|
|
685
688
|
database: this.formattedName_,
|
|
686
689
|
});
|
|
687
690
|
delete reqOpts.gaxOptions;
|
|
688
691
|
// Copy over pageSize and pageToken values from gaxOptions.
|
|
689
692
|
// However values set on options take precedence.
|
|
690
693
|
if (gaxOpts) {
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
694
|
+
const gax = gaxOpts;
|
|
695
|
+
if (gax.pageSize !== undefined) {
|
|
696
|
+
reqOpts.pageSize ??= gax.pageSize;
|
|
697
|
+
delete gax.pageSize;
|
|
698
|
+
}
|
|
699
|
+
if (gax.pageToken !== undefined) {
|
|
700
|
+
reqOpts.pageToken ??= gax.pageToken;
|
|
701
|
+
delete gax.pageToken;
|
|
702
|
+
}
|
|
697
703
|
}
|
|
698
704
|
return this.requestStream({
|
|
699
705
|
client: 'SpannerClient',
|
|
@@ -806,18 +812,21 @@ class Database extends common.GrpcServiceObject {
|
|
|
806
812
|
getDatabaseRoles(optionsOrCallback, cb) {
|
|
807
813
|
const gaxOpts = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
|
|
808
814
|
const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
|
|
809
|
-
|
|
815
|
+
const reqOpts = {
|
|
810
816
|
parent: this.formattedName_,
|
|
811
817
|
};
|
|
812
818
|
// Copy over pageSize and pageToken values from gaxOptions.
|
|
813
819
|
// However, values set on options take precedence.
|
|
814
820
|
if (gaxOpts) {
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
+
const gax = gaxOpts;
|
|
822
|
+
if (gax.pageSize !== undefined) {
|
|
823
|
+
reqOpts.pageSize ??= gax.pageSize;
|
|
824
|
+
delete gax.pageSize;
|
|
825
|
+
}
|
|
826
|
+
if (gax.pageToken !== undefined) {
|
|
827
|
+
reqOpts.pageToken ??= gax.pageToken;
|
|
828
|
+
delete gax.pageToken;
|
|
829
|
+
}
|
|
821
830
|
}
|
|
822
831
|
this.request({
|
|
823
832
|
client: 'DatabaseAdminClient',
|
|
@@ -827,7 +836,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
827
836
|
headers: this.commonHeaders_,
|
|
828
837
|
}, (err, roles, nextPageRequest, ...args) => {
|
|
829
838
|
const nextQuery = nextPageRequest
|
|
830
|
-
?
|
|
839
|
+
? Object.assign({}, gaxOpts, nextPageRequest)
|
|
831
840
|
: null;
|
|
832
841
|
callback(err, roles, nextQuery, ...args);
|
|
833
842
|
});
|
|
@@ -1595,7 +1604,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
1595
1604
|
statements: (0, helper_1.toArray)(statements),
|
|
1596
1605
|
};
|
|
1597
1606
|
}
|
|
1598
|
-
const reqOpts =
|
|
1607
|
+
const reqOpts = Object.assign({
|
|
1599
1608
|
database: this.formattedName_,
|
|
1600
1609
|
}, statements);
|
|
1601
1610
|
return this.request({
|
package/build/src/index.d.ts
CHANGED
|
@@ -259,7 +259,8 @@ declare class Spanner extends GrpcService {
|
|
|
259
259
|
*/
|
|
260
260
|
getDatabaseAdminClient(): v1.DatabaseAdminClient;
|
|
261
261
|
/** Closes this Spanner client and cleans up all resources used by it. */
|
|
262
|
-
close(): void
|
|
262
|
+
close(): Promise<void>;
|
|
263
|
+
close(callback: (err: Error | null) => void): void;
|
|
263
264
|
/**
|
|
264
265
|
* Config for the new instance.
|
|
265
266
|
*
|
package/build/src/index.js
CHANGED
|
@@ -356,19 +356,44 @@ class Spanner extends service_1.GrpcService {
|
|
|
356
356
|
}
|
|
357
357
|
return this.clients_.get(clientName);
|
|
358
358
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
359
|
+
close(callback) {
|
|
360
|
+
const performTeardown = async () => {
|
|
361
|
+
const promises = [];
|
|
362
|
+
this.clients_.forEach(c => {
|
|
363
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
364
|
+
const client = c;
|
|
365
|
+
// Promise.resolve().then() safely converts synchronous throws into Promise rejections
|
|
366
|
+
if (client.operationsClient && client.operationsClient.close) {
|
|
367
|
+
promises.push(Promise.resolve().then(() => client.operationsClient.close()));
|
|
368
|
+
}
|
|
369
|
+
if (client.close) {
|
|
370
|
+
promises.push(Promise.resolve().then(() => client.close()));
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
// Wait for all close attempts to settle.
|
|
374
|
+
// Map success to undefined, and failure to the error.
|
|
375
|
+
const results = await Promise.all(promises.map(p => p.then(() => undefined, err => err || new Error('Unknown error during close'))));
|
|
376
|
+
// Always execute cleanup
|
|
377
|
+
try {
|
|
378
|
+
await cleanup();
|
|
366
379
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
380
|
+
catch (err) {
|
|
381
|
+
console.error('Error occured during cleanup: ', err);
|
|
382
|
+
}
|
|
383
|
+
// If any client failed to close, throw the first error we captured
|
|
384
|
+
const firstError = results.find(r => r !== undefined);
|
|
385
|
+
if (firstError) {
|
|
386
|
+
throw firstError;
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
const res = performTeardown();
|
|
390
|
+
if (callback) {
|
|
391
|
+
// process.nextTick prevents Unhandled Promise Rejections if callback throws
|
|
392
|
+
res.then(() => process.nextTick(() => callback(null)), err => process.nextTick(() => callback(err)));
|
|
393
|
+
}
|
|
394
|
+
else {
|
|
395
|
+
return res;
|
|
396
|
+
}
|
|
372
397
|
}
|
|
373
398
|
createInstance(name, config, callback) {
|
|
374
399
|
if (!name) {
|
|
@@ -382,7 +407,7 @@ class Spanner extends service_1.GrpcService {
|
|
|
382
407
|
const reqOpts = {
|
|
383
408
|
parent: this.projectFormattedName_,
|
|
384
409
|
instanceId: formattedName.split('/').pop(),
|
|
385
|
-
instance:
|
|
410
|
+
instance: Object.assign({
|
|
386
411
|
name: formattedName,
|
|
387
412
|
displayName,
|
|
388
413
|
nodeCount: config.nodes,
|
|
@@ -426,19 +451,22 @@ class Spanner extends service_1.GrpcService {
|
|
|
426
451
|
: {};
|
|
427
452
|
const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
|
|
428
453
|
const gaxOpts = extend(true, {}, options.gaxOptions);
|
|
429
|
-
|
|
454
|
+
const reqOpts = Object.assign({}, options, {
|
|
430
455
|
parent: 'projects/' + this.projectId,
|
|
431
456
|
});
|
|
432
457
|
delete reqOpts.gaxOptions;
|
|
433
458
|
// Copy over pageSize and pageToken values from gaxOptions.
|
|
434
459
|
// However values set on options take precedence.
|
|
435
460
|
if (gaxOpts) {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
461
|
+
const gax = gaxOpts;
|
|
462
|
+
if (gax.pageSize !== undefined) {
|
|
463
|
+
reqOpts.pageSize ??= gax.pageSize;
|
|
464
|
+
delete gax.pageSize;
|
|
465
|
+
}
|
|
466
|
+
if (gax.pageToken !== undefined) {
|
|
467
|
+
reqOpts.pageToken ??= gax.pageToken;
|
|
468
|
+
delete gax.pageToken;
|
|
469
|
+
}
|
|
442
470
|
}
|
|
443
471
|
this.request({
|
|
444
472
|
client: 'InstanceAdminClient',
|
|
@@ -456,7 +484,7 @@ class Spanner extends service_1.GrpcService {
|
|
|
456
484
|
});
|
|
457
485
|
}
|
|
458
486
|
const nextQuery = nextPageRequest
|
|
459
|
-
?
|
|
487
|
+
? Object.assign({}, options, nextPageRequest)
|
|
460
488
|
: null;
|
|
461
489
|
callback(err, instanceInstances, nextQuery, ...args);
|
|
462
490
|
});
|
|
@@ -500,19 +528,22 @@ class Spanner extends service_1.GrpcService {
|
|
|
500
528
|
*/
|
|
501
529
|
getInstancesStream(options = {}) {
|
|
502
530
|
const gaxOpts = extend(true, {}, options.gaxOptions);
|
|
503
|
-
|
|
531
|
+
const reqOpts = Object.assign({}, options, {
|
|
504
532
|
parent: 'projects/' + this.projectId,
|
|
505
533
|
});
|
|
506
534
|
delete reqOpts.gaxOptions;
|
|
507
535
|
// Copy over pageSize and pageToken values from gaxOptions.
|
|
508
536
|
// However values set on options take precedence.
|
|
509
537
|
if (gaxOpts) {
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
538
|
+
const gax = gaxOpts;
|
|
539
|
+
if (gax.pageSize !== undefined) {
|
|
540
|
+
reqOpts.pageSize ??= gax.pageSize;
|
|
541
|
+
delete gax.pageSize;
|
|
542
|
+
}
|
|
543
|
+
if (gax.pageToken !== undefined) {
|
|
544
|
+
reqOpts.pageToken ??= gax.pageToken;
|
|
545
|
+
delete gax.pageToken;
|
|
546
|
+
}
|
|
516
547
|
}
|
|
517
548
|
return this.requestStream({
|
|
518
549
|
client: 'InstanceAdminClient',
|
|
@@ -539,7 +570,7 @@ class Spanner extends service_1.GrpcService {
|
|
|
539
570
|
const reqOpts = {
|
|
540
571
|
parent: this.projectFormattedName_,
|
|
541
572
|
instanceConfigId: formattedName.split('/').pop(),
|
|
542
|
-
instanceConfig:
|
|
573
|
+
instanceConfig: Object.assign({
|
|
543
574
|
name: formattedName,
|
|
544
575
|
displayName,
|
|
545
576
|
}, config),
|
|
@@ -575,19 +606,22 @@ class Spanner extends service_1.GrpcService {
|
|
|
575
606
|
? optionsOrCallback
|
|
576
607
|
: {};
|
|
577
608
|
const gaxOpts = extend(true, {}, options.gaxOptions);
|
|
578
|
-
|
|
609
|
+
const reqOpts = Object.assign({}, options, {
|
|
579
610
|
parent: 'projects/' + this.projectId,
|
|
580
611
|
});
|
|
581
612
|
delete reqOpts.gaxOptions;
|
|
582
613
|
// Copy over pageSize and pageToken values from gaxOptions.
|
|
583
614
|
// However values set on options take precedence.
|
|
584
615
|
if (gaxOpts) {
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
616
|
+
const gax = gaxOpts;
|
|
617
|
+
if (gax.pageSize !== undefined) {
|
|
618
|
+
reqOpts.pageSize ??= gax.pageSize;
|
|
619
|
+
delete gax.pageSize;
|
|
620
|
+
}
|
|
621
|
+
if (gax.pageToken !== undefined) {
|
|
622
|
+
reqOpts.pageToken ??= gax.pageToken;
|
|
623
|
+
delete gax.pageToken;
|
|
624
|
+
}
|
|
591
625
|
}
|
|
592
626
|
return this.request({
|
|
593
627
|
client: 'InstanceAdminClient',
|
|
@@ -597,7 +631,7 @@ class Spanner extends service_1.GrpcService {
|
|
|
597
631
|
headers: this.commonHeaders_,
|
|
598
632
|
}, (err, instanceConfigs, nextPageRequest, ...args) => {
|
|
599
633
|
const nextQuery = nextPageRequest
|
|
600
|
-
?
|
|
634
|
+
? Object.assign({}, options, nextPageRequest)
|
|
601
635
|
: null;
|
|
602
636
|
callback(err, instanceConfigs, nextQuery, ...args);
|
|
603
637
|
});
|
|
@@ -639,18 +673,21 @@ class Spanner extends service_1.GrpcService {
|
|
|
639
673
|
*/
|
|
640
674
|
getInstanceConfigsStream(options = {}) {
|
|
641
675
|
const gaxOpts = extend(true, {}, options.gaxOptions);
|
|
642
|
-
|
|
676
|
+
const reqOpts = Object.assign({}, options, {
|
|
643
677
|
parent: 'projects/' + this.projectId,
|
|
644
678
|
});
|
|
645
679
|
// Copy over pageSize and pageToken values from gaxOptions.
|
|
646
680
|
// However values set on options take precedence.
|
|
647
681
|
if (gaxOpts) {
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
682
|
+
const gax = gaxOpts;
|
|
683
|
+
if (gax.pageSize !== undefined) {
|
|
684
|
+
reqOpts.pageSize ??= gax.pageSize;
|
|
685
|
+
delete gax.pageSize;
|
|
686
|
+
}
|
|
687
|
+
if (gax.pageToken !== undefined) {
|
|
688
|
+
reqOpts.pageToken ??= gax.pageToken;
|
|
689
|
+
delete gax.pageToken;
|
|
690
|
+
}
|
|
654
691
|
}
|
|
655
692
|
delete reqOpts.gaxOptions;
|
|
656
693
|
return this.requestStream({
|
|
@@ -666,10 +703,10 @@ class Spanner extends service_1.GrpcService {
|
|
|
666
703
|
const options = typeof optionsOrCallback === 'object'
|
|
667
704
|
? optionsOrCallback
|
|
668
705
|
: {};
|
|
669
|
-
const reqOpts =
|
|
706
|
+
const reqOpts = Object.assign({}, {
|
|
670
707
|
name: 'projects/' + this.projectId + '/instanceConfigs/' + name,
|
|
671
708
|
});
|
|
672
|
-
const gaxOpts =
|
|
709
|
+
const gaxOpts = Object.assign({}, options.gaxOptions);
|
|
673
710
|
return this.request({
|
|
674
711
|
client: 'InstanceAdminClient',
|
|
675
712
|
method: 'getInstanceConfig',
|
|
@@ -686,19 +723,22 @@ class Spanner extends service_1.GrpcService {
|
|
|
686
723
|
? optionsOrCallback
|
|
687
724
|
: {};
|
|
688
725
|
const gaxOpts = extend(true, {}, options.gaxOptions);
|
|
689
|
-
|
|
726
|
+
const reqOpts = Object.assign({}, options, {
|
|
690
727
|
parent: this.projectFormattedName_,
|
|
691
728
|
});
|
|
692
729
|
delete reqOpts.gaxOptions;
|
|
693
730
|
// Copy over pageSize and pageToken values from gaxOptions.
|
|
694
731
|
// However, values set on options take precedence.
|
|
695
732
|
if (gaxOpts) {
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
733
|
+
const gax = gaxOpts;
|
|
734
|
+
if (gax.pageSize !== undefined) {
|
|
735
|
+
reqOpts.pageSize ??= gax.pageSize;
|
|
736
|
+
delete gax.pageSize;
|
|
737
|
+
}
|
|
738
|
+
if (gax.pageToken !== undefined) {
|
|
739
|
+
reqOpts.pageToken ??= gax.pageToken;
|
|
740
|
+
delete gax.pageToken;
|
|
741
|
+
}
|
|
702
742
|
}
|
|
703
743
|
this.request({
|
|
704
744
|
client: 'InstanceAdminClient',
|
|
@@ -708,7 +748,7 @@ class Spanner extends service_1.GrpcService {
|
|
|
708
748
|
headers: this.commonHeaders_,
|
|
709
749
|
}, (err, operations, nextPageRequest, ...args) => {
|
|
710
750
|
const nextQuery = nextPageRequest
|
|
711
|
-
?
|
|
751
|
+
? Object.assign({}, options, nextPageRequest)
|
|
712
752
|
: null;
|
|
713
753
|
callback(err, operations, nextQuery, ...args);
|
|
714
754
|
});
|
|
@@ -20,7 +20,6 @@ const snakeCase = require("lodash.snakecase");
|
|
|
20
20
|
const common_1 = require("./common");
|
|
21
21
|
const promisify_1 = require("@google-cloud/promisify");
|
|
22
22
|
const google_gax_1 = require("google-gax");
|
|
23
|
-
const extend = require("extend");
|
|
24
23
|
/**
|
|
25
24
|
* The {@link InstanceConfig} class represents a possible configuration for a
|
|
26
25
|
* Cloud Spanner instance.
|
|
@@ -121,7 +120,7 @@ class InstanceConfig extends common.GrpcServiceObject {
|
|
|
121
120
|
}
|
|
122
121
|
setMetadata(config, callback) {
|
|
123
122
|
const reqOpts = {
|
|
124
|
-
instanceConfig:
|
|
123
|
+
instanceConfig: Object.assign({
|
|
125
124
|
name: this.formattedName_,
|
|
126
125
|
}, config.instanceConfig),
|
|
127
126
|
updateMask: {
|
package/build/src/instance.js
CHANGED
|
@@ -203,19 +203,22 @@ class Instance extends common.GrpcServiceObject {
|
|
|
203
203
|
? optionsOrCallback
|
|
204
204
|
: {};
|
|
205
205
|
const gaxOpts = extend(true, {}, options.gaxOptions);
|
|
206
|
-
|
|
206
|
+
const reqOpts = Object.assign({}, options, {
|
|
207
207
|
parent: this.formattedName_,
|
|
208
208
|
});
|
|
209
209
|
delete reqOpts.gaxOptions;
|
|
210
210
|
// Copy over pageSize and pageToken values from gaxOptions.
|
|
211
211
|
// However values set on options take precedence.
|
|
212
212
|
if (gaxOpts) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
213
|
+
const gax = gaxOpts;
|
|
214
|
+
if (gax.pageSize !== undefined) {
|
|
215
|
+
reqOpts.pageSize ??= gax.pageSize;
|
|
216
|
+
delete gax.pageSize;
|
|
217
|
+
}
|
|
218
|
+
if (gax.pageToken !== undefined) {
|
|
219
|
+
reqOpts.pageToken ??= gax.pageToken;
|
|
220
|
+
delete gax.pageToken;
|
|
221
|
+
}
|
|
219
222
|
}
|
|
220
223
|
this.request({
|
|
221
224
|
client: 'DatabaseAdminClient',
|
|
@@ -233,7 +236,7 @@ class Instance extends common.GrpcServiceObject {
|
|
|
233
236
|
});
|
|
234
237
|
}
|
|
235
238
|
const nextQuery = nextPageRequest
|
|
236
|
-
?
|
|
239
|
+
? Object.assign({}, options, nextPageRequest)
|
|
237
240
|
: null;
|
|
238
241
|
callback(err, backupInstances, nextQuery, ...args);
|
|
239
242
|
});
|
|
@@ -279,19 +282,22 @@ class Instance extends common.GrpcServiceObject {
|
|
|
279
282
|
*/
|
|
280
283
|
getBackupsStream(options = {}) {
|
|
281
284
|
const gaxOpts = extend(true, {}, options.gaxOptions);
|
|
282
|
-
|
|
285
|
+
const reqOpts = Object.assign({}, options, {
|
|
283
286
|
parent: this.formattedName_,
|
|
284
287
|
});
|
|
285
288
|
delete reqOpts.gaxOptions;
|
|
286
289
|
// Copy over pageSize and pageToken values from gaxOptions.
|
|
287
290
|
// However values set on options take precedence.
|
|
288
291
|
if (gaxOpts) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
292
|
+
const gax = gaxOpts;
|
|
293
|
+
if (gax.pageSize !== undefined) {
|
|
294
|
+
reqOpts.pageSize ??= gax.pageSize;
|
|
295
|
+
delete gax.pageSize;
|
|
296
|
+
}
|
|
297
|
+
if (gax.pageToken !== undefined) {
|
|
298
|
+
reqOpts.pageToken ??= gax.pageToken;
|
|
299
|
+
delete gax.pageToken;
|
|
300
|
+
}
|
|
295
301
|
}
|
|
296
302
|
return this.requestStream({
|
|
297
303
|
client: 'DatabaseAdminClient',
|
|
@@ -344,19 +350,22 @@ class Instance extends common.GrpcServiceObject {
|
|
|
344
350
|
? optionsOrCallback
|
|
345
351
|
: {};
|
|
346
352
|
const gaxOpts = extend(true, {}, options.gaxOptions);
|
|
347
|
-
|
|
353
|
+
const reqOpts = Object.assign({}, options, {
|
|
348
354
|
parent: this.formattedName_,
|
|
349
355
|
});
|
|
350
356
|
delete reqOpts.gaxOptions;
|
|
351
357
|
// Copy over pageSize and pageToken values from gaxOptions.
|
|
352
358
|
// However values set on options take precedence.
|
|
353
359
|
if (gaxOpts) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
+
const gax = gaxOpts;
|
|
361
|
+
if (gax.pageSize !== undefined) {
|
|
362
|
+
reqOpts.pageSize ??= gax.pageSize;
|
|
363
|
+
delete gax.pageSize;
|
|
364
|
+
}
|
|
365
|
+
if (gax.pageToken !== undefined) {
|
|
366
|
+
reqOpts.pageToken ??= gax.pageToken;
|
|
367
|
+
delete gax.pageToken;
|
|
368
|
+
}
|
|
360
369
|
}
|
|
361
370
|
this.request({
|
|
362
371
|
client: 'DatabaseAdminClient',
|
|
@@ -366,7 +375,7 @@ class Instance extends common.GrpcServiceObject {
|
|
|
366
375
|
headers: this.commonHeaders_,
|
|
367
376
|
}, (err, operations, nextPageRequest, ...args) => {
|
|
368
377
|
const nextQuery = nextPageRequest
|
|
369
|
-
?
|
|
378
|
+
? Object.assign({}, options, nextPageRequest)
|
|
370
379
|
: null;
|
|
371
380
|
callback(err, operations, nextQuery, ...args);
|
|
372
381
|
});
|
|
@@ -415,19 +424,22 @@ class Instance extends common.GrpcServiceObject {
|
|
|
415
424
|
? optionsOrCallback
|
|
416
425
|
: {};
|
|
417
426
|
const gaxOpts = extend(true, {}, options.gaxOptions);
|
|
418
|
-
|
|
427
|
+
const reqOpts = Object.assign({}, options, {
|
|
419
428
|
parent: this.formattedName_,
|
|
420
429
|
});
|
|
421
430
|
delete reqOpts.gaxOptions;
|
|
422
431
|
// Copy over pageSize and pageToken values from gaxOptions.
|
|
423
432
|
// However values set on options take precedence.
|
|
424
433
|
if (gaxOpts) {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
434
|
+
const gax = gaxOpts;
|
|
435
|
+
if (gax.pageSize !== undefined) {
|
|
436
|
+
reqOpts.pageSize ??= gax.pageSize;
|
|
437
|
+
delete gax.pageSize;
|
|
438
|
+
}
|
|
439
|
+
if (gax.pageToken !== undefined) {
|
|
440
|
+
reqOpts.pageToken ??= gax.pageToken;
|
|
441
|
+
delete gax.pageToken;
|
|
442
|
+
}
|
|
431
443
|
}
|
|
432
444
|
this.request({
|
|
433
445
|
client: 'DatabaseAdminClient',
|
|
@@ -437,7 +449,7 @@ class Instance extends common.GrpcServiceObject {
|
|
|
437
449
|
headers: this.commonHeaders_,
|
|
438
450
|
}, (err, operations, nextPageRequest, ...args) => {
|
|
439
451
|
const nextQuery = nextPageRequest
|
|
440
|
-
?
|
|
452
|
+
? Object.assign({}, options, nextPageRequest)
|
|
441
453
|
: null;
|
|
442
454
|
callback(err, operations, nextQuery, ...args);
|
|
443
455
|
});
|
|
@@ -457,7 +469,7 @@ class Instance extends common.GrpcServiceObject {
|
|
|
457
469
|
options.databaseDialect) {
|
|
458
470
|
createStatement = 'CREATE DATABASE "' + name.split('/').pop() + '"';
|
|
459
471
|
}
|
|
460
|
-
const reqOpts =
|
|
472
|
+
const reqOpts = Object.assign({
|
|
461
473
|
parent: this.formattedName_,
|
|
462
474
|
createStatement: createStatement,
|
|
463
475
|
}, options);
|
|
@@ -617,19 +629,22 @@ class Instance extends common.GrpcServiceObject {
|
|
|
617
629
|
? optionsOrCallback
|
|
618
630
|
: {};
|
|
619
631
|
const gaxOpts = extend(true, {}, options.gaxOptions);
|
|
620
|
-
|
|
632
|
+
const reqOpts = Object.assign({}, options, {
|
|
621
633
|
parent: this.formattedName_,
|
|
622
634
|
});
|
|
623
635
|
delete reqOpts.gaxOptions;
|
|
624
636
|
// Copy over pageSize and pageToken values from gaxOptions.
|
|
625
637
|
// However values set on options take precedence.
|
|
626
638
|
if (gaxOpts) {
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
639
|
+
const gax = gaxOpts;
|
|
640
|
+
if (gax.pageSize !== undefined) {
|
|
641
|
+
reqOpts.pageSize ??= gax.pageSize;
|
|
642
|
+
delete gax.pageSize;
|
|
643
|
+
}
|
|
644
|
+
if (gax.pageToken !== undefined) {
|
|
645
|
+
reqOpts.pageToken ??= gax.pageToken;
|
|
646
|
+
delete gax.pageToken;
|
|
647
|
+
}
|
|
633
648
|
}
|
|
634
649
|
this.request({
|
|
635
650
|
client: 'DatabaseAdminClient',
|
|
@@ -648,7 +663,7 @@ class Instance extends common.GrpcServiceObject {
|
|
|
648
663
|
});
|
|
649
664
|
}
|
|
650
665
|
const nextQuery = nextPageRequest
|
|
651
|
-
?
|
|
666
|
+
? Object.assign({}, options, nextPageRequest)
|
|
652
667
|
: null;
|
|
653
668
|
callback(err, databases, nextQuery, ...args);
|
|
654
669
|
});
|
|
@@ -694,19 +709,22 @@ class Instance extends common.GrpcServiceObject {
|
|
|
694
709
|
*/
|
|
695
710
|
getDatabasesStream(options = {}) {
|
|
696
711
|
const gaxOpts = extend(true, {}, options.gaxOptions);
|
|
697
|
-
|
|
712
|
+
const reqOpts = Object.assign({}, options, {
|
|
698
713
|
parent: this.formattedName_,
|
|
699
714
|
});
|
|
700
715
|
delete reqOpts.gaxOptions;
|
|
701
716
|
// Copy over pageSize and pageToken values from gaxOptions.
|
|
702
717
|
// However values set on options take precedence.
|
|
703
718
|
if (gaxOpts) {
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
719
|
+
const gax = gaxOpts;
|
|
720
|
+
if (gax.pageSize !== undefined) {
|
|
721
|
+
reqOpts.pageSize ??= gax.pageSize;
|
|
722
|
+
delete gax.pageSize;
|
|
723
|
+
}
|
|
724
|
+
if (gax.pageToken !== undefined) {
|
|
725
|
+
reqOpts.pageToken ??= gax.pageToken;
|
|
726
|
+
delete gax.pageToken;
|
|
727
|
+
}
|
|
710
728
|
}
|
|
711
729
|
return this.requestStream({
|
|
712
730
|
client: 'DatabaseAdminClient',
|
|
@@ -744,7 +762,7 @@ class Instance extends common.GrpcServiceObject {
|
|
|
744
762
|
const gaxOpts = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
|
|
745
763
|
const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
|
|
746
764
|
const reqOpts = {
|
|
747
|
-
instance:
|
|
765
|
+
instance: Object.assign({
|
|
748
766
|
name: this.formattedName_,
|
|
749
767
|
}, metadata),
|
|
750
768
|
fieldMask: {
|
package/build/src/session.js
CHANGED
|
@@ -22,7 +22,6 @@ exports.Session = void 0;
|
|
|
22
22
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
23
23
|
const common = require('./common-grpc/service-object');
|
|
24
24
|
const promisify_1 = require("@google-cloud/promisify");
|
|
25
|
-
const extend = require("extend");
|
|
26
25
|
const transaction_1 = require("./transaction");
|
|
27
26
|
const common_1 = require("./common");
|
|
28
27
|
const request_id_header_1 = require("./request_id_header");
|
|
@@ -200,7 +199,7 @@ class Session extends common.GrpcServiceObject {
|
|
|
200
199
|
callback(err, null, apiResponse);
|
|
201
200
|
return;
|
|
202
201
|
}
|
|
203
|
-
|
|
202
|
+
Object.assign(this, session);
|
|
204
203
|
callback(null, this, apiResponse);
|
|
205
204
|
});
|
|
206
205
|
},
|
|
@@ -237,6 +237,9 @@ export declare class Snapshot extends EventEmitter {
|
|
|
237
237
|
protected _useInRunner: boolean;
|
|
238
238
|
protected _latestPreCommitToken: spannerClient.spanner.v1.IMultiplexedSessionPrecommitToken | undefined | null;
|
|
239
239
|
id?: Uint8Array | string;
|
|
240
|
+
protected _affinityKey?: string;
|
|
241
|
+
protected _bindGaxOpts?: CallOptions;
|
|
242
|
+
protected _unbindGaxOpts?: CallOptions;
|
|
240
243
|
multiplexedSessionPreviousTransactionId?: Uint8Array | string;
|
|
241
244
|
ended: boolean;
|
|
242
245
|
metadata?: spannerClient.spanner.v1.ITransaction;
|
package/build/src/transaction.js
CHANGED
|
@@ -33,6 +33,20 @@ const instrument_1 = require("./instrument");
|
|
|
33
33
|
const request_id_header_1 = require("./request_id_header");
|
|
34
34
|
const RETRY_INFO_TYPE = 'type.googleapis.com/google.rpc.retryinfo';
|
|
35
35
|
const RETRY_INFO_BIN = 'google.rpc.retryinfo-bin';
|
|
36
|
+
let nextAffinityId = 0;
|
|
37
|
+
/**
|
|
38
|
+
* Injects a key-value pair into the gaxOpts.otherArgs.options object
|
|
39
|
+
* without mutating the original.
|
|
40
|
+
*/
|
|
41
|
+
function injectGaxOpt(existingOpts, key, value) {
|
|
42
|
+
return Object.assign({}, existingOpts, {
|
|
43
|
+
otherArgs: Object.assign({}, existingOpts?.otherArgs, {
|
|
44
|
+
options: Object.assign({}, existingOpts?.otherArgs?.options, {
|
|
45
|
+
[key]: value,
|
|
46
|
+
}),
|
|
47
|
+
}),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
36
50
|
/**
|
|
37
51
|
* @typedef {object} TimestampBounds
|
|
38
52
|
* @property {boolean} [strong=true] Read at a timestamp where all previously
|
|
@@ -95,6 +109,9 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
95
109
|
_useInRunner = false;
|
|
96
110
|
_latestPreCommitToken;
|
|
97
111
|
id;
|
|
112
|
+
_affinityKey;
|
|
113
|
+
_bindGaxOpts;
|
|
114
|
+
_unbindGaxOpts;
|
|
98
115
|
multiplexedSessionPreviousTransactionId;
|
|
99
116
|
ended;
|
|
100
117
|
metadata;
|
|
@@ -158,8 +175,57 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
158
175
|
this.ended = false;
|
|
159
176
|
this.session = session;
|
|
160
177
|
this.queryOptions = Object.assign({}, queryOptions);
|
|
161
|
-
|
|
162
|
-
|
|
178
|
+
// If the session is multiplexed, generate a unique affinity key for this
|
|
179
|
+
// specific transaction/snapshot. This allows requests using the same shared
|
|
180
|
+
// multiplexed session to be distributed across different gRPC channels.
|
|
181
|
+
if (session.metadata && session.metadata.multiplexed) {
|
|
182
|
+
this._affinityKey = `mux-affinity-${process.pid}-${nextAffinityId++}`;
|
|
183
|
+
// Pre-construct and cache the bind gax options to avoid creating
|
|
184
|
+
// a new object on every request, which improves performance.
|
|
185
|
+
this._bindGaxOpts = {
|
|
186
|
+
otherArgs: {
|
|
187
|
+
options: {
|
|
188
|
+
affinityKey: this._affinityKey,
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
// Pre-construct and cache the unbind gax options. This explicitly signals
|
|
193
|
+
// the channel factory to release the affinity mapping when the transaction ends.
|
|
194
|
+
this._unbindGaxOpts = {
|
|
195
|
+
otherArgs: {
|
|
196
|
+
options: {
|
|
197
|
+
affinityKey: this._affinityKey,
|
|
198
|
+
unbind: true,
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
this.request = (config, callback) => {
|
|
203
|
+
let gaxOpts;
|
|
204
|
+
if (!config.gaxOpts || Object.keys(config.gaxOpts).length === 0) {
|
|
205
|
+
gaxOpts = this._bindGaxOpts;
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
gaxOpts = injectGaxOpt(config.gaxOpts, 'affinityKey', this._affinityKey);
|
|
209
|
+
}
|
|
210
|
+
config = Object.assign({}, config, { gaxOpts });
|
|
211
|
+
return session.request(config, callback);
|
|
212
|
+
};
|
|
213
|
+
this.requestStream = (config) => {
|
|
214
|
+
let gaxOpts;
|
|
215
|
+
if (!config.gaxOpts || Object.keys(config.gaxOpts).length === 0) {
|
|
216
|
+
gaxOpts = this._bindGaxOpts;
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
gaxOpts = injectGaxOpt(config.gaxOpts, 'affinityKey', this._affinityKey);
|
|
220
|
+
}
|
|
221
|
+
config = Object.assign({}, config, { gaxOpts });
|
|
222
|
+
return session.requestStream(config);
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
this.request = session.request.bind(session);
|
|
227
|
+
this.requestStream = session.requestStream.bind(session);
|
|
228
|
+
}
|
|
163
229
|
const readOnly = Snapshot.encodeTimestampBounds(options || {});
|
|
164
230
|
this._options = { readOnly };
|
|
165
231
|
this._dbName = this.session.parent.formattedName_;
|
|
@@ -680,6 +746,18 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
680
746
|
}
|
|
681
747
|
this.ended = true;
|
|
682
748
|
process.nextTick(() => this.emit('end'));
|
|
749
|
+
if (this._affinityKey) {
|
|
750
|
+
const database = this.session?.parent;
|
|
751
|
+
const spanner = database?.parent?.parent;
|
|
752
|
+
const client = spanner?.clients_?.get('SpannerClient');
|
|
753
|
+
if (client?.spannerStub) {
|
|
754
|
+
Promise.resolve(client.spannerStub)
|
|
755
|
+
.then((stub) => {
|
|
756
|
+
stub?.getChannel?.()?.unbind?.(this._affinityKey);
|
|
757
|
+
})
|
|
758
|
+
.catch(() => { });
|
|
759
|
+
}
|
|
760
|
+
}
|
|
683
761
|
}
|
|
684
762
|
read(table, requestOrCallback, cb) {
|
|
685
763
|
const rows = [];
|
|
@@ -1449,7 +1527,7 @@ class Transaction extends Dml {
|
|
|
1449
1527
|
commit(optionsOrCallback, cb) {
|
|
1450
1528
|
const options = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
|
|
1451
1529
|
const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
|
|
1452
|
-
|
|
1530
|
+
let gaxOpts = 'gaxOptions' in options ? options.gaxOptions : options;
|
|
1453
1531
|
const mutations = this._queuedMutations;
|
|
1454
1532
|
const session = this.session.formattedName_;
|
|
1455
1533
|
const precommitToken = this._latestPreCommitToken;
|
|
@@ -1504,11 +1582,19 @@ class Transaction extends Dml {
|
|
|
1504
1582
|
}
|
|
1505
1583
|
span.addEvent('Starting Commit');
|
|
1506
1584
|
const database = this.session.parent;
|
|
1585
|
+
if (this._affinityKey) {
|
|
1586
|
+
if (!gaxOpts || Object.keys(gaxOpts).length === 0) {
|
|
1587
|
+
gaxOpts = this._unbindGaxOpts;
|
|
1588
|
+
}
|
|
1589
|
+
else {
|
|
1590
|
+
gaxOpts = injectGaxOpt(gaxOpts, 'unbind', true);
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1507
1593
|
this.request({
|
|
1508
1594
|
client: 'SpannerClient',
|
|
1509
1595
|
method: 'commit',
|
|
1510
1596
|
reqOpts,
|
|
1511
|
-
gaxOpts
|
|
1597
|
+
gaxOpts,
|
|
1512
1598
|
headers: (0, request_id_header_1.injectRequestIDIntoHeaders)(headers, this.session, (0, request_id_header_1.nextNthRequest)(database), 1),
|
|
1513
1599
|
}, (err, resp) => {
|
|
1514
1600
|
if (resp &&
|
|
@@ -1758,7 +1844,7 @@ class Transaction extends Dml {
|
|
|
1758
1844
|
this._mutate('replace', table, rows);
|
|
1759
1845
|
}
|
|
1760
1846
|
rollback(gaxOptionsOrCallback, cb) {
|
|
1761
|
-
|
|
1847
|
+
let gaxOpts = typeof gaxOptionsOrCallback === 'object' ? gaxOptionsOrCallback : {};
|
|
1762
1848
|
const callback = typeof gaxOptionsOrCallback === 'function' ? gaxOptionsOrCallback : cb;
|
|
1763
1849
|
return (0, instrument_1.startTrace)('Transaction.rollback', this._traceConfig, span => {
|
|
1764
1850
|
if (!this.id) {
|
|
@@ -1777,6 +1863,14 @@ class Transaction extends Dml {
|
|
|
1777
1863
|
if (this._getSpanner().routeToLeaderEnabled) {
|
|
1778
1864
|
(0, common_1.addLeaderAwareRoutingHeader)(headers);
|
|
1779
1865
|
}
|
|
1866
|
+
if (this._affinityKey) {
|
|
1867
|
+
if (!gaxOpts || Object.keys(gaxOpts).length === 0) {
|
|
1868
|
+
gaxOpts = this._unbindGaxOpts;
|
|
1869
|
+
}
|
|
1870
|
+
else {
|
|
1871
|
+
gaxOpts = injectGaxOpt(gaxOpts, 'unbind', true);
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1780
1874
|
this.request({
|
|
1781
1875
|
client: 'SpannerClient',
|
|
1782
1876
|
method: 'rollback',
|