@google-cloud/spanner 6.8.0 → 6.10.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 +20 -0
- package/README.md +1 -0
- package/build/protos/google/spanner/admin/database/v1/spanner_database_admin.proto +90 -1
- package/build/protos/protos.d.ts +245 -0
- package/build/protos/protos.js +581 -0
- package/build/protos/protos.json +73 -0
- package/build/src/batch-transaction.js +10 -0
- package/build/src/common-grpc/service.js +4 -0
- package/build/src/common.d.ts +11 -0
- package/build/src/common.js +13 -1
- package/build/src/database.d.ts +74 -0
- package/build/src/database.js +41 -2
- package/build/src/index.d.ts +7 -0
- package/build/src/index.js +4 -0
- package/build/src/session-pool.d.ts +3 -3
- package/build/src/session.d.ts +8 -0
- package/build/src/session.js +15 -1
- package/build/src/transaction.d.ts +9 -0
- package/build/src/transaction.js +46 -6
- package/build/src/v1/database_admin_client.d.ts +79 -0
- package/build/src/v1/database_admin_client.js +43 -0
- package/build/src/v1/database_admin_client_config.json +5 -0
- package/package.json +1 -1
package/build/protos/protos.json
CHANGED
|
@@ -1883,6 +1883,34 @@
|
|
|
1883
1883
|
}
|
|
1884
1884
|
]
|
|
1885
1885
|
},
|
|
1886
|
+
"UpdateDatabase": {
|
|
1887
|
+
"requestType": "UpdateDatabaseRequest",
|
|
1888
|
+
"responseType": "google.longrunning.Operation",
|
|
1889
|
+
"options": {
|
|
1890
|
+
"(google.api.http).patch": "/v1/{database.name=projects/*/instances/*/databases/*}",
|
|
1891
|
+
"(google.api.http).body": "database",
|
|
1892
|
+
"(google.api.method_signature)": "database,update_mask",
|
|
1893
|
+
"(google.longrunning.operation_info).response_type": "Database",
|
|
1894
|
+
"(google.longrunning.operation_info).metadata_type": "UpdateDatabaseMetadata"
|
|
1895
|
+
},
|
|
1896
|
+
"parsedOptions": [
|
|
1897
|
+
{
|
|
1898
|
+
"(google.api.http)": {
|
|
1899
|
+
"patch": "/v1/{database.name=projects/*/instances/*/databases/*}",
|
|
1900
|
+
"body": "database"
|
|
1901
|
+
}
|
|
1902
|
+
},
|
|
1903
|
+
{
|
|
1904
|
+
"(google.api.method_signature)": "database,update_mask"
|
|
1905
|
+
},
|
|
1906
|
+
{
|
|
1907
|
+
"(google.longrunning.operation_info)": {
|
|
1908
|
+
"response_type": "Database",
|
|
1909
|
+
"metadata_type": "UpdateDatabaseMetadata"
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
]
|
|
1913
|
+
},
|
|
1886
1914
|
"UpdateDatabaseDdl": {
|
|
1887
1915
|
"requestType": "UpdateDatabaseDdlRequest",
|
|
1888
1916
|
"responseType": "google.longrunning.Operation",
|
|
@@ -2340,6 +2368,17 @@
|
|
|
2340
2368
|
"options": {
|
|
2341
2369
|
"(google.api.field_behavior)": "OUTPUT_ONLY"
|
|
2342
2370
|
}
|
|
2371
|
+
},
|
|
2372
|
+
"enableDropProtection": {
|
|
2373
|
+
"type": "bool",
|
|
2374
|
+
"id": 11
|
|
2375
|
+
},
|
|
2376
|
+
"reconciling": {
|
|
2377
|
+
"type": "bool",
|
|
2378
|
+
"id": 12,
|
|
2379
|
+
"options": {
|
|
2380
|
+
"(google.api.field_behavior)": "OUTPUT_ONLY"
|
|
2381
|
+
}
|
|
2343
2382
|
}
|
|
2344
2383
|
},
|
|
2345
2384
|
"nested": {
|
|
@@ -2450,6 +2489,40 @@
|
|
|
2450
2489
|
}
|
|
2451
2490
|
}
|
|
2452
2491
|
},
|
|
2492
|
+
"UpdateDatabaseRequest": {
|
|
2493
|
+
"fields": {
|
|
2494
|
+
"database": {
|
|
2495
|
+
"type": "Database",
|
|
2496
|
+
"id": 1,
|
|
2497
|
+
"options": {
|
|
2498
|
+
"(google.api.field_behavior)": "REQUIRED"
|
|
2499
|
+
}
|
|
2500
|
+
},
|
|
2501
|
+
"updateMask": {
|
|
2502
|
+
"type": "google.protobuf.FieldMask",
|
|
2503
|
+
"id": 2,
|
|
2504
|
+
"options": {
|
|
2505
|
+
"(google.api.field_behavior)": "REQUIRED"
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2508
|
+
}
|
|
2509
|
+
},
|
|
2510
|
+
"UpdateDatabaseMetadata": {
|
|
2511
|
+
"fields": {
|
|
2512
|
+
"request": {
|
|
2513
|
+
"type": "UpdateDatabaseRequest",
|
|
2514
|
+
"id": 1
|
|
2515
|
+
},
|
|
2516
|
+
"progress": {
|
|
2517
|
+
"type": "OperationProgress",
|
|
2518
|
+
"id": 2
|
|
2519
|
+
},
|
|
2520
|
+
"cancelTime": {
|
|
2521
|
+
"type": "google.protobuf.Timestamp",
|
|
2522
|
+
"id": 3
|
|
2523
|
+
}
|
|
2524
|
+
}
|
|
2525
|
+
},
|
|
2453
2526
|
"UpdateDatabaseDdlRequest": {
|
|
2454
2527
|
"fields": {
|
|
2455
2528
|
"database": {
|
|
@@ -123,11 +123,16 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
123
123
|
const reqOpts = Object.assign({}, query, transaction_1.Snapshot.encodeParams(query));
|
|
124
124
|
delete reqOpts.gaxOptions;
|
|
125
125
|
delete reqOpts.types;
|
|
126
|
+
const headers = {};
|
|
127
|
+
if (this._getSpanner().routeToLeaderEnabled) {
|
|
128
|
+
(0, common_1.addLeaderAwareRoutingHeader)(headers);
|
|
129
|
+
}
|
|
126
130
|
this.createPartitions_({
|
|
127
131
|
client: 'SpannerClient',
|
|
128
132
|
method: 'partitionQuery',
|
|
129
133
|
reqOpts,
|
|
130
134
|
gaxOpts: query.gaxOptions,
|
|
135
|
+
headers: headers,
|
|
131
136
|
}, callback);
|
|
132
137
|
}
|
|
133
138
|
/**
|
|
@@ -205,11 +210,16 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
205
210
|
delete reqOpts.gaxOptions;
|
|
206
211
|
delete reqOpts.keys;
|
|
207
212
|
delete reqOpts.ranges;
|
|
213
|
+
const headers = {};
|
|
214
|
+
if (this._getSpanner().routeToLeaderEnabled) {
|
|
215
|
+
(0, common_1.addLeaderAwareRoutingHeader)(headers);
|
|
216
|
+
}
|
|
208
217
|
this.createPartitions_({
|
|
209
218
|
client: 'SpannerClient',
|
|
210
219
|
method: 'partitionRead',
|
|
211
220
|
reqOpts,
|
|
212
221
|
gaxOpts: options.gaxOptions,
|
|
222
|
+
headers: headers,
|
|
213
223
|
}, callback);
|
|
214
224
|
}
|
|
215
225
|
/**
|
|
@@ -307,6 +307,10 @@ class GrpcService extends common_1.Service {
|
|
|
307
307
|
}
|
|
308
308
|
this.maxRetries = options.maxRetries;
|
|
309
309
|
this.userAgent = common_1.util.getUserAgentFromPackageJson(config.packageJson);
|
|
310
|
+
if (this.providedUserAgent) {
|
|
311
|
+
this.userAgent = `${this.providedUserAgent} ${this.userAgent}`;
|
|
312
|
+
}
|
|
313
|
+
options['grpc.primary_user_agent'] = this.userAgent;
|
|
310
314
|
this.activeServiceMap_ = new Map();
|
|
311
315
|
this.protos = {};
|
|
312
316
|
const protoServices = config.protoServices;
|
package/build/src/common.d.ts
CHANGED
|
@@ -45,3 +45,14 @@ export interface PagedOptionsWithFilter extends PagedOptions {
|
|
|
45
45
|
* by the backend.
|
|
46
46
|
*/
|
|
47
47
|
export declare const CLOUD_RESOURCE_HEADER = "google-cloud-resource-prefix";
|
|
48
|
+
/*!
|
|
49
|
+
* HTTP header to route the requests at Leader
|
|
50
|
+
*/
|
|
51
|
+
export declare const LEADER_AWARE_ROUTING_HEADER = "x-goog-spanner-route-to-leader";
|
|
52
|
+
/**
|
|
53
|
+
* Add Leader aware routing header to existing header list.
|
|
54
|
+
* @param headers Existing header list.
|
|
55
|
+
*/
|
|
56
|
+
export declare function addLeaderAwareRoutingHeader(headers: {
|
|
57
|
+
[k: string]: string;
|
|
58
|
+
}): void;
|
package/build/src/common.js
CHANGED
|
@@ -15,10 +15,22 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.CLOUD_RESOURCE_HEADER = void 0;
|
|
18
|
+
exports.addLeaderAwareRoutingHeader = exports.LEADER_AWARE_ROUTING_HEADER = exports.CLOUD_RESOURCE_HEADER = void 0;
|
|
19
19
|
/*!
|
|
20
20
|
* HTTP header for the resource prefix to improve routing
|
|
21
21
|
* by the backend.
|
|
22
22
|
*/
|
|
23
23
|
exports.CLOUD_RESOURCE_HEADER = 'google-cloud-resource-prefix';
|
|
24
|
+
/*!
|
|
25
|
+
* HTTP header to route the requests at Leader
|
|
26
|
+
*/
|
|
27
|
+
exports.LEADER_AWARE_ROUTING_HEADER = 'x-goog-spanner-route-to-leader';
|
|
28
|
+
/**
|
|
29
|
+
* Add Leader aware routing header to existing header list.
|
|
30
|
+
* @param headers Existing header list.
|
|
31
|
+
*/
|
|
32
|
+
function addLeaderAwareRoutingHeader(headers) {
|
|
33
|
+
headers[exports.LEADER_AWARE_ROUTING_HEADER] = 'true';
|
|
34
|
+
}
|
|
35
|
+
exports.addLeaderAwareRoutingHeader = addLeaderAwareRoutingHeader;
|
|
24
36
|
//# sourceMappingURL=common.js.map
|
package/build/src/database.d.ts
CHANGED
|
@@ -34,8 +34,11 @@ import { EnumKey, RequestConfig, TranslateEnumKeys } from '.';
|
|
|
34
34
|
import IPolicy = google.iam.v1.IPolicy;
|
|
35
35
|
import Policy = google.iam.v1.Policy;
|
|
36
36
|
import FieldMask = google.protobuf.FieldMask;
|
|
37
|
+
import IDatabase = google.spanner.admin.database.v1.IDatabase;
|
|
37
38
|
export type GetDatabaseRolesCallback = RequestCallback<IDatabaseRole, databaseAdmin.spanner.admin.database.v1.IListDatabaseRolesResponse>;
|
|
38
39
|
export type GetDatabaseRolesResponse = PagedResponse<IDatabaseRole, databaseAdmin.spanner.admin.database.v1.IListDatabaseRolesResponse>;
|
|
40
|
+
type SetDatabaseMetadataCallback = ResourceCallback<GaxOperation, IOperation>;
|
|
41
|
+
type SetDatabaseMetadataResponse = [GaxOperation, IOperation];
|
|
39
42
|
type IDatabaseRole = databaseAdmin.spanner.admin.database.v1.IDatabaseRole;
|
|
40
43
|
type CreateBatchTransactionCallback = ResourceCallback<BatchTransaction, google.spanner.v1.ITransaction | google.spanner.v1.ISession>;
|
|
41
44
|
type CreateBatchTransactionResponse = [
|
|
@@ -164,6 +167,69 @@ declare class Database extends common.GrpcServiceObject {
|
|
|
164
167
|
request: DatabaseRequest;
|
|
165
168
|
databaseRole?: string | null;
|
|
166
169
|
constructor(instance: Instance, name: string, poolOptions?: SessionPoolConstructor | SessionPoolOptions, queryOptions?: spannerClient.spanner.v1.ExecuteSqlRequest.IQueryOptions);
|
|
170
|
+
/**
|
|
171
|
+
* @typedef {array} SetDatabaseMetadataResponse
|
|
172
|
+
* @property {object} 0 The {@link Database} metadata.
|
|
173
|
+
* @property {object} 1 The full API response.
|
|
174
|
+
*/
|
|
175
|
+
/**
|
|
176
|
+
* @callback SetDatabaseMetadataCallback
|
|
177
|
+
* @param {?Error} err Request error, if any.
|
|
178
|
+
* @param {object} metadata The {@link Database} metadata.
|
|
179
|
+
* @param {object} apiResponse The full API response.
|
|
180
|
+
*/
|
|
181
|
+
/**
|
|
182
|
+
* Update the metadata for this database. Note that this method follows PATCH
|
|
183
|
+
* semantics, so previously-configured settings will persist.
|
|
184
|
+
*
|
|
185
|
+
* Wrapper around {@link v1.DatabaseAdminClient#updateDatabase}.
|
|
186
|
+
*
|
|
187
|
+
* @see {@link v1.DatabaseAdminClient#updateDatabase}
|
|
188
|
+
* @see [UpdateDatabase API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.database.v1#google.spanner.admin.database.v1.DatabaseAdmin.UpdateDatabase)
|
|
189
|
+
*
|
|
190
|
+
* @param {object} metadata The metadata you wish to set.
|
|
191
|
+
* @param {object} [gaxOptions] Request configuration options,
|
|
192
|
+
* See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
193
|
+
* for more details.
|
|
194
|
+
* @param {SetDatabaseMetadataCallback} [callback] Callback function.
|
|
195
|
+
* @returns {Promise<SetDatabaseMetadataResponse>}
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```
|
|
199
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
200
|
+
* const spanner = new Spanner();
|
|
201
|
+
*
|
|
202
|
+
* const instance = spanner.instance('my-instance');
|
|
203
|
+
* const database = instance.database('my-database');
|
|
204
|
+
*
|
|
205
|
+
* const metadata = {
|
|
206
|
+
* enableDropProtection: true
|
|
207
|
+
* };
|
|
208
|
+
*
|
|
209
|
+
* database.setMetadata(metadata, function(err, operation, apiResponse) {
|
|
210
|
+
* if (err) {
|
|
211
|
+
* // Error handling omitted.
|
|
212
|
+
* }
|
|
213
|
+
*
|
|
214
|
+
* operation
|
|
215
|
+
* .on('error', function(err) {})
|
|
216
|
+
* .on('complete', function() {
|
|
217
|
+
* // Metadata updated successfully.
|
|
218
|
+
* });
|
|
219
|
+
* });
|
|
220
|
+
*
|
|
221
|
+
* //-
|
|
222
|
+
* // If the callback is omitted, we'll return a Promise.
|
|
223
|
+
* //-
|
|
224
|
+
* database.setMetadata(metadata).then(function(data) {
|
|
225
|
+
* const operation = data[0];
|
|
226
|
+
* const apiResponse = data[1];
|
|
227
|
+
* });
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
setMetadata(metadata: IDatabase, gaxOptions?: CallOptions): Promise<SetDatabaseMetadataResponse>;
|
|
231
|
+
setMetadata(metadata: IDatabase, callback: SetDatabaseMetadataCallback): void;
|
|
232
|
+
setMetadata(metadata: IDatabase, gaxOptions: CallOptions, callback: SetDatabaseMetadataCallback): void;
|
|
167
233
|
static getEnvironmentQueryOptions(): databaseAdmin.spanner.v1.ExecuteSqlRequest.IQueryOptions;
|
|
168
234
|
/**
|
|
169
235
|
* @typedef {object} BatchCreateSessionsOptions
|
|
@@ -1864,6 +1930,14 @@ declare class Database extends common.GrpcServiceObject {
|
|
|
1864
1930
|
* ```
|
|
1865
1931
|
*/
|
|
1866
1932
|
static formatName_(instanceName: string, name: string): string;
|
|
1933
|
+
/**
|
|
1934
|
+
* Gets the Spanner object
|
|
1935
|
+
*
|
|
1936
|
+
* @private
|
|
1937
|
+
*
|
|
1938
|
+
* @returns {Spanner}
|
|
1939
|
+
*/
|
|
1940
|
+
private _getSpanner;
|
|
1867
1941
|
}
|
|
1868
1942
|
/**
|
|
1869
1943
|
* Reference to the {@link Database} class.
|
package/build/src/database.js
CHANGED
|
@@ -31,6 +31,7 @@ const table_1 = require("./table");
|
|
|
31
31
|
const transaction_runner_1 = require("./transaction-runner");
|
|
32
32
|
const common_1 = require("./common");
|
|
33
33
|
const arrify = require("arrify");
|
|
34
|
+
const snakeCase = require("lodash.snakecase");
|
|
34
35
|
/**
|
|
35
36
|
* Create a Database object to interact with a Cloud Spanner database.
|
|
36
37
|
*
|
|
@@ -156,6 +157,25 @@ class Database extends common.GrpcServiceObject {
|
|
|
156
157
|
this.pool_.open();
|
|
157
158
|
this.queryOptions_ = Object.assign(Object.assign({}, queryOptions), Database.getEnvironmentQueryOptions());
|
|
158
159
|
}
|
|
160
|
+
setMetadata(metadata, optionsOrCallback, cb) {
|
|
161
|
+
const gaxOpts = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
|
|
162
|
+
const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
|
|
163
|
+
const reqOpts = {
|
|
164
|
+
database: extend({
|
|
165
|
+
name: this.formattedName_,
|
|
166
|
+
}, metadata),
|
|
167
|
+
updateMask: {
|
|
168
|
+
paths: Object.keys(metadata).map(snakeCase),
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
return this.request({
|
|
172
|
+
client: 'DatabaseAdminClient',
|
|
173
|
+
method: 'updateDatabase',
|
|
174
|
+
reqOpts,
|
|
175
|
+
gaxOpts,
|
|
176
|
+
headers: this.resourceHeader_,
|
|
177
|
+
}, callback);
|
|
178
|
+
}
|
|
159
179
|
static getEnvironmentQueryOptions() {
|
|
160
180
|
const options = {};
|
|
161
181
|
if (process.env.SPANNER_OPTIMIZER_VERSION) {
|
|
@@ -179,12 +199,16 @@ class Database extends common.GrpcServiceObject {
|
|
|
179
199
|
sessionTemplate: { labels: labels, creatorRole: databaseRole },
|
|
180
200
|
sessionCount: count,
|
|
181
201
|
};
|
|
202
|
+
const headers = this.resourceHeader_;
|
|
203
|
+
if (this._getSpanner().routeToLeaderEnabled) {
|
|
204
|
+
(0, common_1.addLeaderAwareRoutingHeader)(headers);
|
|
205
|
+
}
|
|
182
206
|
this.request({
|
|
183
207
|
client: 'SpannerClient',
|
|
184
208
|
method: 'batchCreateSessions',
|
|
185
209
|
reqOpts,
|
|
186
210
|
gaxOpts: options.gaxOptions,
|
|
187
|
-
headers:
|
|
211
|
+
headers: headers,
|
|
188
212
|
}, (err, resp) => {
|
|
189
213
|
if (err) {
|
|
190
214
|
callback(err, null, resp);
|
|
@@ -275,12 +299,16 @@ class Database extends common.GrpcServiceObject {
|
|
|
275
299
|
}
|
|
276
300
|
reqOpts.session.creatorRole =
|
|
277
301
|
options.databaseRole || this.databaseRole || null;
|
|
302
|
+
const headers = this.resourceHeader_;
|
|
303
|
+
if (this._getSpanner().routeToLeaderEnabled) {
|
|
304
|
+
(0, common_1.addLeaderAwareRoutingHeader)(headers);
|
|
305
|
+
}
|
|
278
306
|
this.request({
|
|
279
307
|
client: 'SpannerClient',
|
|
280
308
|
method: 'createSession',
|
|
281
309
|
reqOpts,
|
|
282
310
|
gaxOpts: options.gaxOptions,
|
|
283
|
-
headers:
|
|
311
|
+
headers: headers,
|
|
284
312
|
}, (err, resp) => {
|
|
285
313
|
if (err) {
|
|
286
314
|
callback(err, null, resp);
|
|
@@ -1177,6 +1205,16 @@ class Database extends common.GrpcServiceObject {
|
|
|
1177
1205
|
const databaseName = name.split('/').pop();
|
|
1178
1206
|
return instanceName + '/databases/' + databaseName;
|
|
1179
1207
|
}
|
|
1208
|
+
/**
|
|
1209
|
+
* Gets the Spanner object
|
|
1210
|
+
*
|
|
1211
|
+
* @private
|
|
1212
|
+
*
|
|
1213
|
+
* @returns {Spanner}
|
|
1214
|
+
*/
|
|
1215
|
+
_getSpanner() {
|
|
1216
|
+
return this.instance.parent;
|
|
1217
|
+
}
|
|
1180
1218
|
}
|
|
1181
1219
|
exports.Database = Database;
|
|
1182
1220
|
/*! Developer Documentation
|
|
@@ -1225,6 +1263,7 @@ exports.Database = Database;
|
|
|
1225
1263
|
'runTransaction',
|
|
1226
1264
|
'runTransactionAsync',
|
|
1227
1265
|
'session',
|
|
1266
|
+
'setMetadata',
|
|
1228
1267
|
'table',
|
|
1229
1268
|
'updateSchema',
|
|
1230
1269
|
],
|
package/build/src/index.d.ts
CHANGED
|
@@ -46,11 +46,17 @@ export type GetInstanceConfigCallback = NormalCallback<IInstanceConfig>;
|
|
|
46
46
|
export type GetInstanceConfigOperationsOptions = PagedOptionsWithFilter;
|
|
47
47
|
export type GetInstanceConfigOperationsResponse = PagedResponse<IOperation, instanceAdmin.spanner.admin.instance.v1.IListInstanceConfigOperationsResponse>;
|
|
48
48
|
export type GetInstanceConfigOperationsCallback = PagedCallback<IOperation, instanceAdmin.spanner.admin.instance.v1.IListInstanceConfigOperationsResponse>;
|
|
49
|
+
/**
|
|
50
|
+
* Session pool configuration options.
|
|
51
|
+
* @property {boolean} [routeToLeaderEnabled=False] If set to true leader aware routing will be enabled.
|
|
52
|
+
* Enabling leader aware routing would route all requests in RW/PDML transactions to leader region.
|
|
53
|
+
*/
|
|
49
54
|
export interface SpannerOptions extends GrpcClientOptions {
|
|
50
55
|
apiEndpoint?: string;
|
|
51
56
|
servicePath?: string;
|
|
52
57
|
port?: number;
|
|
53
58
|
sslCreds?: grpc.ChannelCredentials;
|
|
59
|
+
routeToLeaderEnabled?: boolean;
|
|
54
60
|
}
|
|
55
61
|
export interface RequestConfig {
|
|
56
62
|
client: string;
|
|
@@ -154,6 +160,7 @@ declare class Spanner extends GrpcService {
|
|
|
154
160
|
resourceHeader_: {
|
|
155
161
|
[k: string]: string;
|
|
156
162
|
};
|
|
163
|
+
routeToLeaderEnabled: boolean;
|
|
157
164
|
/**
|
|
158
165
|
* Placeholder used to auto populate a column with the commit timestamp.
|
|
159
166
|
* This can only be used for timestamp columns that have set the option
|
package/build/src/index.js
CHANGED
|
@@ -173,6 +173,10 @@ class Spanner extends service_1.GrpcService {
|
|
|
173
173
|
packageJson: require('../../package.json'),
|
|
174
174
|
};
|
|
175
175
|
super(config, options);
|
|
176
|
+
this.routeToLeaderEnabled = false;
|
|
177
|
+
if (options.routeToLeaderEnabled === true) {
|
|
178
|
+
this.routeToLeaderEnabled = true;
|
|
179
|
+
}
|
|
176
180
|
this.options = options;
|
|
177
181
|
this.auth = new google_auth_library_1.GoogleAuth(this.options);
|
|
178
182
|
this.clients_ = new Map();
|
|
@@ -111,13 +111,13 @@ export interface SessionPoolInterface extends EventEmitter {
|
|
|
111
111
|
* @property {number} [acquireTimeout=Infinity] Time in milliseconds before
|
|
112
112
|
* giving up trying to acquire a session. If the specified value is
|
|
113
113
|
* `Infinity`, a timeout will not occur.
|
|
114
|
-
* @property {number} [concurrency=
|
|
114
|
+
* @property {number} [concurrency=Infinity] How many concurrent requests the pool is
|
|
115
115
|
* allowed to make.
|
|
116
116
|
* @property {boolean} [fail=false] If set to true, an error will be thrown when
|
|
117
117
|
* there are no available sessions for a request.
|
|
118
118
|
* @property {number} [idlesAfter=10] How long until a resource becomes idle, in
|
|
119
119
|
* minutes.
|
|
120
|
-
* @property {number} [keepAlive=
|
|
120
|
+
* @property {number} [keepAlive=30] How often to ping idle sessions, in
|
|
121
121
|
* minutes. Must be less than 1 hour.
|
|
122
122
|
* @property {Object<string, string>} [labels] Labels to apply to any session
|
|
123
123
|
* created by the pool.
|
|
@@ -125,7 +125,7 @@ export interface SessionPoolInterface extends EventEmitter {
|
|
|
125
125
|
* given time.
|
|
126
126
|
* @property {number} [maxIdle=1] Maximum number of idle resources to keep in
|
|
127
127
|
* the pool at any given time.
|
|
128
|
-
* @property {number} [min=
|
|
128
|
+
* @property {number} [min=25] Minimum number of resources to keep in the pool at
|
|
129
129
|
* any given time.
|
|
130
130
|
* @property {number} [writes=0.0]. Deprecated.
|
|
131
131
|
* @property {number} [incStep=25] The number of new sessions to create when at
|
package/build/src/session.d.ts
CHANGED
|
@@ -246,5 +246,13 @@ export declare class Session extends common.GrpcServiceObject {
|
|
|
246
246
|
* ```
|
|
247
247
|
*/
|
|
248
248
|
static formatName_(databaseName: string, name: string): string;
|
|
249
|
+
/**
|
|
250
|
+
* Gets the Spanner object
|
|
251
|
+
*
|
|
252
|
+
* @private
|
|
253
|
+
*
|
|
254
|
+
* @returns {Spanner}
|
|
255
|
+
*/
|
|
256
|
+
private _getSpanner;
|
|
249
257
|
}
|
|
250
258
|
export {};
|
package/build/src/session.js
CHANGED
|
@@ -227,12 +227,16 @@ class Session extends common.GrpcServiceObject {
|
|
|
227
227
|
const reqOpts = {
|
|
228
228
|
name: this.formattedName_,
|
|
229
229
|
};
|
|
230
|
+
const headers = this.resourceHeader_;
|
|
231
|
+
if (this._getSpanner().routeToLeaderEnabled) {
|
|
232
|
+
(0, common_1.addLeaderAwareRoutingHeader)(headers);
|
|
233
|
+
}
|
|
230
234
|
return this.request({
|
|
231
235
|
client: 'SpannerClient',
|
|
232
236
|
method: 'getSession',
|
|
233
237
|
reqOpts,
|
|
234
238
|
gaxOpts,
|
|
235
|
-
headers:
|
|
239
|
+
headers: headers,
|
|
236
240
|
}, (err, resp) => {
|
|
237
241
|
if (resp) {
|
|
238
242
|
resp.databaseRole = resp.creatorRole;
|
|
@@ -322,6 +326,16 @@ class Session extends common.GrpcServiceObject {
|
|
|
322
326
|
const sessionName = name.split('/').pop();
|
|
323
327
|
return databaseName + '/sessions/' + sessionName;
|
|
324
328
|
}
|
|
329
|
+
/**
|
|
330
|
+
* Gets the Spanner object
|
|
331
|
+
*
|
|
332
|
+
* @private
|
|
333
|
+
*
|
|
334
|
+
* @returns {Spanner}
|
|
335
|
+
*/
|
|
336
|
+
_getSpanner() {
|
|
337
|
+
return this.parent.parent.parent;
|
|
338
|
+
}
|
|
325
339
|
}
|
|
326
340
|
exports.Session = Session;
|
|
327
341
|
/*! Developer Documentation
|
|
@@ -30,6 +30,7 @@ import { NormalCallback } from './common';
|
|
|
30
30
|
import { google } from '../protos/protos';
|
|
31
31
|
import IQueryOptions = google.spanner.v1.ExecuteSqlRequest.IQueryOptions;
|
|
32
32
|
import IRequestOptions = google.spanner.v1.IRequestOptions;
|
|
33
|
+
import { Spanner } from '.';
|
|
33
34
|
export type Rows = Array<Row | Json>;
|
|
34
35
|
export interface TimestampBounds {
|
|
35
36
|
strong?: boolean;
|
|
@@ -854,6 +855,14 @@ export declare class Snapshot extends EventEmitter {
|
|
|
854
855
|
* @private
|
|
855
856
|
*/
|
|
856
857
|
private _wrapWithIdWaiter;
|
|
858
|
+
/**
|
|
859
|
+
* Gets the Spanner object
|
|
860
|
+
*
|
|
861
|
+
* @private
|
|
862
|
+
*
|
|
863
|
+
* @returns {Spanner}
|
|
864
|
+
*/
|
|
865
|
+
protected _getSpanner(): Spanner;
|
|
857
866
|
}
|
|
858
867
|
/**
|
|
859
868
|
* Never use DML class directly. Instead, it should be extended upon
|
package/build/src/transaction.js
CHANGED
|
@@ -163,12 +163,18 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
163
163
|
if (this.requestOptions) {
|
|
164
164
|
reqOpts.requestOptions = this.requestOptions;
|
|
165
165
|
}
|
|
166
|
+
const headers = this.resourceHeader_;
|
|
167
|
+
if (this._getSpanner().routeToLeaderEnabled &&
|
|
168
|
+
(this._options.readWrite !== undefined ||
|
|
169
|
+
this._options.partitionedDml !== undefined)) {
|
|
170
|
+
(0, common_1.addLeaderAwareRoutingHeader)(headers);
|
|
171
|
+
}
|
|
166
172
|
this.request({
|
|
167
173
|
client: 'SpannerClient',
|
|
168
174
|
method: 'beginTransaction',
|
|
169
175
|
reqOpts,
|
|
170
176
|
gaxOpts,
|
|
171
|
-
headers:
|
|
177
|
+
headers: headers,
|
|
172
178
|
}, (err, resp) => {
|
|
173
179
|
if (err) {
|
|
174
180
|
callback(err, resp);
|
|
@@ -375,6 +381,12 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
375
381
|
table,
|
|
376
382
|
keySet,
|
|
377
383
|
});
|
|
384
|
+
const headers = this.resourceHeader_;
|
|
385
|
+
if (this._getSpanner().routeToLeaderEnabled &&
|
|
386
|
+
(this._options.readWrite !== undefined ||
|
|
387
|
+
this._options.partitionedDml !== undefined)) {
|
|
388
|
+
(0, common_1.addLeaderAwareRoutingHeader)(headers);
|
|
389
|
+
}
|
|
378
390
|
const makeRequest = (resumeToken) => {
|
|
379
391
|
if (this.id && transaction.begin) {
|
|
380
392
|
delete transaction.begin;
|
|
@@ -385,7 +397,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
385
397
|
method: 'streamingRead',
|
|
386
398
|
reqOpts: Object.assign({}, reqOpts, { resumeToken }),
|
|
387
399
|
gaxOpts: gaxOptions,
|
|
388
|
-
headers:
|
|
400
|
+
headers: headers,
|
|
389
401
|
});
|
|
390
402
|
};
|
|
391
403
|
return (_c = (0, partial_result_stream_1.partialResultStream)(this._wrapWithIdWaiter(makeRequest), {
|
|
@@ -623,6 +635,12 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
623
635
|
paramTypes,
|
|
624
636
|
});
|
|
625
637
|
};
|
|
638
|
+
const headers = this.resourceHeader_;
|
|
639
|
+
if (this._getSpanner().routeToLeaderEnabled &&
|
|
640
|
+
(this._options.readWrite !== undefined ||
|
|
641
|
+
this._options.partitionedDml !== undefined)) {
|
|
642
|
+
(0, common_1.addLeaderAwareRoutingHeader)(headers);
|
|
643
|
+
}
|
|
626
644
|
const makeRequest = (resumeToken) => {
|
|
627
645
|
if (!reqOpts || (this.id && !reqOpts.transaction.id)) {
|
|
628
646
|
try {
|
|
@@ -639,7 +657,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
639
657
|
method: 'executeStreamingSql',
|
|
640
658
|
reqOpts: Object.assign({}, reqOpts, { resumeToken }),
|
|
641
659
|
gaxOpts: gaxOptions,
|
|
642
|
-
headers:
|
|
660
|
+
headers: headers,
|
|
643
661
|
});
|
|
644
662
|
};
|
|
645
663
|
return (0, partial_result_stream_1.partialResultStream)(this._wrapWithIdWaiter(makeRequest), {
|
|
@@ -796,6 +814,16 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
796
814
|
.on('data', chunk => this._idWaiter.emit('data', chunk))
|
|
797
815
|
.once('end', () => this._idWaiter.emit('end')));
|
|
798
816
|
}
|
|
817
|
+
/**
|
|
818
|
+
* Gets the Spanner object
|
|
819
|
+
*
|
|
820
|
+
* @private
|
|
821
|
+
*
|
|
822
|
+
* @returns {Spanner}
|
|
823
|
+
*/
|
|
824
|
+
_getSpanner() {
|
|
825
|
+
return this.session.parent.parent.parent;
|
|
826
|
+
}
|
|
799
827
|
}
|
|
800
828
|
exports.Snapshot = Snapshot;
|
|
801
829
|
/*! Developer Documentation
|
|
@@ -965,12 +993,16 @@ class Transaction extends Dml {
|
|
|
965
993
|
seqno: this._seqno++,
|
|
966
994
|
statements,
|
|
967
995
|
};
|
|
996
|
+
const headers = this.resourceHeader_;
|
|
997
|
+
if (this._getSpanner().routeToLeaderEnabled) {
|
|
998
|
+
(0, common_1.addLeaderAwareRoutingHeader)(headers);
|
|
999
|
+
}
|
|
968
1000
|
this.request({
|
|
969
1001
|
client: 'SpannerClient',
|
|
970
1002
|
method: 'executeBatchDml',
|
|
971
1003
|
reqOpts,
|
|
972
1004
|
gaxOpts,
|
|
973
|
-
headers:
|
|
1005
|
+
headers: headers,
|
|
974
1006
|
}, (err, resp) => {
|
|
975
1007
|
var _a;
|
|
976
1008
|
let batchUpdateError;
|
|
@@ -1037,12 +1069,16 @@ class Transaction extends Dml {
|
|
|
1037
1069
|
reqOpts.returnCommitStats = options.returnCommitStats;
|
|
1038
1070
|
}
|
|
1039
1071
|
reqOpts.requestOptions = Object.assign(requestOptions || {}, this.requestOptions);
|
|
1072
|
+
const headers = this.resourceHeader_;
|
|
1073
|
+
if (this._getSpanner().routeToLeaderEnabled) {
|
|
1074
|
+
(0, common_1.addLeaderAwareRoutingHeader)(headers);
|
|
1075
|
+
}
|
|
1040
1076
|
this.request({
|
|
1041
1077
|
client: 'SpannerClient',
|
|
1042
1078
|
method: 'commit',
|
|
1043
1079
|
reqOpts,
|
|
1044
1080
|
gaxOpts: gaxOpts,
|
|
1045
|
-
headers:
|
|
1081
|
+
headers: headers,
|
|
1046
1082
|
}, (err, resp) => {
|
|
1047
1083
|
this.end();
|
|
1048
1084
|
if (resp && resp.commitTimestamp) {
|
|
@@ -1294,12 +1330,16 @@ class Transaction extends Dml {
|
|
|
1294
1330
|
session,
|
|
1295
1331
|
transactionId,
|
|
1296
1332
|
};
|
|
1333
|
+
const headers = this.resourceHeader_;
|
|
1334
|
+
if (this._getSpanner().routeToLeaderEnabled) {
|
|
1335
|
+
(0, common_1.addLeaderAwareRoutingHeader)(headers);
|
|
1336
|
+
}
|
|
1297
1337
|
this.request({
|
|
1298
1338
|
client: 'SpannerClient',
|
|
1299
1339
|
method: 'rollback',
|
|
1300
1340
|
reqOpts,
|
|
1301
1341
|
gaxOpts,
|
|
1302
|
-
headers:
|
|
1342
|
+
headers: headers,
|
|
1303
1343
|
}, (err) => {
|
|
1304
1344
|
this.end();
|
|
1305
1345
|
callback(err);
|