@google-cloud/spanner 7.20.0 → 8.0.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 +1 -0
- package/build/protos/google/spanner/admin/database/v1/backup.proto +1 -1
- package/build/protos/google/spanner/admin/database/v1/backup_schedule.proto +1 -1
- package/build/protos/google/spanner/admin/database/v1/common.proto +1 -1
- package/build/protos/google/spanner/admin/database/v1/spanner_database_admin.proto +1 -1
- package/build/protos/google/spanner/admin/instance/v1/common.proto +1 -1
- package/build/protos/google/spanner/admin/instance/v1/spanner_instance_admin.proto +1 -1
- package/build/protos/google/spanner/executor/v1/cloud_executor.proto +1 -1
- package/build/protos/google/spanner/v1/commit_response.proto +1 -1
- package/build/protos/google/spanner/v1/keys.proto +1 -1
- package/build/protos/google/spanner/v1/mutation.proto +1 -1
- package/build/protos/google/spanner/v1/query_plan.proto +1 -1
- package/build/protos/google/spanner/v1/result_set.proto +55 -49
- package/build/protos/google/spanner/v1/spanner.proto +1 -1
- package/build/protos/google/spanner/v1/transaction.proto +1 -1
- package/build/protos/google/spanner/v1/type.proto +1 -1
- package/build/protos/protos.d.ts +56 -50
- package/build/protos/protos.js +1016 -331
- package/build/protos/protos.json +47 -20
- package/build/src/backup.js +7 -0
- package/build/src/batch-transaction.d.ts +48 -29
- package/build/src/batch-transaction.js +13 -98
- package/build/src/codec.js +43 -26
- package/build/src/common-grpc/service-object.js +1 -0
- package/build/src/common-grpc/service.js +25 -8
- package/build/src/database.js +77 -49
- package/build/src/helper.d.ts +9 -0
- package/build/src/helper.js +24 -0
- package/build/src/index.js +24 -13
- package/build/src/instance-config.d.ts +1 -1
- package/build/src/instance-config.js +4 -0
- package/build/src/instance.js +12 -6
- package/build/src/instrument.d.ts +2 -0
- package/build/src/instrument.js +12 -9
- package/build/src/multiplexed-session.js +7 -1
- package/build/src/partial-result-stream.js +9 -5
- package/build/src/request_id_header.js +1 -0
- package/build/src/session-factory.js +5 -2
- package/build/src/session-pool.js +23 -6
- package/build/src/session.d.ts +2 -1
- package/build/src/session.js +8 -2
- package/build/src/table.js +6 -1
- package/build/src/transaction-runner.js +12 -2
- package/build/src/transaction.d.ts +2 -1
- package/build/src/transaction.js +95 -81
- package/build/src/v1/database_admin_client.d.ts +3 -2
- package/build/src/v1/database_admin_client.js +551 -167
- package/build/src/v1/instance_admin_client.d.ts +2 -1
- package/build/src/v1/instance_admin_client.js +453 -133
- package/build/src/v1/spanner_client.d.ts +2 -1
- package/build/src/v1/spanner_client.js +283 -85
- package/build/src/v1/spanner_executor_proxy_client.d.ts +2 -1
- package/build/src/v1/spanner_executor_proxy_client.js +41 -19
- package/package.json +57 -58
package/build/src/index.js
CHANGED
|
@@ -108,6 +108,29 @@ const gcpApiConfig = require('./spanner_grpc_config.json');
|
|
|
108
108
|
* @param {ClientConfig} [options] Configuration options.
|
|
109
109
|
*/
|
|
110
110
|
class Spanner extends service_1.GrpcService {
|
|
111
|
+
options;
|
|
112
|
+
auth;
|
|
113
|
+
clients_;
|
|
114
|
+
instances_;
|
|
115
|
+
instanceConfigs_;
|
|
116
|
+
projectIdReplaced_;
|
|
117
|
+
projectFormattedName_;
|
|
118
|
+
commonHeaders_;
|
|
119
|
+
routeToLeaderEnabled = true;
|
|
120
|
+
directedReadOptions;
|
|
121
|
+
defaultTransactionOptions;
|
|
122
|
+
_observabilityOptions;
|
|
123
|
+
_nthClientId;
|
|
124
|
+
/**
|
|
125
|
+
* Placeholder used to auto populate a column with the commit timestamp.
|
|
126
|
+
* This can only be used for timestamp columns that have set the option
|
|
127
|
+
* "(allow_commit_timestamp=true)" in the schema.
|
|
128
|
+
*
|
|
129
|
+
* @type {string}
|
|
130
|
+
*/
|
|
131
|
+
static COMMIT_TIMESTAMP = 'spanner.commit_timestamp()';
|
|
132
|
+
static POSTGRESQL = protos_1.google.spanner.admin.database.v1.DatabaseDialect.POSTGRESQL;
|
|
133
|
+
static GOOGLE_STANDARD_SQL = protos_1.google.spanner.admin.database.v1.DatabaseDialect.GOOGLE_STANDARD_SQL;
|
|
111
134
|
/**
|
|
112
135
|
* Gets the configured Spanner emulator host from an environment variable.
|
|
113
136
|
*/
|
|
@@ -135,7 +158,6 @@ class Spanner extends service_1.GrpcService {
|
|
|
135
158
|
return undefined;
|
|
136
159
|
}
|
|
137
160
|
constructor(options) {
|
|
138
|
-
var _a;
|
|
139
161
|
const scopes = [];
|
|
140
162
|
const clientClasses = [
|
|
141
163
|
v1.DatabaseAdminClient,
|
|
@@ -196,7 +218,6 @@ class Spanner extends service_1.GrpcService {
|
|
|
196
218
|
packageJson: require('../../package.json'),
|
|
197
219
|
};
|
|
198
220
|
super(config, options);
|
|
199
|
-
this.routeToLeaderEnabled = true;
|
|
200
221
|
if (options.routeToLeaderEnabled === false) {
|
|
201
222
|
this.routeToLeaderEnabled = false;
|
|
202
223
|
}
|
|
@@ -210,7 +231,7 @@ class Spanner extends service_1.GrpcService {
|
|
|
210
231
|
this.directedReadOptions = directedReadOptions;
|
|
211
232
|
this.defaultTransactionOptions = defaultTransactionOptions;
|
|
212
233
|
this._observabilityOptions = options.observabilityOptions;
|
|
213
|
-
this.commonHeaders_ = (0, common_1.getCommonHeaders)(this.projectFormattedName_,
|
|
234
|
+
this.commonHeaders_ = (0, common_1.getCommonHeaders)(this.projectFormattedName_, this._observabilityOptions?.enableEndToEndTracing);
|
|
214
235
|
(0, instrument_1.ensureInitialContextManagerSet)();
|
|
215
236
|
this._nthClientId = (0, request_id_header_1.nextSpannerClientId)();
|
|
216
237
|
}
|
|
@@ -1083,16 +1104,6 @@ class Spanner extends service_1.GrpcService {
|
|
|
1083
1104
|
}
|
|
1084
1105
|
}
|
|
1085
1106
|
exports.Spanner = Spanner;
|
|
1086
|
-
/**
|
|
1087
|
-
* Placeholder used to auto populate a column with the commit timestamp.
|
|
1088
|
-
* This can only be used for timestamp columns that have set the option
|
|
1089
|
-
* "(allow_commit_timestamp=true)" in the schema.
|
|
1090
|
-
*
|
|
1091
|
-
* @type {string}
|
|
1092
|
-
*/
|
|
1093
|
-
Spanner.COMMIT_TIMESTAMP = 'spanner.commit_timestamp()';
|
|
1094
|
-
Spanner.POSTGRESQL = protos_1.google.spanner.admin.database.v1.DatabaseDialect.POSTGRESQL;
|
|
1095
|
-
Spanner.GOOGLE_STANDARD_SQL = protos_1.google.spanner.admin.database.v1.DatabaseDialect.GOOGLE_STANDARD_SQL;
|
|
1096
1107
|
/*! Developer Documentation
|
|
1097
1108
|
*
|
|
1098
1109
|
* All async methods (except for streams) will return a Promise in the event
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
declare const common: any;
|
|
16
16
|
import { google as instanceAdmin } from '../protos/protos';
|
|
17
|
-
import { Operation as GaxOperation } from 'google-gax
|
|
17
|
+
import { Operation as GaxOperation } from 'google-gax';
|
|
18
18
|
import { LongRunningCallback, RequestCallback, ResourceCallback, NormalCallback } from './common';
|
|
19
19
|
import { GetInstanceConfigCallback, GetInstanceConfigOptions, GetInstanceConfigResponse, RequestConfig, Spanner } from './index';
|
|
20
20
|
import { CallOptions } from 'google-gax';
|
|
@@ -41,6 +41,10 @@ const extend = require("extend");
|
|
|
41
41
|
* ```
|
|
42
42
|
*/
|
|
43
43
|
class InstanceConfig extends common.GrpcServiceObject {
|
|
44
|
+
formattedName_;
|
|
45
|
+
request;
|
|
46
|
+
metadata;
|
|
47
|
+
resourceHeader_;
|
|
44
48
|
constructor(spanner, name) {
|
|
45
49
|
const formattedName_ = InstanceConfig.formatName_(spanner.projectId, name);
|
|
46
50
|
const methods = {
|
package/build/src/instance.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.Instance = void 0;
|
|
19
|
-
const
|
|
19
|
+
const helper_1 = require("./helper");
|
|
20
20
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
21
21
|
const common = require('./common-grpc/service-object');
|
|
22
22
|
const promisify_1 = require("@google-cloud/promisify");
|
|
@@ -46,8 +46,14 @@ const protos_1 = require("../protos/protos");
|
|
|
46
46
|
* ```
|
|
47
47
|
*/
|
|
48
48
|
class Instance extends common.GrpcServiceObject {
|
|
49
|
+
formattedName_;
|
|
50
|
+
request;
|
|
51
|
+
requestStream;
|
|
52
|
+
databases_;
|
|
53
|
+
metadata;
|
|
54
|
+
commonHeaders_;
|
|
55
|
+
_observabilityOptions;
|
|
49
56
|
constructor(spanner, name) {
|
|
50
|
-
var _a;
|
|
51
57
|
const formattedName_ = Instance.formatName_(spanner.projectId, name);
|
|
52
58
|
const methods = {
|
|
53
59
|
/**
|
|
@@ -116,7 +122,7 @@ class Instance extends common.GrpcServiceObject {
|
|
|
116
122
|
this.requestStream = spanner.requestStream.bind(spanner);
|
|
117
123
|
this.databases_ = new Map();
|
|
118
124
|
this._observabilityOptions = spanner._observabilityOptions;
|
|
119
|
-
this.commonHeaders_ = (0, common_1.getCommonHeaders)(this.formattedName_,
|
|
125
|
+
this.commonHeaders_ = (0, common_1.getCommonHeaders)(this.formattedName_, this._observabilityOptions?.enableEndToEndTracing);
|
|
120
126
|
}
|
|
121
127
|
/**
|
|
122
128
|
* Get a reference to a Backup object.
|
|
@@ -456,7 +462,7 @@ class Instance extends common.GrpcServiceObject {
|
|
|
456
462
|
delete reqOpts.poolCtor;
|
|
457
463
|
delete reqOpts.gaxOptions;
|
|
458
464
|
if (reqOpts.schema) {
|
|
459
|
-
reqOpts.extraStatements =
|
|
465
|
+
reqOpts.extraStatements = (0, helper_1.toArray)(reqOpts.schema);
|
|
460
466
|
delete reqOpts.schema;
|
|
461
467
|
}
|
|
462
468
|
this.request({
|
|
@@ -529,7 +535,7 @@ class Instance extends common.GrpcServiceObject {
|
|
|
529
535
|
const reqOpts = {
|
|
530
536
|
name: this.formattedName_,
|
|
531
537
|
};
|
|
532
|
-
Promise.all(Array.from(this.databases_.values()).map(database => {
|
|
538
|
+
void Promise.all(Array.from(this.databases_.values()).map(database => {
|
|
533
539
|
return database.close();
|
|
534
540
|
}))
|
|
535
541
|
.catch(() => { })
|
|
@@ -715,7 +721,7 @@ class Instance extends common.GrpcServiceObject {
|
|
|
715
721
|
};
|
|
716
722
|
if (options.fieldNames) {
|
|
717
723
|
reqOpts['fieldMask'] = {
|
|
718
|
-
paths:
|
|
724
|
+
paths: (0, helper_1.toArray)(options['fieldNames']).map(snakeCase),
|
|
719
725
|
};
|
|
720
726
|
}
|
|
721
727
|
return this.request({
|
package/build/src/instrument.js
CHANGED
|
@@ -73,33 +73,36 @@ function ensureInitialContextManagerSet() {
|
|
|
73
73
|
* @returns {Span} The created span.
|
|
74
74
|
*/
|
|
75
75
|
function startTrace(spanNameSuffix, config, cb) {
|
|
76
|
-
var _a;
|
|
77
76
|
if (!config) {
|
|
78
77
|
config = {};
|
|
79
78
|
}
|
|
80
|
-
return getTracer(
|
|
81
|
-
var _a;
|
|
82
|
-
span.setAttribute(semantic_conventions_1.SEMATTRS_DB_SYSTEM, 'spanner');
|
|
79
|
+
return getTracer(config.opts?.tracerProvider).startActiveSpan(SPAN_NAMESPACE_PREFIX + '.' + spanNameSuffix, { kind: api_1.SpanKind.CLIENT }, span => {
|
|
83
80
|
span.setAttribute(semantic_conventions_1.ATTR_OTEL_SCOPE_NAME, TRACER_NAME);
|
|
84
81
|
span.setAttribute(semantic_conventions_1.ATTR_OTEL_SCOPE_VERSION, TRACER_VERSION);
|
|
85
82
|
span.setAttribute('gcp.client.service', 'spanner');
|
|
86
83
|
span.setAttribute('gcp.client.version', TRACER_VERSION);
|
|
87
84
|
span.setAttribute('gcp.client.repo', 'googleapis/nodejs-spanner');
|
|
88
85
|
if (config.tableName) {
|
|
89
|
-
span.setAttribute(
|
|
86
|
+
span.setAttribute('db.sql.table', config.tableName);
|
|
90
87
|
}
|
|
91
88
|
if (config.dbName) {
|
|
92
|
-
span.setAttribute(
|
|
89
|
+
span.setAttribute('db.name', config.dbName);
|
|
93
90
|
}
|
|
94
|
-
|
|
91
|
+
if (config.requestTag) {
|
|
92
|
+
span.setAttribute('request.tag', config.requestTag);
|
|
93
|
+
}
|
|
94
|
+
if (config.transactionTag) {
|
|
95
|
+
span.setAttribute('transaction.tag', config.transactionTag);
|
|
96
|
+
}
|
|
97
|
+
const allowExtendedTracing = optedInPII || config.opts?.enableExtendedTracing;
|
|
95
98
|
if (config.sql && allowExtendedTracing) {
|
|
96
99
|
const sql = config.sql;
|
|
97
100
|
if (typeof sql === 'string') {
|
|
98
|
-
span.setAttribute(
|
|
101
|
+
span.setAttribute('db.statement', sql);
|
|
99
102
|
}
|
|
100
103
|
else {
|
|
101
104
|
const stmt = sql;
|
|
102
|
-
span.setAttribute(
|
|
105
|
+
span.setAttribute('db.statement', stmt.sql);
|
|
103
106
|
}
|
|
104
107
|
}
|
|
105
108
|
// If at all the invoked function throws an exception,
|
|
@@ -30,6 +30,12 @@ exports.MUX_SESSION_CREATE_ERROR = 'mux-session-create-error';
|
|
|
30
30
|
* @extends {EventEmitter}
|
|
31
31
|
*/
|
|
32
32
|
class MultiplexedSession extends events_1.EventEmitter {
|
|
33
|
+
database;
|
|
34
|
+
// frequency to create new mux session
|
|
35
|
+
refreshRate;
|
|
36
|
+
_multiplexedSession;
|
|
37
|
+
_refreshHandle;
|
|
38
|
+
_observabilityOptions;
|
|
33
39
|
constructor(database) {
|
|
34
40
|
super();
|
|
35
41
|
this.database = database;
|
|
@@ -125,7 +131,7 @@ class MultiplexedSession extends events_1.EventEmitter {
|
|
|
125
131
|
*
|
|
126
132
|
*/
|
|
127
133
|
getSession(callback) {
|
|
128
|
-
this._acquire().then(session => callback(null, session, session
|
|
134
|
+
this._acquire().then(session => callback(null, session, session?.txn), callback);
|
|
129
135
|
}
|
|
130
136
|
/**
|
|
131
137
|
* Acquires a session asynchronously, and prepares the transaction for the session.
|
|
@@ -39,9 +39,15 @@ const stream = require("stream");
|
|
|
39
39
|
* @param {RowOptions} [options] The row options.
|
|
40
40
|
*/
|
|
41
41
|
class PartialResultStream extends stream_1.Transform {
|
|
42
|
+
_destroyed;
|
|
43
|
+
_fields;
|
|
44
|
+
_options;
|
|
45
|
+
_pendingValue;
|
|
46
|
+
_pendingValueForResume;
|
|
47
|
+
_values;
|
|
48
|
+
_numPushFailed = 0;
|
|
42
49
|
constructor(options = {}) {
|
|
43
50
|
super({ objectMode: true });
|
|
44
|
-
this._numPushFailed = 0;
|
|
45
51
|
this._destroyed = false;
|
|
46
52
|
this._options = Object.assign({ maxResumeRetries: 20 }, options);
|
|
47
53
|
this._values = [];
|
|
@@ -199,9 +205,8 @@ class PartialResultStream extends stream_1.Transform {
|
|
|
199
205
|
*/
|
|
200
206
|
_createRow(values) {
|
|
201
207
|
const fields = values.map((value, index) => {
|
|
202
|
-
var _a;
|
|
203
208
|
const { name, type } = this._fields[index];
|
|
204
|
-
const columnMetadata =
|
|
209
|
+
const columnMetadata = this._options.columnsMetadata?.[name];
|
|
205
210
|
return {
|
|
206
211
|
name,
|
|
207
212
|
value: codec_1.codec.decode(value, type, columnMetadata),
|
|
@@ -284,13 +289,12 @@ exports.PartialResultStream = PartialResultStream;
|
|
|
284
289
|
* @returns {PartialResultStream}
|
|
285
290
|
*/
|
|
286
291
|
function partialResultStream(requestFn, options) {
|
|
287
|
-
var _a, _b;
|
|
288
292
|
const retryableCodes = [google_gax_1.grpc.status.UNAVAILABLE];
|
|
289
293
|
const maxQueued = 10;
|
|
290
294
|
let lastResumeToken;
|
|
291
295
|
let lastRequestStream;
|
|
292
296
|
const startTime = Date.now();
|
|
293
|
-
const timeout =
|
|
297
|
+
const timeout = options?.gaxOptions?.timeout ?? Infinity;
|
|
294
298
|
// mergeStream allows multiple streams to be connected into one. This is good;
|
|
295
299
|
// if we need to retry a request and pipe more data to the user's stream.
|
|
296
300
|
// We also add an additional stream that can be used to flush any remaining
|
|
@@ -34,6 +34,7 @@ exports.randIdForProcess = randIdForProcess;
|
|
|
34
34
|
const X_GOOG_SPANNER_REQUEST_ID_HEADER = 'x-goog-spanner-request-id';
|
|
35
35
|
exports.X_GOOG_SPANNER_REQUEST_ID_HEADER = X_GOOG_SPANNER_REQUEST_ID_HEADER;
|
|
36
36
|
class AtomicCounter {
|
|
37
|
+
backingBuffer;
|
|
37
38
|
constructor(initialValue) {
|
|
38
39
|
this.backingBuffer = new Uint32Array(new SharedArrayBuffer(Uint32Array.BYTES_PER_ELEMENT));
|
|
39
40
|
if (initialValue) {
|
|
@@ -31,6 +31,10 @@ const common = require('./common-grpc/service-object');
|
|
|
31
31
|
* configuration options or custom pool inteface.
|
|
32
32
|
*/
|
|
33
33
|
class SessionFactory extends common.GrpcServiceObject {
|
|
34
|
+
multiplexedSession_;
|
|
35
|
+
pool_;
|
|
36
|
+
isMultiplexed;
|
|
37
|
+
isMultiplexedPartitionOps;
|
|
34
38
|
constructor(database, name, poolOptions) {
|
|
35
39
|
super({
|
|
36
40
|
parent: database,
|
|
@@ -110,8 +114,7 @@ class SessionFactory extends common.GrpcServiceObject {
|
|
|
110
114
|
* @throws {Error} If the session is invalid or cannot be released.
|
|
111
115
|
*/
|
|
112
116
|
release(session) {
|
|
113
|
-
|
|
114
|
-
if (!((_a = session.metadata) === null || _a === void 0 ? void 0 : _a.multiplexed)) {
|
|
117
|
+
if (!session.metadata?.multiplexed) {
|
|
115
118
|
this.pool_.release(session);
|
|
116
119
|
}
|
|
117
120
|
}
|
|
@@ -43,6 +43,7 @@ const DEFAULTS = {
|
|
|
43
43
|
* @private
|
|
44
44
|
*/
|
|
45
45
|
class ReleaseError extends google_gax_1.GoogleError {
|
|
46
|
+
resource;
|
|
46
47
|
constructor(resource) {
|
|
47
48
|
super('Unable to release unknown resource.');
|
|
48
49
|
this.resource = resource;
|
|
@@ -55,6 +56,7 @@ exports.ReleaseError = ReleaseError;
|
|
|
55
56
|
* @private
|
|
56
57
|
*/
|
|
57
58
|
class SessionLeakError extends google_gax_1.GoogleError {
|
|
59
|
+
messages;
|
|
58
60
|
constructor(leaks) {
|
|
59
61
|
super(`${leaks.length} session leak(s) detected.`);
|
|
60
62
|
// Restore error name that was overwritten by the super constructor call.
|
|
@@ -67,6 +69,7 @@ exports.SessionLeakError = SessionLeakError;
|
|
|
67
69
|
* Error to be thrown when the session pool is exhausted.
|
|
68
70
|
*/
|
|
69
71
|
class SessionPoolExhaustedError extends google_gax_1.GoogleError {
|
|
72
|
+
messages;
|
|
70
73
|
constructor(leaks) {
|
|
71
74
|
super("No resources available." /* errors.Exhausted */);
|
|
72
75
|
// Restore error name that was overwritten by the super constructor call.
|
|
@@ -95,6 +98,19 @@ function isSessionNotFoundError(error) {
|
|
|
95
98
|
* @extends {EventEmitter}
|
|
96
99
|
*/
|
|
97
100
|
class SessionPool extends events_1.EventEmitter {
|
|
101
|
+
database;
|
|
102
|
+
isOpen;
|
|
103
|
+
options;
|
|
104
|
+
_acquires;
|
|
105
|
+
_evictHandle;
|
|
106
|
+
_inventory;
|
|
107
|
+
_onClose;
|
|
108
|
+
_pending = 0;
|
|
109
|
+
_waiters = 0;
|
|
110
|
+
_pingHandle;
|
|
111
|
+
_requests;
|
|
112
|
+
_traces;
|
|
113
|
+
_observabilityOptions;
|
|
98
114
|
/**
|
|
99
115
|
* Formats stack trace objects into Node-like stack trace.
|
|
100
116
|
*
|
|
@@ -186,8 +202,6 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
186
202
|
*/
|
|
187
203
|
constructor(database, options) {
|
|
188
204
|
super();
|
|
189
|
-
this._pending = 0;
|
|
190
|
-
this._waiters = 0;
|
|
191
205
|
if (options && options.min && options.max && options.min > options.max) {
|
|
192
206
|
throw new TypeError('Min sessions may not be greater than max sessions.');
|
|
193
207
|
}
|
|
@@ -227,7 +241,9 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
227
241
|
this._stopHouseKeeping();
|
|
228
242
|
this.emit('close');
|
|
229
243
|
sessions.forEach(session => this._destroy(session));
|
|
230
|
-
this._requests
|
|
244
|
+
this._requests
|
|
245
|
+
.onIdle()
|
|
246
|
+
.then(() => {
|
|
231
247
|
const leaks = this._getLeaks();
|
|
232
248
|
let error;
|
|
233
249
|
this._inventory.sessions = [];
|
|
@@ -236,7 +252,8 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
236
252
|
error = new SessionLeakError(leaks);
|
|
237
253
|
}
|
|
238
254
|
callback(error);
|
|
239
|
-
})
|
|
255
|
+
})
|
|
256
|
+
.catch(err => callback(err));
|
|
240
257
|
}
|
|
241
258
|
/**
|
|
242
259
|
* Retrieve a read session.
|
|
@@ -508,7 +525,7 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
508
525
|
}
|
|
509
526
|
const index = this._inventory.sessions.indexOf(session);
|
|
510
527
|
this._inventory.sessions.splice(index, 1);
|
|
511
|
-
this._destroy(session);
|
|
528
|
+
void this._destroy(session);
|
|
512
529
|
}
|
|
513
530
|
}
|
|
514
531
|
/**
|
|
@@ -672,7 +689,7 @@ class SessionPool extends events_1.EventEmitter {
|
|
|
672
689
|
}
|
|
673
690
|
catch (e) {
|
|
674
691
|
this._inventory.borrowed.delete(session);
|
|
675
|
-
this._destroy(session);
|
|
692
|
+
await this._destroy(session);
|
|
676
693
|
}
|
|
677
694
|
}
|
|
678
695
|
/**
|
package/build/src/session.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ import { Snapshot, Transaction, PartitionedDml, TimestampBounds } from './transa
|
|
|
22
22
|
import { google } from '../protos/protos';
|
|
23
23
|
import { Database } from './database';
|
|
24
24
|
import { NormalCallback } from './common';
|
|
25
|
+
import { ObservabilityOptions } from './instrument';
|
|
25
26
|
import { grpc, CallOptions } from 'google-gax';
|
|
26
27
|
import IRequestOptions = google.spanner.v1.IRequestOptions;
|
|
27
28
|
export type GetSessionResponse = [Session, r.Response];
|
|
@@ -87,7 +88,6 @@ export type DeleteSessionCallback = NormalCallback<google.protobuf.IEmpty>;
|
|
|
87
88
|
* ```
|
|
88
89
|
*/
|
|
89
90
|
export declare class Session extends common.GrpcServiceObject {
|
|
90
|
-
id: string;
|
|
91
91
|
formattedName_?: string;
|
|
92
92
|
txn?: Transaction;
|
|
93
93
|
lastUsed?: number;
|
|
@@ -95,6 +95,7 @@ export declare class Session extends common.GrpcServiceObject {
|
|
|
95
95
|
commonHeaders_: {
|
|
96
96
|
[k: string]: string;
|
|
97
97
|
};
|
|
98
|
+
_observabilityOptions?: ObservabilityOptions;
|
|
98
99
|
constructor(database: Database, name?: string);
|
|
99
100
|
/**
|
|
100
101
|
* Delete a session.
|
package/build/src/session.js
CHANGED
|
@@ -67,8 +67,13 @@ const request_id_header_1 = require("./request_id_header");
|
|
|
67
67
|
* ```
|
|
68
68
|
*/
|
|
69
69
|
class Session extends common.GrpcServiceObject {
|
|
70
|
+
formattedName_;
|
|
71
|
+
txn;
|
|
72
|
+
lastUsed;
|
|
73
|
+
lastError;
|
|
74
|
+
commonHeaders_;
|
|
75
|
+
_observabilityOptions;
|
|
70
76
|
constructor(database, name) {
|
|
71
|
-
var _a;
|
|
72
77
|
const methods = {
|
|
73
78
|
/**
|
|
74
79
|
* Create a session.
|
|
@@ -200,7 +205,8 @@ class Session extends common.GrpcServiceObject {
|
|
|
200
205
|
});
|
|
201
206
|
},
|
|
202
207
|
});
|
|
203
|
-
this.
|
|
208
|
+
this._observabilityOptions = database._observabilityOptions;
|
|
209
|
+
this.commonHeaders_ = (0, common_1.getCommonHeaders)(this.parent.formattedName_, this._observabilityOptions?.enableEndToEndTracing);
|
|
204
210
|
this.request = database.request;
|
|
205
211
|
this.requestStream = database.requestStream;
|
|
206
212
|
if (name) {
|
package/build/src/table.js
CHANGED
|
@@ -43,6 +43,9 @@ const POSTGRESQL = 'POSTGRESQL';
|
|
|
43
43
|
* ```
|
|
44
44
|
*/
|
|
45
45
|
class Table {
|
|
46
|
+
database;
|
|
47
|
+
name;
|
|
48
|
+
_observabilityOptions;
|
|
46
49
|
constructor(database, name) {
|
|
47
50
|
/**
|
|
48
51
|
* The {@link Database} instance of this {@link Table} instance.
|
|
@@ -177,7 +180,7 @@ class Table {
|
|
|
177
180
|
return performDelete();
|
|
178
181
|
}
|
|
179
182
|
else {
|
|
180
|
-
performDelete();
|
|
183
|
+
void performDelete();
|
|
181
184
|
}
|
|
182
185
|
}
|
|
183
186
|
deleteRows(keys, optionsOrCallback, cb) {
|
|
@@ -239,6 +242,8 @@ class Table {
|
|
|
239
242
|
opts: this._observabilityOptions,
|
|
240
243
|
tableName: this.name,
|
|
241
244
|
dbName: this.getDBName(),
|
|
245
|
+
transactionTag: options?.requestOptions
|
|
246
|
+
?.transactionTag,
|
|
242
247
|
};
|
|
243
248
|
(0, instrument_1.startTrace)('Table.' + method, traceConfig, span => {
|
|
244
249
|
const requestOptions = 'requestOptions' in options ? options.requestOptions : {};
|
|
@@ -39,11 +39,15 @@ const RetryInfo = protobufjs_1.Root.fromJSON(jsonProtos).lookup('google.rpc.Retr
|
|
|
39
39
|
* @param {Error} [err] The last known retryable Error.
|
|
40
40
|
*/
|
|
41
41
|
class DeadlineError extends Error {
|
|
42
|
+
code;
|
|
43
|
+
details;
|
|
44
|
+
metadata;
|
|
45
|
+
errors;
|
|
42
46
|
constructor(error) {
|
|
43
47
|
super('Deadline for Transaction exceeded.');
|
|
44
48
|
this.code = google_gax_1.grpc.status.DEADLINE_EXCEEDED;
|
|
45
|
-
this.details =
|
|
46
|
-
this.metadata =
|
|
49
|
+
this.details = error?.details || '';
|
|
50
|
+
this.metadata = error?.metadata || new google_gax_1.grpc.Metadata();
|
|
47
51
|
this.errors = [];
|
|
48
52
|
if (error) {
|
|
49
53
|
this.errors.push(error);
|
|
@@ -62,6 +66,10 @@ exports.DeadlineError = DeadlineError;
|
|
|
62
66
|
* @param {RunTransactionOptions} [options] The runner options.
|
|
63
67
|
*/
|
|
64
68
|
class Runner {
|
|
69
|
+
attempts;
|
|
70
|
+
session;
|
|
71
|
+
transaction;
|
|
72
|
+
options;
|
|
65
73
|
constructor(session, transaction, options) {
|
|
66
74
|
this.attempts = 0;
|
|
67
75
|
this.session = session;
|
|
@@ -179,6 +187,7 @@ exports.Runner = Runner;
|
|
|
179
187
|
* @param {RunTransactionOptions} [options] Runner options.
|
|
180
188
|
*/
|
|
181
189
|
class TransactionRunner extends Runner {
|
|
190
|
+
runFn;
|
|
182
191
|
constructor(session, transaction, runFn, options) {
|
|
183
192
|
super(session, transaction, options);
|
|
184
193
|
this.runFn = runFn;
|
|
@@ -250,6 +259,7 @@ exports.TransactionRunner = TransactionRunner;
|
|
|
250
259
|
* @param {RunTransactionOptions} [options] Runner options.
|
|
251
260
|
*/
|
|
252
261
|
class AsyncTransactionRunner extends Runner {
|
|
262
|
+
runFn;
|
|
253
263
|
constructor(session, transaction, runFn, options) {
|
|
254
264
|
super(session, transaction, options);
|
|
255
265
|
this.runFn = runFn;
|
|
@@ -29,7 +29,7 @@ import { google } from '../protos/protos';
|
|
|
29
29
|
import IQueryOptions = google.spanner.v1.ExecuteSqlRequest.IQueryOptions;
|
|
30
30
|
import IRequestOptions = google.spanner.v1.IRequestOptions;
|
|
31
31
|
import { Spanner } from '.';
|
|
32
|
-
import { ObservabilityOptions } from './instrument';
|
|
32
|
+
import { ObservabilityOptions, traceConfig } from './instrument';
|
|
33
33
|
import { RunTransactionOptions } from './transaction-runner';
|
|
34
34
|
export type Rows = Array<Row | Json>;
|
|
35
35
|
export interface TimestampBounds {
|
|
@@ -247,6 +247,7 @@ export declare class Snapshot extends EventEmitter {
|
|
|
247
247
|
};
|
|
248
248
|
requestOptions?: Pick<IRequestOptions, 'transactionTag'>;
|
|
249
249
|
_observabilityOptions?: ObservabilityOptions;
|
|
250
|
+
_traceConfig: traceConfig;
|
|
250
251
|
protected _dbName?: string;
|
|
251
252
|
/**
|
|
252
253
|
* The transaction ID.
|