Skip to content
This repository was archived by the owner on Oct 20, 2026. It is now read-only.

Commit ba45693

Browse files
committed
feat: Added support for partitioned dml
1 parent 66e7a5f commit ba45693

8 files changed

Lines changed: 42 additions & 45 deletions

File tree

‎samples/directed-reads.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function main(
7373
.Type.READ_ONLY,
7474
},
7575
],
76-
autoFailover: true,
76+
autoFailoverDisabled: true,
7777
},
7878
};
7979

‎src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export type GetInstanceConfigOperationsCallback = PagedCallback<
112112
* Disabling leader aware routing would route all requests in RW/PDML transactions to any region.
113113
* @property {google.spanner.v1.IDirectedReadOptions} [directedReadOptions] Sets the DirectedReadOptions for all ReadRequests and ExecuteSqlRequests for the Client.
114114
* Indicates which replicas or regions should be used for non-transactional reads or queries.
115-
* DirectedReadOptions won't be set for readWrite transactions or partitioned dml requests"
115+
* DirectedReadOptions won't be set for readWrite transactions"
116116
*/
117117
export interface SpannerOptions extends GrpcClientOptions {
118118
apiEndpoint?: string;

‎src/transaction.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,7 @@ export class Snapshot extends EventEmitter {
13361336
if (
13371337
!directedReadOptions &&
13381338
this._getSpanner().directedReadOptions &&
1339-
!this._options.readWrite
1339+
this._options.readOnly
13401340
) {
13411341
return this._getSpanner().directedReadOptions;
13421342
}

‎system-test/spanner.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7113,7 +7113,7 @@ describe('Spanner', () => {
71137113
.ReplicaSelection.Type.READ_ONLY,
71147114
},
71157115
],
7116-
autoFailover: true,
7116+
autoFailoverDisabled: true,
71177117
},
71187118
};
71197119

@@ -8717,7 +8717,7 @@ describe('Spanner', () => {
87178717
.ReplicaSelection.Type.READ_WRITE,
87188718
},
87198719
],
8720-
autoFailover: true,
8720+
autoFailoverDisabled: true,
87218721
},
87228722
};
87238723

‎test/batch-transaction.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import * as proxyquire from 'proxyquire';
2525
import * as sinon from 'sinon';
2626

2727
import {Session, Database, Spanner} from '../src';
28+
import {protos} from '../src';
2829
import * as bt from '../src/batch-transaction';
2930
import {PartialResultStream} from '../src/partial-result-stream';
3031
import {
@@ -144,19 +145,35 @@ describe('BatchTransaction', () => {
144145

145146
describe('createQueryPartitions', () => {
146147
const GAX_OPTS = {a: 'b'};
148+
149+
const fakeDirectedReadOptionsForRequest = {
150+
includeReplicas: {
151+
replicaSelections: [
152+
{
153+
location: 'us-west1',
154+
type: protos.google.spanner.v1.DirectedReadOptions.ReplicaSelection
155+
.Type.READ_WRITE,
156+
},
157+
],
158+
autoFailoverDisabled: true,
159+
},
160+
};
161+
147162
const QUERY = {
148163
sql: 'SELECT * FROM Singers',
149164
gaxOptions: GAX_OPTS,
150165
params: {},
151166
types: {},
152167
dataBoostEnabled: true,
168+
directedReadOptions: fakeDirectedReadOptionsForRequest
153169
};
154170

155171
it('should make the correct request', () => {
156172
const fakeParams = {
157173
params: {a: 'b'},
158174
paramTypes: {a: 'string'},
159175
dataBoostEnabled: true,
176+
directedReadOptions: fakeDirectedReadOptionsForRequest
160177
};
161178

162179
const expectedQuery = Object.assign({sql: QUERY.sql}, fakeParams);
@@ -301,12 +318,27 @@ describe('BatchTransaction', () => {
301318

302319
describe('createReadPartitions', () => {
303320
const GAX_OPTS = {};
321+
322+
const fakeDirectedReadOptionsForRequest = {
323+
includeReplicas: {
324+
replicaSelections: [
325+
{
326+
location: 'us-west1',
327+
type: protos.google.spanner.v1.DirectedReadOptions.ReplicaSelection
328+
.Type.READ_WRITE,
329+
},
330+
],
331+
autoFailoverDisabled: true,
332+
},
333+
};
334+
304335
const QUERY = {
305336
table: 'abc',
306337
keys: ['a', 'b'],
307338
ranges: [{}, {}],
308339
gaxOptions: GAX_OPTS,
309340
dataBoostEnabled: true,
341+
directedReadOptions: fakeDirectedReadOptionsForRequest
310342
};
311343

312344
it('should make the correct request', () => {
@@ -315,6 +347,7 @@ describe('BatchTransaction', () => {
315347
table: QUERY.table,
316348
keySet: fakeKeySet,
317349
dataBoostEnabled: true,
350+
directedReadOptions: fakeDirectedReadOptionsForRequest
318351
};
319352

320353
const stub = sandbox.stub(batchTransaction, 'createPartitions_');

‎test/database.ts‎

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,7 +2463,7 @@ describe('Database', () => {
24632463
.Type.READ_WRITE,
24642464
},
24652465
],
2466-
autoFailover: true,
2466+
autoFailoverDisabled: true,
24672467
},
24682468
};
24692469

@@ -2582,19 +2582,9 @@ describe('Database', () => {
25822582
assert.ok(fakeCallback.calledOnce);
25832583
});
25842584

2585-
it('should override directedReadOptions set for client when passed', () => {
2585+
it('should ignore directedReadOptions set for client', () => {
25862586
const fakeCallback = sandbox.spy();
25872587

2588-
const fakeDirectedReadOptionsForRequest = {
2589-
includeReplicas: {
2590-
replicaSelections: [
2591-
{
2592-
location: 'us-east1',
2593-
},
2594-
],
2595-
},
2596-
};
2597-
25982588
database.parent.parent = {
25992589
routeToLeaderEnabled: true,
26002590
directedReadOptions: fakeDirectedReadOptions,
@@ -2605,31 +2595,6 @@ describe('Database', () => {
26052595
sql: QUERY.sql,
26062596
params: QUERY.params,
26072597
requestOptions: {priority: RequestOptions.Priority.PRIORITY_LOW},
2608-
directedReadOptions: fakeDirectedReadOptionsForRequest,
2609-
},
2610-
fakeCallback
2611-
);
2612-
2613-
const [query] = runUpdateStub.lastCall.args;
2614-
2615-
assert.deepStrictEqual(query, {
2616-
sql: QUERY.sql,
2617-
params: QUERY.params,
2618-
requestOptions: {priority: RequestOptions.Priority.PRIORITY_LOW},
2619-
directedReadOptions: fakeDirectedReadOptionsForRequest,
2620-
});
2621-
assert.ok(fakeCallback.calledOnce);
2622-
});
2623-
2624-
it('should accept requestOptions for client', () => {
2625-
const fakeCallback = sandbox.spy();
2626-
2627-
database.runPartitionedUpdate(
2628-
{
2629-
sql: QUERY.sql,
2630-
params: QUERY.params,
2631-
requestOptions: {priority: RequestOptions.Priority.PRIORITY_LOW},
2632-
directedReadOptions: fakeDirectedReadOptions,
26332598
},
26342599
fakeCallback
26352600
);
@@ -2640,7 +2605,6 @@ describe('Database', () => {
26402605
sql: QUERY.sql,
26412606
params: QUERY.params,
26422607
requestOptions: {priority: RequestOptions.Priority.PRIORITY_LOW},
2643-
directedReadOptions: fakeDirectedReadOptions,
26442608
});
26452609
assert.ok(fakeCallback.calledOnce);
26462610
});

‎test/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ describe('Spanner', () => {
292292
.ReplicaSelection.Type.READ_ONLY,
293293
},
294294
],
295-
autoFailover: true,
295+
autoFailoverDisabled: true,
296296
},
297297
};
298298

‎test/transaction.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('Transaction', () => {
7777
.Type.READ_ONLY,
7878
},
7979
],
80-
autoFailover: true,
80+
autoFailoverDisabled: true,
8181
},
8282
};
8383

0 commit comments

Comments
 (0)