@google-cloud/spanner 7.21.0 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/build/protos/google/spanner/admin/database/v1/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 +36 -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/change_stream.proto +451 -0
- package/build/protos/google/spanner/v1/commit_response.proto +10 -5
- 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 +41 -357
- package/build/protos/google/spanner/v1/type.proto +1 -1
- package/build/protos/protos.d.ts +1577 -194
- package/build/protos/protos.js +3977 -288
- package/build/protos/protos.json +325 -3
- package/build/src/backup.js +7 -0
- package/build/src/batch-transaction.d.ts +48 -29
- package/build/src/batch-transaction.js +15 -100
- package/build/src/codec.js +63 -47
- package/build/src/common-grpc/service-object.js +1 -0
- package/build/src/common-grpc/service.js +35 -18
- package/build/src/common.d.ts +1 -0
- package/build/src/common.js +9 -1
- package/build/src/database.d.ts +1 -0
- package/build/src/database.js +54 -42
- package/build/src/helper.d.ts +99 -0
- package/build/src/helper.js +178 -0
- package/build/src/index.d.ts +33 -0
- package/build/src/index.js +202 -21
- 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.js +5 -6
- package/build/src/metrics/constants.d.ts +36 -0
- package/build/src/metrics/constants.js +106 -0
- package/build/src/metrics/external-types.d.ts +20 -0
- package/build/src/metrics/external-types.js +32 -0
- package/build/src/metrics/interceptor.d.ts +13 -0
- package/build/src/metrics/interceptor.js +87 -0
- package/build/src/metrics/metrics-tracer-factory.d.ts +165 -0
- package/build/src/metrics/metrics-tracer-factory.js +389 -0
- package/build/src/metrics/metrics-tracer.d.ts +204 -0
- package/build/src/metrics/metrics-tracer.js +371 -0
- package/build/src/metrics/spanner-metrics-exporter.d.ts +35 -0
- package/build/src/metrics/spanner-metrics-exporter.js +119 -0
- package/build/src/metrics/transform.d.ts +144 -0
- package/build/src/metrics/transform.js +272 -0
- package/build/src/multiplexed-session.js +7 -1
- package/build/src/partial-result-stream.js +18 -10
- package/build/src/request_id_header.js +1 -0
- package/build/src/session-factory.d.ts +34 -0
- package/build/src/session-factory.js +35 -2
- package/build/src/session-pool.js +24 -8
- package/build/src/session.d.ts +0 -1
- package/build/src/session.js +7 -2
- package/build/src/table.js +6 -3
- package/build/src/transaction-runner.d.ts +1 -0
- package/build/src/transaction-runner.js +18 -2
- package/build/src/transaction.d.ts +42 -1
- package/build/src/transaction.js +258 -94
- package/build/src/v1/database_admin_client.d.ts +37 -2
- package/build/src/v1/database_admin_client.js +718 -168
- package/build/src/v1/database_admin_client_config.json +4 -0
- package/build/src/v1/instance_admin_client.d.ts +122 -1
- package/build/src/v1/instance_admin_client.js +765 -146
- package/build/src/v1/spanner_client.d.ts +2 -1
- package/build/src/v1/spanner_client.js +391 -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/build/src/v1/spanner_proto_list.json +1 -0
- package/package.json +64 -58
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) {
|
|
@@ -235,12 +238,12 @@ class Table {
|
|
|
235
238
|
* @param {function} callback The callback function.
|
|
236
239
|
*/
|
|
237
240
|
_mutate(method, rows, options = {}, callback) {
|
|
238
|
-
var _a;
|
|
239
241
|
const traceConfig = {
|
|
240
242
|
opts: this._observabilityOptions,
|
|
241
243
|
tableName: this.name,
|
|
242
244
|
dbName: this.getDBName(),
|
|
243
|
-
transactionTag:
|
|
245
|
+
transactionTag: options?.requestOptions
|
|
246
|
+
?.transactionTag,
|
|
244
247
|
};
|
|
245
248
|
(0, instrument_1.startTrace)('Table.' + method, traceConfig, span => {
|
|
246
249
|
const requestOptions = 'requestOptions' in options ? options.requestOptions : {};
|
|
@@ -80,6 +80,7 @@ export declare abstract class Runner<T> {
|
|
|
80
80
|
session: Session;
|
|
81
81
|
transaction?: Transaction;
|
|
82
82
|
options: RunTransactionOptions;
|
|
83
|
+
multiplexedSessionPreviousTransactionId?: Uint8Array | string;
|
|
83
84
|
constructor(session: Session, transaction: Transaction, options?: RunTransactionOptions);
|
|
84
85
|
/**
|
|
85
86
|
* Runs the user function against the provided transaction. Resolving the
|
|
@@ -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,11 @@ 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;
|
|
73
|
+
multiplexedSessionPreviousTransactionId;
|
|
65
74
|
constructor(session, transaction, options) {
|
|
66
75
|
this.attempts = 0;
|
|
67
76
|
this.session = session;
|
|
@@ -125,6 +134,8 @@ class Runner {
|
|
|
125
134
|
}
|
|
126
135
|
const transaction = this.session.transaction(this.session.parent.queryOptions_);
|
|
127
136
|
transaction.setReadWriteTransactionOptions(this.options);
|
|
137
|
+
transaction.multiplexedSessionPreviousTransactionId =
|
|
138
|
+
this.multiplexedSessionPreviousTransactionId;
|
|
128
139
|
if (this.attempts > 0) {
|
|
129
140
|
await transaction.begin();
|
|
130
141
|
}
|
|
@@ -153,6 +164,9 @@ class Runner {
|
|
|
153
164
|
this.session.lastError = e;
|
|
154
165
|
lastError = e;
|
|
155
166
|
}
|
|
167
|
+
finally {
|
|
168
|
+
this.multiplexedSessionPreviousTransactionId = transaction.id;
|
|
169
|
+
}
|
|
156
170
|
// Note that if the error is a 'Session not found' error, it will be
|
|
157
171
|
// thrown here. We do this to bubble this error up to the caller who is
|
|
158
172
|
// responsible for retrying the transaction on a different session.
|
|
@@ -179,6 +193,7 @@ exports.Runner = Runner;
|
|
|
179
193
|
* @param {RunTransactionOptions} [options] Runner options.
|
|
180
194
|
*/
|
|
181
195
|
class TransactionRunner extends Runner {
|
|
196
|
+
runFn;
|
|
182
197
|
constructor(session, transaction, runFn, options) {
|
|
183
198
|
super(session, transaction, options);
|
|
184
199
|
this.runFn = runFn;
|
|
@@ -250,6 +265,7 @@ exports.TransactionRunner = TransactionRunner;
|
|
|
250
265
|
* @param {RunTransactionOptions} [options] Runner options.
|
|
251
266
|
*/
|
|
252
267
|
class AsyncTransactionRunner extends Runner {
|
|
268
|
+
runFn;
|
|
253
269
|
constructor(session, transaction, runFn, options) {
|
|
254
270
|
super(session, transaction, options);
|
|
255
271
|
this.runFn = runFn;
|
|
@@ -23,6 +23,7 @@ import { Json, JSONOptions, Type, Value } from './codec';
|
|
|
23
23
|
import { PartialResultStream, ResumeToken, Row } from './partial-result-stream';
|
|
24
24
|
import { Session } from './session';
|
|
25
25
|
import { Key } from './table';
|
|
26
|
+
import { Span } from './instrument';
|
|
26
27
|
import { google as spannerClient } from '../protos/protos';
|
|
27
28
|
import { NormalCallback } from './common';
|
|
28
29
|
import { google } from '../protos/protos';
|
|
@@ -173,6 +174,7 @@ export interface RunUpdateCallback {
|
|
|
173
174
|
(err: null | grpc.ServiceError, rowCount: number): void;
|
|
174
175
|
}
|
|
175
176
|
export type CommitCallback = NormalCallback<spannerClient.spanner.v1.ICommitResponse>;
|
|
177
|
+
type PrecommitTokenProvider = spannerClient.spanner.v1.ITransaction | spannerClient.spanner.v1.IPartialResultSet | spannerClient.spanner.v1.IExecuteBatchDmlResponse | spannerClient.spanner.v1.ICommitResponse;
|
|
176
178
|
/**
|
|
177
179
|
* @typedef {object} TimestampBounds
|
|
178
180
|
* @property {boolean} [strong=true] Read at a timestamp where all previously
|
|
@@ -233,7 +235,9 @@ export declare class Snapshot extends EventEmitter {
|
|
|
233
235
|
protected _waitingRequests: Array<() => void>;
|
|
234
236
|
protected _inlineBeginStarted: any;
|
|
235
237
|
protected _useInRunner: boolean;
|
|
238
|
+
protected _latestPreCommitToken: spannerClient.spanner.v1.IMultiplexedSessionPrecommitToken | undefined | null;
|
|
236
239
|
id?: Uint8Array | string;
|
|
240
|
+
multiplexedSessionPreviousTransactionId?: Uint8Array | string;
|
|
237
241
|
ended: boolean;
|
|
238
242
|
metadata?: spannerClient.spanner.v1.ITransaction;
|
|
239
243
|
readTimestamp?: PreciseDate;
|
|
@@ -249,6 +253,7 @@ export declare class Snapshot extends EventEmitter {
|
|
|
249
253
|
_observabilityOptions?: ObservabilityOptions;
|
|
250
254
|
_traceConfig: traceConfig;
|
|
251
255
|
protected _dbName?: string;
|
|
256
|
+
protected _mutationKey: spannerClient.spanner.v1.Mutation | null;
|
|
252
257
|
/**
|
|
253
258
|
* The transaction ID.
|
|
254
259
|
*
|
|
@@ -293,6 +298,40 @@ export declare class Snapshot extends EventEmitter {
|
|
|
293
298
|
* are specified for a query.
|
|
294
299
|
*/
|
|
295
300
|
constructor(session: Session, options?: TimestampBounds, queryOptions?: IQueryOptions);
|
|
301
|
+
protected _updatePrecommitToken(resp: PrecommitTokenProvider): void;
|
|
302
|
+
/**
|
|
303
|
+
* Selects a single representative mutation from a list to be used as the
|
|
304
|
+
* transaction's `mutationKey`.
|
|
305
|
+
*
|
|
306
|
+
* This key is required by Spanner and is sent in the `BeginTransactionRequest`
|
|
307
|
+
* for read-write transactions that only contain mutations. The selection follows
|
|
308
|
+
* a two-tiered heuristic to choose the most significant mutation.
|
|
309
|
+
*
|
|
310
|
+
* The selection heuristic is as follows:
|
|
311
|
+
*
|
|
312
|
+
* 1. Priority of Operation Type: High-priority mutations (`delete`, `update`,
|
|
313
|
+
* `replace`, `insertOrUpdate`) are always chosen over low-priority
|
|
314
|
+
* (`insert`) mutations.
|
|
315
|
+
*
|
|
316
|
+
* 2. Selection Strategy:
|
|
317
|
+
* - If any high-priority mutations exist, one is chosen randomly from
|
|
318
|
+
* that group, ignoring the number of rows.
|
|
319
|
+
* - If only `insert` mutations exist, the one(s) with the largest number
|
|
320
|
+
* of rows are identified, and one is chosen randomly from that subset.
|
|
321
|
+
*
|
|
322
|
+
* @protected
|
|
323
|
+
* @param mutations The list of mutations from which to select the key.
|
|
324
|
+
*/
|
|
325
|
+
protected _setMutationKey(mutations: spannerClient.spanner.v1.Mutation[]): void;
|
|
326
|
+
/**
|
|
327
|
+
* Modifies transaction selector to include the multiplexed session previous
|
|
328
|
+
* transaction id.
|
|
329
|
+
* This is essential for operations that use an `inline begin`.
|
|
330
|
+
* @protected
|
|
331
|
+
* @param transaction The transaction selector object that will be mutated
|
|
332
|
+
* to include the multiplexed session previous transaction id.
|
|
333
|
+
*/
|
|
334
|
+
protected _setPreviousTransactionId(transaction: spannerClient.spanner.v1.ITransactionSelector): void;
|
|
296
335
|
/**
|
|
297
336
|
* @typedef {object} TransactionResponse
|
|
298
337
|
* @property {string|Buffer} id The transaction ID.
|
|
@@ -909,7 +948,7 @@ export declare class Snapshot extends EventEmitter {
|
|
|
909
948
|
*
|
|
910
949
|
* @param {spannerClient.spanner.v1.ITransaction} resp Response object.
|
|
911
950
|
*/
|
|
912
|
-
protected _update(resp: spannerClient.spanner.v1.ITransaction): void;
|
|
951
|
+
protected _update(resp: spannerClient.spanner.v1.ITransaction, span: Span): void;
|
|
913
952
|
/**
|
|
914
953
|
* Wrap `makeRequest` function with the lock to make sure the inline begin
|
|
915
954
|
* transaction can happen only once.
|
|
@@ -1012,6 +1051,7 @@ export declare class Transaction extends Dml {
|
|
|
1012
1051
|
commitTimestamp?: PreciseDate;
|
|
1013
1052
|
commitTimestampProto?: spannerClient.protobuf.ITimestamp;
|
|
1014
1053
|
private _queuedMutations;
|
|
1054
|
+
private _retryCommit;
|
|
1015
1055
|
/**
|
|
1016
1056
|
* Timestamp at which the transaction was committed. Will be populated once
|
|
1017
1057
|
* {@link Transaction#commit} is called.
|
|
@@ -1695,3 +1735,4 @@ export declare class PartitionedDml extends Dml {
|
|
|
1695
1735
|
runUpdate(query: string | ExecuteSqlRequest): Promise<RunUpdateResponse>;
|
|
1696
1736
|
runUpdate(query: string | ExecuteSqlRequest, callback: RunUpdateCallback): void;
|
|
1697
1737
|
}
|
|
1738
|
+
export {};
|