@google-cloud/spanner 7.14.0 → 7.15.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/CHANGELOG.md +24 -0
- package/README.md +14 -2
- package/build/protos/protos.d.ts +0 -144
- package/build/protos/protos.js +48 -288
- package/build/protos/protos.json +3 -0
- package/build/src/batch-transaction.d.ts +1 -0
- package/build/src/batch-transaction.js +90 -50
- package/build/src/database.d.ts +5 -2
- package/build/src/database.js +430 -235
- package/build/src/index.d.ts +5 -0
- package/build/src/index.js +4 -0
- package/build/src/instance.d.ts +2 -0
- package/build/src/instance.js +6 -1
- package/build/src/instrument.d.ts +84 -0
- package/build/src/instrument.js +213 -0
- package/build/src/session-pool.d.ts +2 -0
- package/build/src/session-pool.js +61 -23
- package/build/src/session.js +1 -7
- package/build/src/table.d.ts +3 -0
- package/build/src/table.js +34 -14
- package/build/src/transaction.d.ts +3 -0
- package/build/src/transaction.js +411 -194
- package/package.json +11 -2
|
@@ -22,6 +22,7 @@ const extend = require("extend");
|
|
|
22
22
|
const is = require("is");
|
|
23
23
|
const transaction_1 = require("./transaction");
|
|
24
24
|
const common_1 = require("../src/common");
|
|
25
|
+
const instrument_1 = require("./instrument");
|
|
25
26
|
/**
|
|
26
27
|
* Use a BatchTransaction object to create partitions and read/query against
|
|
27
28
|
* your Cloud Spanner database.
|
|
@@ -123,17 +124,33 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
123
124
|
const reqOpts = Object.assign({}, query, transaction_1.Snapshot.encodeParams(query));
|
|
124
125
|
delete reqOpts.gaxOptions;
|
|
125
126
|
delete reqOpts.types;
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
127
|
+
const traceConfig = {
|
|
128
|
+
sql: query,
|
|
129
|
+
opts: this._observabilityOptions,
|
|
130
|
+
dbName: this.getDBName(),
|
|
131
|
+
};
|
|
132
|
+
return (0, instrument_1.startTrace)('BatchTransaction.createQueryPartitions', traceConfig, span => {
|
|
133
|
+
const headers = {};
|
|
134
|
+
if (this._getSpanner().routeToLeaderEnabled) {
|
|
135
|
+
(0, common_1.addLeaderAwareRoutingHeader)(headers);
|
|
136
|
+
}
|
|
137
|
+
this.createPartitions_({
|
|
138
|
+
client: 'SpannerClient',
|
|
139
|
+
method: 'partitionQuery',
|
|
140
|
+
reqOpts,
|
|
141
|
+
gaxOpts: query.gaxOptions,
|
|
142
|
+
headers: headers,
|
|
143
|
+
}, (err, partitions, resp) => {
|
|
144
|
+
if (err) {
|
|
145
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
146
|
+
}
|
|
147
|
+
span.end();
|
|
148
|
+
callback(err, partitions, resp);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
getDBName() {
|
|
153
|
+
return this.session.parent.formattedName_;
|
|
137
154
|
}
|
|
138
155
|
/**
|
|
139
156
|
* Generic create partition method. Handles common parameters used in both
|
|
@@ -146,32 +163,42 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
146
163
|
* @param {function} callback Callback function.
|
|
147
164
|
*/
|
|
148
165
|
createPartitions_(config, callback) {
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
});
|
|
153
|
-
config.reqOpts = extend({}, query);
|
|
154
|
-
config.headers = {
|
|
155
|
-
[common_1.CLOUD_RESOURCE_HEADER]: this.session.parent.formattedName_,
|
|
166
|
+
const traceConfig = {
|
|
167
|
+
opts: this._observabilityOptions,
|
|
168
|
+
dbName: this.getDBName(),
|
|
156
169
|
};
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
const partitions = resp.partitions.map(partition => {
|
|
164
|
-
return extend({}, query, partition);
|
|
170
|
+
return (0, instrument_1.startTrace)('BatchTransaction.createPartitions_', traceConfig, span => {
|
|
171
|
+
const query = extend({}, config.reqOpts, {
|
|
172
|
+
session: this.session.formattedName_,
|
|
173
|
+
transaction: { id: this.id },
|
|
165
174
|
});
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
this.
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
175
|
+
config.reqOpts = extend({}, query);
|
|
176
|
+
config.headers = {
|
|
177
|
+
[common_1.CLOUD_RESOURCE_HEADER]: this.session.parent
|
|
178
|
+
.formattedName_,
|
|
179
|
+
};
|
|
180
|
+
delete query.partitionOptions;
|
|
181
|
+
this.session.request(config, (err, resp) => {
|
|
182
|
+
if (err) {
|
|
183
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
184
|
+
span.end();
|
|
185
|
+
callback(err, null, resp);
|
|
186
|
+
return;
|
|
172
187
|
}
|
|
173
|
-
|
|
174
|
-
|
|
188
|
+
const partitions = resp.partitions.map(partition => {
|
|
189
|
+
return extend({}, query, partition);
|
|
190
|
+
});
|
|
191
|
+
if (resp.transaction) {
|
|
192
|
+
const { id, readTimestamp } = resp.transaction;
|
|
193
|
+
this.id = id;
|
|
194
|
+
if (readTimestamp) {
|
|
195
|
+
this.readTimestampProto = readTimestamp;
|
|
196
|
+
this.readTimestamp = new precise_date_1.PreciseDate(readTimestamp);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
span.end();
|
|
200
|
+
callback(null, partitions, resp);
|
|
201
|
+
});
|
|
175
202
|
});
|
|
176
203
|
}
|
|
177
204
|
/**
|
|
@@ -204,23 +231,35 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
204
231
|
* @returns {Promise<CreateReadPartitionsResponse>}
|
|
205
232
|
*/
|
|
206
233
|
createReadPartitions(options, callback) {
|
|
207
|
-
const
|
|
208
|
-
|
|
234
|
+
const traceConfig = {
|
|
235
|
+
opts: this._observabilityOptions,
|
|
236
|
+
dbName: this.getDBName(),
|
|
237
|
+
};
|
|
238
|
+
return (0, instrument_1.startTrace)('BatchTransaction.createReadPartitions', traceConfig, span => {
|
|
239
|
+
const reqOpts = Object.assign({}, options, {
|
|
240
|
+
keySet: transaction_1.Snapshot.encodeKeySet(options),
|
|
241
|
+
});
|
|
242
|
+
delete reqOpts.gaxOptions;
|
|
243
|
+
delete reqOpts.keys;
|
|
244
|
+
delete reqOpts.ranges;
|
|
245
|
+
const headers = {};
|
|
246
|
+
if (this._getSpanner().routeToLeaderEnabled) {
|
|
247
|
+
(0, common_1.addLeaderAwareRoutingHeader)(headers);
|
|
248
|
+
}
|
|
249
|
+
this.createPartitions_({
|
|
250
|
+
client: 'SpannerClient',
|
|
251
|
+
method: 'partitionRead',
|
|
252
|
+
reqOpts,
|
|
253
|
+
gaxOpts: options.gaxOptions,
|
|
254
|
+
headers: headers,
|
|
255
|
+
}, (err, partitions, resp) => {
|
|
256
|
+
if (err) {
|
|
257
|
+
(0, instrument_1.setSpanError)(span, err);
|
|
258
|
+
}
|
|
259
|
+
span.end();
|
|
260
|
+
callback(err, partitions, resp);
|
|
261
|
+
});
|
|
209
262
|
});
|
|
210
|
-
delete reqOpts.gaxOptions;
|
|
211
|
-
delete reqOpts.keys;
|
|
212
|
-
delete reqOpts.ranges;
|
|
213
|
-
const headers = {};
|
|
214
|
-
if (this._getSpanner().routeToLeaderEnabled) {
|
|
215
|
-
(0, common_1.addLeaderAwareRoutingHeader)(headers);
|
|
216
|
-
}
|
|
217
|
-
this.createPartitions_({
|
|
218
|
-
client: 'SpannerClient',
|
|
219
|
-
method: 'partitionRead',
|
|
220
|
-
reqOpts,
|
|
221
|
-
gaxOpts: options.gaxOptions,
|
|
222
|
-
headers: headers,
|
|
223
|
-
}, callback);
|
|
224
263
|
}
|
|
225
264
|
/**
|
|
226
265
|
* Executes partition.
|
|
@@ -294,6 +333,7 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
294
333
|
* ```
|
|
295
334
|
*/
|
|
296
335
|
executeStream(partition) {
|
|
336
|
+
// TODO: Instrument the streams with Otel.
|
|
297
337
|
if (is.string(partition.table)) {
|
|
298
338
|
return this.createReadStream(partition.table, partition);
|
|
299
339
|
}
|
package/build/src/database.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ import IPolicy = google.iam.v1.IPolicy;
|
|
|
33
33
|
import Policy = google.iam.v1.Policy;
|
|
34
34
|
import FieldMask = google.protobuf.FieldMask;
|
|
35
35
|
import IDatabase = google.spanner.admin.database.v1.IDatabase;
|
|
36
|
+
import { ObservabilityOptions } from './instrument';
|
|
36
37
|
export type GetDatabaseRolesCallback = RequestCallback<IDatabaseRole, databaseAdmin.spanner.admin.database.v1.IListDatabaseRolesResponse>;
|
|
37
38
|
export type GetDatabaseRolesResponse = PagedResponse<IDatabaseRole, databaseAdmin.spanner.admin.database.v1.IListDatabaseRolesResponse>;
|
|
38
39
|
type SetDatabaseMetadataCallback = ResourceCallback<GaxOperation, IOperation>;
|
|
@@ -175,6 +176,8 @@ declare class Database extends common.GrpcServiceObject {
|
|
|
175
176
|
request: DatabaseRequest;
|
|
176
177
|
databaseRole?: string | null;
|
|
177
178
|
databaseDialect?: EnumKey<typeof databaseAdmin.spanner.admin.database.v1.DatabaseDialect> | null;
|
|
179
|
+
_observabilityOptions?: ObservabilityOptions;
|
|
180
|
+
private _traceConfig;
|
|
178
181
|
constructor(instance: Instance, name: string, poolOptions?: SessionPoolConstructor | SessionPoolOptions, queryOptions?: spannerClient.spanner.v1.ExecuteSqlRequest.IQueryOptions);
|
|
179
182
|
/**
|
|
180
183
|
* @typedef {array} SetDatabaseMetadataResponse
|
|
@@ -1861,7 +1864,7 @@ declare class Database extends common.GrpcServiceObject {
|
|
|
1861
1864
|
*
|
|
1862
1865
|
* @example
|
|
1863
1866
|
* ```
|
|
1864
|
-
* const {Spanner} = require('@google-cloud/spanner');
|
|
1867
|
+
* const {Spanner, MutationSet} = require('@google-cloud/spanner');
|
|
1865
1868
|
* const spanner = new Spanner();
|
|
1866
1869
|
*
|
|
1867
1870
|
* const instance = spanner.instance('my-instance');
|
|
@@ -1879,7 +1882,7 @@ declare class Database extends common.GrpcServiceObject {
|
|
|
1879
1882
|
* });
|
|
1880
1883
|
*
|
|
1881
1884
|
* try {
|
|
1882
|
-
* const [response
|
|
1885
|
+
* const [response] = await database.writeAtLeastOnce(mutations, {});
|
|
1883
1886
|
* console.log(response.commitTimestamp);
|
|
1884
1887
|
* } catch(err) {
|
|
1885
1888
|
* console.log("Error: ", err);
|