@google-cloud/spanner 7.18.1 → 7.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/README.md +1 -0
- package/build/protos/google/spanner/admin/database/v1/backup.proto +16 -0
- package/build/protos/google/spanner/admin/database/v1/spanner_database_admin.proto +70 -0
- package/build/protos/google/spanner/v1/transaction.proto +48 -1
- package/build/protos/protos.d.ts +552 -0
- package/build/protos/protos.js +1300 -1
- package/build/protos/protos.json +122 -2
- package/build/src/database.js +14 -9
- package/build/src/multiplexed-session.d.ts +0 -1
- package/build/src/multiplexed-session.js +0 -3
- package/build/src/request_id_header.d.ts +41 -0
- package/build/src/request_id_header.js +138 -0
- package/build/src/session-factory.d.ts +15 -0
- package/build/src/session-factory.js +18 -5
- package/build/src/session-pool.js +18 -7
- package/build/src/transaction.d.ts +3 -0
- package/build/src/transaction.js +6 -6
- package/build/src/v1/database_admin_client.d.ts +40 -9
- package/build/src/v1/database_admin_client.js +87 -9
- package/build/src/v1/database_admin_client_config.json +5 -0
- package/build/src/v1/instance_admin_client.d.ts +5 -5
- package/build/src/v1/instance_admin_client.js +5 -5
- package/build/src/v1/spanner_client.d.ts +1 -1
- package/build/src/v1/spanner_client.js +2 -2
- package/build/src/v1/spanner_executor_proxy_client.js +1 -1
- package/package.json +2 -2
package/build/protos/protos.json
CHANGED
|
@@ -1624,8 +1624,8 @@
|
|
|
1624
1624
|
"java_package": "com.google.spanner.admin.database.v1",
|
|
1625
1625
|
"php_namespace": "Google\\Cloud\\Spanner\\Admin\\Database\\V1",
|
|
1626
1626
|
"ruby_package": "Google::Cloud::Spanner::Admin::Database::V1",
|
|
1627
|
-
"(google.api.resource_definition).type": "spanner.googleapis.com/
|
|
1628
|
-
"(google.api.resource_definition).pattern": "projects/{project}/instances/{instance}"
|
|
1627
|
+
"(google.api.resource_definition).type": "spanner.googleapis.com/InstancePartition",
|
|
1628
|
+
"(google.api.resource_definition).pattern": "projects/{project}/instances/{instance}/instancePartitions/{instance_partition}"
|
|
1629
1629
|
},
|
|
1630
1630
|
"nested": {
|
|
1631
1631
|
"Backup": {
|
|
@@ -1757,6 +1757,14 @@
|
|
|
1757
1757
|
"options": {
|
|
1758
1758
|
"(google.api.field_behavior)": "OUTPUT_ONLY"
|
|
1759
1759
|
}
|
|
1760
|
+
},
|
|
1761
|
+
"instancePartitions": {
|
|
1762
|
+
"rule": "repeated",
|
|
1763
|
+
"type": "BackupInstancePartition",
|
|
1764
|
+
"id": 19,
|
|
1765
|
+
"options": {
|
|
1766
|
+
"(google.api.field_behavior)": "OUTPUT_ONLY"
|
|
1767
|
+
}
|
|
1760
1768
|
}
|
|
1761
1769
|
},
|
|
1762
1770
|
"nested": {
|
|
@@ -2119,6 +2127,17 @@
|
|
|
2119
2127
|
"IncrementalBackupSpec": {
|
|
2120
2128
|
"fields": {}
|
|
2121
2129
|
},
|
|
2130
|
+
"BackupInstancePartition": {
|
|
2131
|
+
"fields": {
|
|
2132
|
+
"instancePartition": {
|
|
2133
|
+
"type": "string",
|
|
2134
|
+
"id": 1,
|
|
2135
|
+
"options": {
|
|
2136
|
+
"(google.api.resource_reference).type": "spanner.googleapis.com/InstancePartition"
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
},
|
|
2122
2141
|
"OperationProgress": {
|
|
2123
2142
|
"fields": {
|
|
2124
2143
|
"progressPercent": {
|
|
@@ -2878,6 +2897,26 @@
|
|
|
2878
2897
|
}
|
|
2879
2898
|
]
|
|
2880
2899
|
},
|
|
2900
|
+
"AddSplitPoints": {
|
|
2901
|
+
"requestType": "AddSplitPointsRequest",
|
|
2902
|
+
"responseType": "AddSplitPointsResponse",
|
|
2903
|
+
"options": {
|
|
2904
|
+
"(google.api.http).post": "/v1/{database=projects/*/instances/*/databases/*}:addSplitPoints",
|
|
2905
|
+
"(google.api.http).body": "*",
|
|
2906
|
+
"(google.api.method_signature)": "database,split_points"
|
|
2907
|
+
},
|
|
2908
|
+
"parsedOptions": [
|
|
2909
|
+
{
|
|
2910
|
+
"(google.api.http)": {
|
|
2911
|
+
"post": "/v1/{database=projects/*/instances/*/databases/*}:addSplitPoints",
|
|
2912
|
+
"body": "*"
|
|
2913
|
+
}
|
|
2914
|
+
},
|
|
2915
|
+
{
|
|
2916
|
+
"(google.api.method_signature)": "database,split_points"
|
|
2917
|
+
}
|
|
2918
|
+
]
|
|
2919
|
+
},
|
|
2881
2920
|
"CreateBackupSchedule": {
|
|
2882
2921
|
"requestType": "CreateBackupScheduleRequest",
|
|
2883
2922
|
"responseType": "BackupSchedule",
|
|
@@ -3575,6 +3614,76 @@
|
|
|
3575
3614
|
"id": 2
|
|
3576
3615
|
}
|
|
3577
3616
|
}
|
|
3617
|
+
},
|
|
3618
|
+
"AddSplitPointsRequest": {
|
|
3619
|
+
"fields": {
|
|
3620
|
+
"database": {
|
|
3621
|
+
"type": "string",
|
|
3622
|
+
"id": 1,
|
|
3623
|
+
"options": {
|
|
3624
|
+
"(google.api.field_behavior)": "REQUIRED",
|
|
3625
|
+
"(google.api.resource_reference).type": "spanner.googleapis.com/Database"
|
|
3626
|
+
}
|
|
3627
|
+
},
|
|
3628
|
+
"splitPoints": {
|
|
3629
|
+
"rule": "repeated",
|
|
3630
|
+
"type": "SplitPoints",
|
|
3631
|
+
"id": 2,
|
|
3632
|
+
"options": {
|
|
3633
|
+
"(google.api.field_behavior)": "REQUIRED"
|
|
3634
|
+
}
|
|
3635
|
+
},
|
|
3636
|
+
"initiator": {
|
|
3637
|
+
"type": "string",
|
|
3638
|
+
"id": 3,
|
|
3639
|
+
"options": {
|
|
3640
|
+
"(google.api.field_behavior)": "OPTIONAL"
|
|
3641
|
+
}
|
|
3642
|
+
}
|
|
3643
|
+
}
|
|
3644
|
+
},
|
|
3645
|
+
"AddSplitPointsResponse": {
|
|
3646
|
+
"fields": {}
|
|
3647
|
+
},
|
|
3648
|
+
"SplitPoints": {
|
|
3649
|
+
"fields": {
|
|
3650
|
+
"table": {
|
|
3651
|
+
"type": "string",
|
|
3652
|
+
"id": 1
|
|
3653
|
+
},
|
|
3654
|
+
"index": {
|
|
3655
|
+
"type": "string",
|
|
3656
|
+
"id": 2
|
|
3657
|
+
},
|
|
3658
|
+
"keys": {
|
|
3659
|
+
"rule": "repeated",
|
|
3660
|
+
"type": "Key",
|
|
3661
|
+
"id": 3,
|
|
3662
|
+
"options": {
|
|
3663
|
+
"(google.api.field_behavior)": "REQUIRED"
|
|
3664
|
+
}
|
|
3665
|
+
},
|
|
3666
|
+
"expireTime": {
|
|
3667
|
+
"type": "google.protobuf.Timestamp",
|
|
3668
|
+
"id": 5,
|
|
3669
|
+
"options": {
|
|
3670
|
+
"(google.api.field_behavior)": "OPTIONAL"
|
|
3671
|
+
}
|
|
3672
|
+
}
|
|
3673
|
+
},
|
|
3674
|
+
"nested": {
|
|
3675
|
+
"Key": {
|
|
3676
|
+
"fields": {
|
|
3677
|
+
"keyParts": {
|
|
3678
|
+
"type": "google.protobuf.ListValue",
|
|
3679
|
+
"id": 1,
|
|
3680
|
+
"options": {
|
|
3681
|
+
"(google.api.field_behavior)": "REQUIRED"
|
|
3682
|
+
}
|
|
3683
|
+
}
|
|
3684
|
+
}
|
|
3685
|
+
}
|
|
3686
|
+
}
|
|
3578
3687
|
}
|
|
3579
3688
|
}
|
|
3580
3689
|
}
|
|
@@ -8706,6 +8815,10 @@
|
|
|
8706
8815
|
"excludeTxnFromChangeStreams": {
|
|
8707
8816
|
"type": "bool",
|
|
8708
8817
|
"id": 5
|
|
8818
|
+
},
|
|
8819
|
+
"isolationLevel": {
|
|
8820
|
+
"type": "IsolationLevel",
|
|
8821
|
+
"id": 6
|
|
8709
8822
|
}
|
|
8710
8823
|
},
|
|
8711
8824
|
"nested": {
|
|
@@ -8774,6 +8887,13 @@
|
|
|
8774
8887
|
"id": 6
|
|
8775
8888
|
}
|
|
8776
8889
|
}
|
|
8890
|
+
},
|
|
8891
|
+
"IsolationLevel": {
|
|
8892
|
+
"values": {
|
|
8893
|
+
"ISOLATION_LEVEL_UNSPECIFIED": 0,
|
|
8894
|
+
"SERIALIZABLE": 1,
|
|
8895
|
+
"REPEATABLE_READ": 2
|
|
8896
|
+
}
|
|
8777
8897
|
}
|
|
8778
8898
|
}
|
|
8779
8899
|
},
|
package/build/src/database.js
CHANGED
|
@@ -350,6 +350,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
350
350
|
}
|
|
351
351
|
const session = this.session(resp.name);
|
|
352
352
|
session.metadata = resp;
|
|
353
|
+
session._observabilityOptions = this._traceConfig.opts;
|
|
353
354
|
span.end();
|
|
354
355
|
callback(null, session, resp);
|
|
355
356
|
});
|
|
@@ -382,7 +383,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
382
383
|
_releaseOnEnd(session, transaction, span) {
|
|
383
384
|
transaction.once('end', () => {
|
|
384
385
|
try {
|
|
385
|
-
this.
|
|
386
|
+
this.sessionFactory_.release(session);
|
|
386
387
|
}
|
|
387
388
|
catch (e) {
|
|
388
389
|
(0, instrument_1.setSpanErrorAndException)(span, e);
|
|
@@ -679,7 +680,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
679
680
|
return;
|
|
680
681
|
}
|
|
681
682
|
return (0, instrument_1.startTrace)('Database.getSnapshot', this._traceConfig, span => {
|
|
682
|
-
this.
|
|
683
|
+
this.sessionFactory_.getSession((err, session) => {
|
|
683
684
|
if (err) {
|
|
684
685
|
(0, instrument_1.setSpanError)(span, err);
|
|
685
686
|
span.end();
|
|
@@ -690,18 +691,19 @@ class Database extends common.GrpcServiceObject {
|
|
|
690
691
|
snapshot.begin(err => {
|
|
691
692
|
if (err) {
|
|
692
693
|
(0, instrument_1.setSpanError)(span, err);
|
|
693
|
-
if ((0, session_pool_1.isSessionNotFoundError)(err)
|
|
694
|
+
if ((0, session_pool_1.isSessionNotFoundError)(err) &&
|
|
695
|
+
!this.sessionFactory_.isMultiplexedEnabled()) {
|
|
694
696
|
span.addEvent('No session available', {
|
|
695
697
|
'session.id': session === null || session === void 0 ? void 0 : session.id,
|
|
696
698
|
});
|
|
697
699
|
session.lastError = err;
|
|
698
|
-
this.
|
|
700
|
+
this.sessionFactory_.release(session);
|
|
699
701
|
span.end();
|
|
700
702
|
this.getSnapshot(options, callback);
|
|
701
703
|
}
|
|
702
704
|
else {
|
|
703
705
|
span.addEvent('Using Session', { 'session.id': session === null || session === void 0 ? void 0 : session.id });
|
|
704
|
-
this.
|
|
706
|
+
this.sessionFactory_.release(session);
|
|
705
707
|
span.end();
|
|
706
708
|
callback(err);
|
|
707
709
|
}
|
|
@@ -1107,7 +1109,7 @@ class Database extends common.GrpcServiceObject {
|
|
|
1107
1109
|
...this._traceConfig,
|
|
1108
1110
|
};
|
|
1109
1111
|
return (0, instrument_1.startTrace)('Database.runStream', traceConfig, span => {
|
|
1110
|
-
this.
|
|
1112
|
+
this.sessionFactory_.getSession((err, session) => {
|
|
1111
1113
|
if (err) {
|
|
1112
1114
|
(0, instrument_1.setSpanError)(span, err);
|
|
1113
1115
|
proxyStream.destroy(err);
|
|
@@ -1127,7 +1129,8 @@ class Database extends common.GrpcServiceObject {
|
|
|
1127
1129
|
.once('error', err => {
|
|
1128
1130
|
(0, instrument_1.setSpanError)(span, err);
|
|
1129
1131
|
if (!dataReceived &&
|
|
1130
|
-
(0, session_pool_1.isSessionNotFoundError)(err)
|
|
1132
|
+
(0, session_pool_1.isSessionNotFoundError)(err) &&
|
|
1133
|
+
!this.sessionFactory_.isMultiplexedEnabled()) {
|
|
1131
1134
|
// If it is a 'Session not found' error and we have not yet received
|
|
1132
1135
|
// any data, we can safely retry the query on a new session.
|
|
1133
1136
|
// Register the error on the session so the pool can discard it.
|
|
@@ -1460,8 +1463,10 @@ class Database extends common.GrpcServiceObject {
|
|
|
1460
1463
|
? optionsOrCallback
|
|
1461
1464
|
: {};
|
|
1462
1465
|
return (0, instrument_1.startTrace)('Database.writeAtLeastOnce', this._traceConfig, span => {
|
|
1463
|
-
this.
|
|
1464
|
-
if (err &&
|
|
1466
|
+
this.sessionFactory_.getSession((err, session, transaction) => {
|
|
1467
|
+
if (err &&
|
|
1468
|
+
(0, session_pool_1.isSessionNotFoundError)(err) &&
|
|
1469
|
+
!this.sessionFactory_.isMultiplexedEnabled()) {
|
|
1465
1470
|
span.addEvent('No session available', {
|
|
1466
1471
|
'session.id': session === null || session === void 0 ? void 0 : session.id,
|
|
1467
1472
|
});
|
|
@@ -57,7 +57,6 @@ export interface MultiplexedSessionInterface extends EventEmitter {
|
|
|
57
57
|
export declare class MultiplexedSession extends EventEmitter implements MultiplexedSessionInterface {
|
|
58
58
|
database: Database;
|
|
59
59
|
refreshRate: number;
|
|
60
|
-
isMultiplexedEnabled: boolean;
|
|
61
60
|
_multiplexedSession: Session | null;
|
|
62
61
|
_refreshHandle: NodeJS.Timer;
|
|
63
62
|
_observabilityOptions?: ObservabilityOptions;
|
|
@@ -37,9 +37,6 @@ class MultiplexedSession extends events_1.EventEmitter {
|
|
|
37
37
|
this.refreshRate = 7;
|
|
38
38
|
this._multiplexedSession = null;
|
|
39
39
|
this._observabilityOptions = database._observabilityOptions;
|
|
40
|
-
process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS === 'true'
|
|
41
|
-
? (this.isMultiplexedEnabled = true)
|
|
42
|
-
: (this.isMultiplexedEnabled = false);
|
|
43
40
|
}
|
|
44
41
|
/**
|
|
45
42
|
* Creates a new multiplexed session and manages its maintenance.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 Google LLC. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import * as grpc from '@grpc/grpc-js';
|
|
17
|
+
declare const randIdForProcess: string;
|
|
18
|
+
declare const X_GOOG_SPANNER_REQUEST_ID_HEADER = "x-goog-spanner-request-id";
|
|
19
|
+
declare class AtomicCounter {
|
|
20
|
+
private readonly backingBuffer;
|
|
21
|
+
constructor(initialValue?: number);
|
|
22
|
+
increment(n?: number): number;
|
|
23
|
+
value(): number;
|
|
24
|
+
toString(): string;
|
|
25
|
+
reset(): void;
|
|
26
|
+
}
|
|
27
|
+
declare function craftRequestId(nthClientId: number, channelId: number, nthRequest: number, attempt: number): string;
|
|
28
|
+
export declare function resetNthClientId(): void;
|
|
29
|
+
declare function nextSpannerClientId(): number;
|
|
30
|
+
declare function newAtomicCounter(n?: number): AtomicCounter;
|
|
31
|
+
declare function injectRequestIDIntoError(config: any, err: Error): void;
|
|
32
|
+
declare function injectRequestIDIntoHeaders(headers: {
|
|
33
|
+
[k: string]: string;
|
|
34
|
+
}, session: any, nthRequest?: number, attempt?: number): {
|
|
35
|
+
[k: string]: string;
|
|
36
|
+
};
|
|
37
|
+
declare function nextNthRequest(database: any): number;
|
|
38
|
+
export interface RequestIDError extends grpc.ServiceError {
|
|
39
|
+
requestID: string;
|
|
40
|
+
}
|
|
41
|
+
export { AtomicCounter, X_GOOG_SPANNER_REQUEST_ID_HEADER, craftRequestId, injectRequestIDIntoError, injectRequestIDIntoHeaders, nextNthRequest, nextSpannerClientId, newAtomicCounter, randIdForProcess, };
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright 2025 Google LLC. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.randIdForProcess = exports.X_GOOG_SPANNER_REQUEST_ID_HEADER = exports.AtomicCounter = void 0;
|
|
19
|
+
exports.resetNthClientId = resetNthClientId;
|
|
20
|
+
exports.craftRequestId = craftRequestId;
|
|
21
|
+
exports.injectRequestIDIntoError = injectRequestIDIntoError;
|
|
22
|
+
exports.injectRequestIDIntoHeaders = injectRequestIDIntoHeaders;
|
|
23
|
+
exports.nextNthRequest = nextNthRequest;
|
|
24
|
+
exports.nextSpannerClientId = nextSpannerClientId;
|
|
25
|
+
exports.newAtomicCounter = newAtomicCounter;
|
|
26
|
+
const crypto_1 = require("crypto");
|
|
27
|
+
const randIdForProcess = (0, crypto_1.randomBytes)(8)
|
|
28
|
+
.readUint32LE(0)
|
|
29
|
+
.toString(16)
|
|
30
|
+
.padStart(8, '0');
|
|
31
|
+
exports.randIdForProcess = randIdForProcess;
|
|
32
|
+
const X_GOOG_SPANNER_REQUEST_ID_HEADER = 'x-goog-spanner-request-id';
|
|
33
|
+
exports.X_GOOG_SPANNER_REQUEST_ID_HEADER = X_GOOG_SPANNER_REQUEST_ID_HEADER;
|
|
34
|
+
class AtomicCounter {
|
|
35
|
+
constructor(initialValue) {
|
|
36
|
+
this.backingBuffer = new Uint32Array(new SharedArrayBuffer(Uint32Array.BYTES_PER_ELEMENT));
|
|
37
|
+
if (initialValue) {
|
|
38
|
+
this.increment(initialValue);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
increment(n) {
|
|
42
|
+
if (!n) {
|
|
43
|
+
n = 1;
|
|
44
|
+
}
|
|
45
|
+
Atomics.add(this.backingBuffer, 0, n);
|
|
46
|
+
return this.value();
|
|
47
|
+
}
|
|
48
|
+
value() {
|
|
49
|
+
return Atomics.load(this.backingBuffer, 0);
|
|
50
|
+
}
|
|
51
|
+
toString() {
|
|
52
|
+
return `${this.value()}`;
|
|
53
|
+
}
|
|
54
|
+
reset() {
|
|
55
|
+
Atomics.store(this.backingBuffer, 0, 0);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.AtomicCounter = AtomicCounter;
|
|
59
|
+
const REQUEST_HEADER_VERSION = 1;
|
|
60
|
+
function craftRequestId(nthClientId, channelId, nthRequest, attempt) {
|
|
61
|
+
return `${REQUEST_HEADER_VERSION}.${randIdForProcess}.${nthClientId}.${channelId}.${nthRequest}.${attempt}`;
|
|
62
|
+
}
|
|
63
|
+
const nthClientId = new AtomicCounter();
|
|
64
|
+
// Only exported for deterministic testing.
|
|
65
|
+
function resetNthClientId() {
|
|
66
|
+
nthClientId.reset();
|
|
67
|
+
}
|
|
68
|
+
/*
|
|
69
|
+
* nextSpannerClientId increments the internal
|
|
70
|
+
* counter for created SpannerClients, for use
|
|
71
|
+
* with x-goog-spanner-request-id.
|
|
72
|
+
*/
|
|
73
|
+
function nextSpannerClientId() {
|
|
74
|
+
nthClientId.increment(1);
|
|
75
|
+
return nthClientId.value();
|
|
76
|
+
}
|
|
77
|
+
function newAtomicCounter(n) {
|
|
78
|
+
return new AtomicCounter(n);
|
|
79
|
+
}
|
|
80
|
+
function extractRequestID(config) {
|
|
81
|
+
if (!config) {
|
|
82
|
+
return '';
|
|
83
|
+
}
|
|
84
|
+
const hdrs = config;
|
|
85
|
+
if (hdrs && hdrs.headers) {
|
|
86
|
+
return hdrs.headers[X_GOOG_SPANNER_REQUEST_ID_HEADER];
|
|
87
|
+
}
|
|
88
|
+
return '';
|
|
89
|
+
}
|
|
90
|
+
function injectRequestIDIntoError(config, err) {
|
|
91
|
+
if (!err) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
// Inject that RequestID into the actual
|
|
95
|
+
// error object regardless of the type.
|
|
96
|
+
const requestID = extractRequestID(config);
|
|
97
|
+
if (requestID) {
|
|
98
|
+
Object.assign(err, { requestID: requestID });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function injectRequestIDIntoHeaders(headers, session, nthRequest, attempt) {
|
|
102
|
+
if (!session) {
|
|
103
|
+
return headers;
|
|
104
|
+
}
|
|
105
|
+
if (!nthRequest) {
|
|
106
|
+
const database = session.parent;
|
|
107
|
+
if (!(database && typeof database._nextNthRequest === 'function')) {
|
|
108
|
+
return headers;
|
|
109
|
+
}
|
|
110
|
+
nthRequest = database._nextNthRequest();
|
|
111
|
+
}
|
|
112
|
+
attempt = attempt || 1;
|
|
113
|
+
return _metadataWithRequestId(session, nthRequest, attempt, headers);
|
|
114
|
+
}
|
|
115
|
+
function _metadataWithRequestId(session, nthRequest, attempt, priorMetadata) {
|
|
116
|
+
if (!priorMetadata) {
|
|
117
|
+
priorMetadata = {};
|
|
118
|
+
}
|
|
119
|
+
const withReqId = {
|
|
120
|
+
...priorMetadata,
|
|
121
|
+
};
|
|
122
|
+
const database = session.parent;
|
|
123
|
+
let clientId = 1;
|
|
124
|
+
let channelId = 1;
|
|
125
|
+
if (database) {
|
|
126
|
+
clientId = database._nthClientId || 1;
|
|
127
|
+
channelId = database._channelId || 1;
|
|
128
|
+
}
|
|
129
|
+
withReqId[X_GOOG_SPANNER_REQUEST_ID_HEADER] = craftRequestId(clientId, channelId, nthRequest, attempt);
|
|
130
|
+
return withReqId;
|
|
131
|
+
}
|
|
132
|
+
function nextNthRequest(database) {
|
|
133
|
+
if (!(database && typeof database._nextNthRequest === 'function')) {
|
|
134
|
+
return 1;
|
|
135
|
+
}
|
|
136
|
+
return database._nextNthRequest();
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=request_id_header.js.map
|
|
@@ -53,6 +53,12 @@ export interface SessionFactoryInterface {
|
|
|
53
53
|
* @param {Session} session The session to be released.
|
|
54
54
|
*/
|
|
55
55
|
release(session: Session): void;
|
|
56
|
+
/**
|
|
57
|
+
* When called returns if the multiplexed is enabled or not.
|
|
58
|
+
*
|
|
59
|
+
* @name SessionFactoryInterface#isMultiplexedEnabled
|
|
60
|
+
*/
|
|
61
|
+
isMultiplexedEnabled(): boolean;
|
|
56
62
|
}
|
|
57
63
|
/**
|
|
58
64
|
* Creates a SessionFactory object to manage the creation of
|
|
@@ -68,6 +74,7 @@ export interface SessionFactoryInterface {
|
|
|
68
74
|
export declare class SessionFactory extends common.GrpcServiceObject implements SessionFactoryInterface {
|
|
69
75
|
multiplexedSession_: MultiplexedSessionInterface;
|
|
70
76
|
pool_: SessionPoolInterface;
|
|
77
|
+
isMultiplexed: boolean;
|
|
71
78
|
constructor(database: Database, name: String, poolOptions?: SessionPoolConstructor | SessionPoolOptions);
|
|
72
79
|
/**
|
|
73
80
|
* Retrieves a session, either a regular session or a multiplexed session, based on the environment variable configuration.
|
|
@@ -96,5 +103,13 @@ export declare class SessionFactory extends common.GrpcServiceObject implements
|
|
|
96
103
|
* @throws {Error} If the session is invalid or cannot be released.
|
|
97
104
|
*/
|
|
98
105
|
release(session: Session): void;
|
|
106
|
+
/**
|
|
107
|
+
* Returns if a multiplexed is enabled or not.
|
|
108
|
+
*
|
|
109
|
+
* This method returns true if multiplexed session is enabled, otherwise returns false
|
|
110
|
+
*
|
|
111
|
+
* @returns {boolean}
|
|
112
|
+
*/
|
|
113
|
+
isMultiplexedEnabled(): boolean;
|
|
99
114
|
}
|
|
100
115
|
export {};
|
|
@@ -43,8 +43,12 @@ class SessionFactory extends common.GrpcServiceObject {
|
|
|
43
43
|
this.pool_.on('error', this.emit.bind(database, 'error'));
|
|
44
44
|
this.pool_.open();
|
|
45
45
|
this.multiplexedSession_ = new multiplexed_session_1.MultiplexedSession(database);
|
|
46
|
+
// set the isMultiplexed property to true if multiplexed session is enabled, otherwise set the property to false
|
|
47
|
+
process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS === 'true'
|
|
48
|
+
? (this.isMultiplexed = true)
|
|
49
|
+
: (this.isMultiplexed = false);
|
|
46
50
|
// Multiplexed sessions should only be created if its enabled.
|
|
47
|
-
if (this.
|
|
51
|
+
if (this.isMultiplexed) {
|
|
48
52
|
this.multiplexedSession_.on('error', this.emit.bind(database, 'error'));
|
|
49
53
|
this.multiplexedSession_.createSession();
|
|
50
54
|
}
|
|
@@ -58,11 +62,10 @@ class SessionFactory extends common.GrpcServiceObject {
|
|
|
58
62
|
* @param {GetSessionCallback} callback The callback function.
|
|
59
63
|
*/
|
|
60
64
|
getSession(callback) {
|
|
61
|
-
const sessionHandler = this.
|
|
62
|
-
.isMultiplexedEnabled
|
|
65
|
+
const sessionHandler = this.isMultiplexed
|
|
63
66
|
? this.multiplexedSession_
|
|
64
67
|
: this.pool_;
|
|
65
|
-
sessionHandler.getSession((err, session) => callback(err, session));
|
|
68
|
+
sessionHandler.getSession((err, session, transaction) => callback(err, session, transaction));
|
|
66
69
|
}
|
|
67
70
|
/**
|
|
68
71
|
* Returns the regular session pool object.
|
|
@@ -84,10 +87,20 @@ class SessionFactory extends common.GrpcServiceObject {
|
|
|
84
87
|
* @throws {Error} If the session is invalid or cannot be released.
|
|
85
88
|
*/
|
|
86
89
|
release(session) {
|
|
87
|
-
if (!this.
|
|
90
|
+
if (!this.isMultiplexed) {
|
|
88
91
|
this.pool_.release(session);
|
|
89
92
|
}
|
|
90
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Returns if a multiplexed is enabled or not.
|
|
96
|
+
*
|
|
97
|
+
* This method returns true if multiplexed session is enabled, otherwise returns false
|
|
98
|
+
*
|
|
99
|
+
* @returns {boolean}
|
|
100
|
+
*/
|
|
101
|
+
isMultiplexedEnabled() {
|
|
102
|
+
return this.isMultiplexed;
|
|
103
|
+
}
|
|
91
104
|
}
|
|
92
105
|
exports.SessionFactory = SessionFactory;
|
|
93
106
|
//# sourceMappingURL=session-factory.js.map
|
|
@@ -521,12 +521,7 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
521
521
|
if (needed <= 0) {
|
|
522
522
|
return;
|
|
523
523
|
}
|
|
524
|
-
|
|
525
|
-
await this._createSessions(needed);
|
|
526
|
-
}
|
|
527
|
-
catch (e) {
|
|
528
|
-
this.emit('error', e);
|
|
529
|
-
}
|
|
524
|
+
await this._createSessions(needed);
|
|
530
525
|
}
|
|
531
526
|
/**
|
|
532
527
|
* Retrieves a list of all the idle sessions.
|
|
@@ -691,7 +686,23 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
691
686
|
const sessions = this._getIdleSessions();
|
|
692
687
|
const pings = sessions.map(session => this._ping(session));
|
|
693
688
|
await Promise.all(pings);
|
|
694
|
-
|
|
689
|
+
try {
|
|
690
|
+
await this._fill();
|
|
691
|
+
}
|
|
692
|
+
catch (error) {
|
|
693
|
+
// Ignore `Database not found` error. This allows a user to call instance.database('db-name')
|
|
694
|
+
// for a database that does not yet exist with SessionPoolOptions.min > 0.
|
|
695
|
+
const err = error;
|
|
696
|
+
if ((0, helper_1.isDatabaseNotFoundError)(err) ||
|
|
697
|
+
(0, helper_1.isInstanceNotFoundError)(err) ||
|
|
698
|
+
(0, helper_1.isCreateSessionPermissionError)(err) ||
|
|
699
|
+
(0, helper_1.isDefaultCredentialsNotSetError)(err) ||
|
|
700
|
+
(0, helper_1.isProjectIdNotSetInEnvironmentError)(err)) {
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
this.emit('error', err);
|
|
704
|
+
}
|
|
705
|
+
return;
|
|
695
706
|
}
|
|
696
707
|
/**
|
|
697
708
|
* Creates a transaction for a session.
|
|
@@ -101,6 +101,9 @@ export interface Statement {
|
|
|
101
101
|
types?: Type | {
|
|
102
102
|
[param: string]: Value;
|
|
103
103
|
};
|
|
104
|
+
paramTypes?: {
|
|
105
|
+
[k: string]: google.spanner.v1.Type;
|
|
106
|
+
} | null;
|
|
104
107
|
}
|
|
105
108
|
export interface ExecuteSqlRequest extends Statement, RequestOptions {
|
|
106
109
|
resumeToken?: ResumeToken;
|
package/build/src/transaction.js
CHANGED
|
@@ -915,10 +915,11 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
915
915
|
* @returns {object}
|
|
916
916
|
*/
|
|
917
917
|
static encodeParams(request) {
|
|
918
|
+
var _a;
|
|
918
919
|
const typeMap = request.types || {};
|
|
919
|
-
const params = {};
|
|
920
|
-
const paramTypes = {};
|
|
921
|
-
if (request.params) {
|
|
920
|
+
const params = { fields: ((_a = request.params) === null || _a === void 0 ? void 0 : _a.fields) || {} };
|
|
921
|
+
const paramTypes = request.paramTypes || {};
|
|
922
|
+
if (request.params && !request.params.fields) {
|
|
922
923
|
const fields = {};
|
|
923
924
|
Object.keys(request.params).forEach(param => {
|
|
924
925
|
const value = request.params[param];
|
|
@@ -1572,10 +1573,9 @@ class Transaction extends Dml {
|
|
|
1572
1573
|
};
|
|
1573
1574
|
return (0, instrument_2.startTrace)('Transaction.rollback', traceConfig, span => {
|
|
1574
1575
|
if (!this.id) {
|
|
1575
|
-
|
|
1576
|
-
(0, instrument_2.setSpanError)(span, err);
|
|
1576
|
+
span.addEvent('Transaction ID is unknown, nothing to rollback.');
|
|
1577
1577
|
span.end();
|
|
1578
|
-
callback(
|
|
1578
|
+
callback(null);
|
|
1579
1579
|
return;
|
|
1580
1580
|
}
|
|
1581
1581
|
const session = this.session.formattedName_;
|