Skip to content

Commit 0824f39

Browse files
authored
Merge branch 'main' into uuid-support
2 parents af60f7c + a6919b1 commit 0824f39

File tree

10 files changed

+249
-20
lines changed

10 files changed

+249
-20
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
[1]: https://www.npmjs.com/package/nodejs-spanner?activeTab=versions
66

7+
## [7.18.1](https://github.com/googleapis/nodejs-spanner/compare/v7.18.0...v7.18.1) (2025-02-05)
8+
9+
10+
### Bug Fixes
11+
12+
* Fix NodeJS release ([#2229](https://github.com/googleapis/nodejs-spanner/issues/2229)) ([f830fc8](https://github.com/googleapis/nodejs-spanner/commit/f830fc82ce666902db3cddc667326dc2731c14a1))
13+
714
## [7.18.0](https://github.com/googleapis/nodejs-spanner/compare/v7.17.1...v7.18.0) (2025-01-29)
815

916

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-spanner/tre
143143
| Updates a user-managed instance configuration. | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/instance-config-update.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/instance-config-update.js,samples/README.md) |
144144
| Creates a new instance partition | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/instance-partition-create.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/instance-partition-create.js,samples/README.md) |
145145
| Updates an instance. | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/instance-update.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/instance-update.js,samples/README.md) |
146+
| Creates a instance with asymmetric autoscaling config. | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/instance-with-asymmetric-autoscaling-config.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/instance-with-asymmetric-autoscaling-config.js,samples/README.md) |
146147
| Creates a instance with autoscaling config. | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/instance-with-autoscaling-config.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/instance-with-autoscaling-config.js,samples/README.md) |
147148
| Instance-with-processing-units | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/instance-with-processing-units.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/instance-with-processing-units.js,samples/README.md) |
148149
| Instance | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/instance.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/instance.js,samples/README.md) |

observability-test/transaction.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,14 +501,14 @@ describe('Transaction', () => {
501501
transaction.id = ID;
502502
});
503503

504-
it('error with unset `id`', done => {
504+
it('no error with unset `id`', done => {
505505
const expectedError = new Error(
506506
'Transaction ID is unknown, nothing to rollback.'
507507
);
508508
delete transaction.id;
509509

510510
transaction.rollback(err => {
511-
assert.deepStrictEqual(err, expectedError);
511+
assert.deepStrictEqual(err, null);
512512

513513
const exportResults = extractExportedSpans();
514514
const actualSpanNames = exportResults.spanNames;
@@ -521,7 +521,9 @@ describe('Transaction', () => {
521521
`span names mismatch:\n\tGot: ${actualSpanNames}\n\tWant: ${expectedSpanNames}`
522522
);
523523

524-
const expectedEventNames = [];
524+
const expectedEventNames = [
525+
'Transaction ID is unknown, nothing to rollback.',
526+
];
525527
assert.deepStrictEqual(
526528
actualEventNames,
527529
expectedEventNames,
@@ -532,12 +534,12 @@ describe('Transaction', () => {
532534
const spans = exportResults.spans;
533535
const firstSpan = spans[0];
534536
assert.strictEqual(
535-
SpanStatusCode.ERROR,
537+
SpanStatusCode.UNSET,
536538
firstSpan.status.code,
537-
'Unexpected an span status code'
539+
'Unexpected span status code'
538540
);
539541
assert.strictEqual(
540-
expectedError.message,
542+
undefined,
541543
firstSpan.status.message,
542544
'Unexpected span status message'
543545
);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@google-cloud/spanner",
33
"description": "Cloud Spanner Client Library for Node.js",
4-
"version": "7.18.0",
4+
"version": "7.18.1",
55
"license": "Apache-2.0",
66
"author": "Google Inc.",
77
"engines": {

samples/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ and automatic, synchronous replication for high availability.
6868
* [Updates a user-managed instance configuration.](#updates-a-user-managed-instance-configuration.)
6969
* [Creates a new instance partition](#creates-a-new-instance-partition)
7070
* [Updates an instance.](#updates-an-instance.)
71+
* [Creates a instance with asymmetric autoscaling config.](#creates-a-instance-with-asymmetric-autoscaling-config.)
7172
* [Creates a instance with autoscaling config.](#creates-a-instance-with-autoscaling-config.)
7273
* [Instance-with-processing-units](#instance-with-processing-units)
7374
* [Instance](#instance)
@@ -1067,6 +1068,23 @@ __Usage:__
10671068

10681069

10691070

1071+
### Creates a instance with asymmetric autoscaling config.
1072+
1073+
View the [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/instance-with-asymmetric-autoscaling-config.js).
1074+
1075+
[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/instance-with-asymmetric-autoscaling-config.js,samples/README.md)
1076+
1077+
__Usage:__
1078+
1079+
1080+
`node instance-with-asymmetric-autoscaling-config.js <INSTANCE_ID> <PROJECT_ID>`
1081+
1082+
1083+
-----
1084+
1085+
1086+
1087+
10701088
### Creates a instance with autoscaling config.
10711089

10721090
View the [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/instance-with-autoscaling-config.js).
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
// sample-metadata:
17+
// title: Creates a instance with asymmetric autoscaling config.
18+
// usage: node instance-with-asymmetric-autoscaling-config.js <INSTANCE_ID> <PROJECT_ID>
19+
20+
'use strict';
21+
22+
function main(instanceId = 'my-instance', projectId = 'my-project-id') {
23+
async function createInstanceWithAsymmetricAutoscalingConfig() {
24+
// [START spanner_create_instance_with_asymmetric_autoscaling_config]
25+
// Imports the Google Cloud client library
26+
const {Spanner, protos} = require('@google-cloud/spanner');
27+
28+
/**
29+
* TODO(developer): Uncomment the following lines before running the sample.
30+
*/
31+
// const projectId = 'my-project-id';
32+
// const instanceId = 'my-instance';
33+
34+
// Creates a client
35+
const spanner = new Spanner({
36+
projectId: projectId,
37+
});
38+
39+
// Get the instance admin client
40+
const instanceAdminClient = spanner.getInstanceAdminClient();
41+
42+
const autoscalingConfig =
43+
protos.google.spanner.admin.instance.v1.AutoscalingConfig.create({
44+
// Only one of minNodes/maxNodes or minProcessingUnits/maxProcessingUnits can be set.
45+
autoscalingLimits:
46+
protos.google.spanner.admin.instance.v1.AutoscalingConfig.AutoscalingLimits.create(
47+
{
48+
minNodes: 1,
49+
maxNodes: 2,
50+
}
51+
),
52+
// highPriorityCpuUtilizationPercent and storageUtilizationPercent are both
53+
// percentages and must lie between 0 and 100.
54+
autoscalingTargets:
55+
protos.google.spanner.admin.instance.v1.AutoscalingConfig.AutoscalingTargets.create(
56+
{
57+
highPriorityCpuUtilizationPercent: 65,
58+
storageUtilizationPercent: 95,
59+
}
60+
),
61+
// The read-only replicas listed in the asymmetric autoscaling options scale independently
62+
// from other replicas.
63+
asymmetricAutoscalingOptions: [
64+
protos.google.spanner.admin.instance.v1.AutoscalingConfig.AsymmetricAutoscalingOption.create(
65+
{
66+
replicaSelection:
67+
protos.google.spanner.admin.instance.v1.ReplicaSelection.create(
68+
{
69+
location: 'europe-west1',
70+
}
71+
),
72+
}
73+
),
74+
protos.google.spanner.admin.instance.v1.AutoscalingConfig.AsymmetricAutoscalingOption.create(
75+
{
76+
replicaSelection:
77+
protos.google.spanner.admin.instance.v1.ReplicaSelection.create(
78+
{
79+
location: 'europe-west4',
80+
}
81+
),
82+
}
83+
),
84+
protos.google.spanner.admin.instance.v1.AutoscalingConfig.AsymmetricAutoscalingOption.create(
85+
{
86+
replicaSelection:
87+
protos.google.spanner.admin.instance.v1.ReplicaSelection.create(
88+
{
89+
location: 'asia-east1',
90+
}
91+
),
92+
}
93+
),
94+
],
95+
});
96+
97+
// Creates a new instance with autoscaling configuration and asymmetric autoscaling option
98+
// When autoscalingConfig is enabled, nodeCount and processingUnits fields
99+
// need not be specified.
100+
try {
101+
console.log(
102+
`Creating instance ${instanceAdminClient.instancePath(
103+
projectId,
104+
instanceId
105+
)}.`
106+
);
107+
const [operation] = await instanceAdminClient.createInstance({
108+
instanceId: instanceId,
109+
parent: instanceAdminClient.projectPath(projectId),
110+
instance: {
111+
config: instanceAdminClient.instanceConfigPath(
112+
projectId,
113+
'nam-eur-asia3'
114+
),
115+
displayName: 'Display name for the instance.',
116+
autoscalingConfig: autoscalingConfig,
117+
labels: {
118+
cloud_spanner_samples: 'true',
119+
created: Math.round(Date.now() / 1000).toString(), // current time
120+
},
121+
// Feature MULTI_REGION is available only for ENTERPRISE_PLUS edition
122+
edition:
123+
protos.google.spanner.admin.instance.v1.Instance.Edition
124+
.ENTERPRISE_PLUS,
125+
},
126+
});
127+
128+
console.log(`Waiting for operation on ${instanceId} to complete...`);
129+
await operation.promise();
130+
console.log(`Created instance ${instanceId}.`);
131+
132+
// get instance metadata
133+
const [metadata] = await instanceAdminClient.getInstance({
134+
name: instanceAdminClient.instancePath(projectId, instanceId),
135+
});
136+
console.log(
137+
`Autoscaling configurations of ${instanceId} are: ` +
138+
'\n' +
139+
`Min nodes: ${metadata.autoscalingConfig.autoscalingLimits.minNodes} ` +
140+
'nodes.' +
141+
'\n' +
142+
`Max nodes: ${metadata.autoscalingConfig.autoscalingLimits.maxNodes}` +
143+
' nodes.' +
144+
'\n' +
145+
`High priority cpu utilization percent: ${metadata.autoscalingConfig.autoscalingTargets.highPriorityCpuUtilizationPercent}.` +
146+
'\n' +
147+
`Storage utilization percent: ${metadata.autoscalingConfig.autoscalingTargets.storageUtilizationPercent}.` +
148+
'\n' +
149+
`Asymmetric Autoscaling Options: ${
150+
metadata.autoscalingConfig.asymmetricAutoscalingOptions &&
151+
metadata.autoscalingConfig.asymmetricAutoscalingOptions.length > 0
152+
? metadata.autoscalingConfig.asymmetricAutoscalingOptions
153+
.map(option =>
154+
option.replicaSelection && option.replicaSelection.location
155+
? option.replicaSelection.location
156+
: 'N/A'
157+
)
158+
.join(', ')
159+
: 'None'
160+
}`
161+
);
162+
} catch (err) {
163+
console.error('ERROR:', err);
164+
}
165+
// [END spanner_create_instance_with_asymmetric_autoscaling_config]
166+
}
167+
createInstanceWithAsymmetricAutoscalingConfig();
168+
}
169+
170+
process.on('unhandledRejection', err => {
171+
console.error(err.message);
172+
process.exitCode = 1;
173+
});
174+
main(...process.argv.slice(2));

samples/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"dependencies": {
1818
"@google-cloud/kms": "^4.0.0",
1919
"@google-cloud/precise-date": "^4.0.0",
20-
"@google-cloud/spanner": "^7.18.0",
20+
"@google-cloud/spanner": "^7.18.1",
2121
"protobufjs": "^7.0.0",
2222
"yargs": "^17.0.0"
2323
},

samples/system-test/spanner.test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,41 @@ describe('Autogenerated Admin Clients', () => {
379379
)
380380
);
381381
});
382+
383+
// create_instance_with_asymmetric_autoscaling_config
384+
it('should create an example instance with autoscaling config and asymmetric Autoscaling Options', async () => {
385+
const output = execSync(
386+
`node instance-with-asymmetric-autoscaling-config.js "${SAMPLE_INSTANCE_ID}" ${PROJECT_ID}`
387+
);
388+
assert.match(
389+
output,
390+
new RegExp(
391+
`Waiting for operation on ${SAMPLE_INSTANCE_ID} to complete...`
392+
)
393+
);
394+
assert.match(
395+
output,
396+
new RegExp(`Created instance ${SAMPLE_INSTANCE_ID}.`)
397+
);
398+
assert.match(
399+
output,
400+
new RegExp(
401+
`Autoscaling configurations of ${SAMPLE_INSTANCE_ID} are: ` +
402+
'\n' +
403+
'Min nodes: 1 ' +
404+
'nodes.' +
405+
'\n' +
406+
'Max nodes: 2' +
407+
' nodes.' +
408+
'\n' +
409+
'High priority cpu utilization percent: 65.' +
410+
'\n' +
411+
'Storage utilization percent: 95.' +
412+
'\n' +
413+
'Asymmetric Autoscaling Options: europe-west1, europe-west4, asia-east1'
414+
)
415+
);
416+
});
382417
});
383418

384419
// check that base instance was created

src/transaction.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2517,12 +2517,9 @@ export class Transaction extends Dml {
25172517
};
25182518
return startTrace('Transaction.rollback', traceConfig, span => {
25192519
if (!this.id) {
2520-
const err = new Error(
2521-
'Transaction ID is unknown, nothing to rollback.'
2522-
) as ServiceError;
2523-
setSpanError(span, err);
2520+
span.addEvent('Transaction ID is unknown, nothing to rollback.');
25242521
span.end();
2525-
callback!(err);
2522+
callback(null);
25262523
return;
25272524
}
25282525

test/transaction.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,15 +1975,10 @@ describe('Transaction', () => {
19751975
transaction.id = ID;
19761976
});
19771977

1978-
it('should return an error if the `id` is not set', done => {
1979-
const expectedError = new Error(
1980-
'Transaction ID is unknown, nothing to rollback.'
1981-
);
1982-
1978+
it('should not return an error if the `id` is not set', done => {
19831979
delete transaction.id;
1984-
19851980
transaction.rollback(err => {
1986-
assert.deepStrictEqual(err, expectedError);
1981+
assert.deepStrictEqual(err, null);
19871982
done();
19881983
});
19891984
});

0 commit comments

Comments
 (0)