diff --git a/src/index.ts b/src/index.ts index 76eccc6b3..558382ba7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -108,8 +108,8 @@ export type GetInstanceConfigOperationsCallback = PagedCallback< /** * Session pool configuration options. - * @property {boolean} [routeToLeaderEnabled=True] If set to false leader aware routing will be disabled. - * Disabling leader aware routing would route all requests in RW/PDML transactions to any region. + * @property {boolean} [routeToLeaderEnabled=False] If set to true leader aware routing will be enabled. + * Enabling leader aware routing would route all requests in RW/PDML transactions to leader region. */ export interface SpannerOptions extends GrpcClientOptions { apiEndpoint?: string; @@ -216,7 +216,7 @@ class Spanner extends GrpcService { projectIdReplaced_: boolean; projectFormattedName_: string; resourceHeader_: {[k: string]: string}; - routeToLeaderEnabled = true; + routeToLeaderEnabled = false; /** * Placeholder used to auto populate a column with the commit timestamp. @@ -318,8 +318,8 @@ class Spanner extends GrpcService { } as {} as GrpcServiceConfig; super(config, options); - if (options.routeToLeaderEnabled === false) { - this.routeToLeaderEnabled = false; + if (options.routeToLeaderEnabled === true) { + this.routeToLeaderEnabled = true; } this.options = options; diff --git a/test/spanner.ts b/test/spanner.ts index 2ca4697f0..322566389 100644 --- a/test/spanner.ts +++ b/test/spanner.ts @@ -1491,14 +1491,14 @@ describe('Spanner with mock server', () => { }); describe('LeaderAwareRouting', () => { - let spannerWithLARDisabled: Spanner; - let instanceWithLARDisabled: Instance; + let spannerWithLAREnabled: Spanner; + let instanceWithLAREnabled: Instance; - function newTestDatabaseWithLARDisabled( + function newTestDatabaseWithLAREnabled( options?: SessionPoolOptions, queryOptions?: IQueryOptions ): Database { - return instanceWithLARDisabled.database( + return instanceWithLAREnabled.database( `database-${dbCounter++}`, options, queryOptions @@ -1506,18 +1506,18 @@ describe('Spanner with mock server', () => { } before(() => { - spannerWithLARDisabled = new Spanner({ + spannerWithLAREnabled = new Spanner({ servicePath: 'localhost', port, sslCreds: grpc.credentials.createInsecure(), - routeToLeaderEnabled: false, + routeToLeaderEnabled: true, }); // Gets a reference to a Cloud Spanner instance and database - instanceWithLARDisabled = spannerWithLARDisabled.instance('instance'); + instanceWithLAREnabled = spannerWithLAREnabled.instance('instance'); }); it('should execute with leader aware routing enabled in a read/write transaction', async () => { - const database = newTestDatabase(); + const database = newTestDatabaseWithLAREnabled(); await database.runTransactionAsync(async tx => { await tx!.runUpdate({ sql: insertSql, @@ -1539,7 +1539,7 @@ describe('Spanner with mock server', () => { }); it('should execute with leader aware routing disabled in a read/write transaction', async () => { - const database = newTestDatabaseWithLARDisabled(); + const database = newTestDatabase(); await database.runTransactionAsync(async tx => { await tx!.runUpdate({ sql: insertSql,