From 9f8440843fd8926a37ec300a318dad33b83b4f97 Mon Sep 17 00:00:00 2001 From: nginsberg-google <131713109+nginsberg-google@users.noreply.github.com> Date: Thu, 8 Feb 2024 00:10:16 -0800 Subject: [PATCH] feat(spanner): add maxCommitDelay support (#1992) maxCommitDelays allows the user to specify the maximum delay a commit request is willing to incur in order to improve throughput. This PR adds support for the feature in the commit API. --- src/transaction.ts | 10 ++++++++++ test/transaction.ts | 9 ++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/transaction.ts b/src/transaction.ts index 555433478..11eb03657 100644 --- a/src/transaction.ts +++ b/src/transaction.ts @@ -69,6 +69,7 @@ export interface RequestOptions { export interface CommitOptions { requestOptions?: Pick; returnCommitStats?: boolean; + maxCommitDelay?: spannerClient.protobuf.IDuration; gaxOptions?: CallOptions; } @@ -1798,6 +1799,9 @@ export class Transaction extends Dml { * with the commit request. * @property {boolean} returnCommitStats Include statistics related to the * transaction in the {@link CommitResponse}. + * @property {spannerClient.proto.IDuration} maxCommitDelay Maximum amount + * of delay the commit is willing to incur in order to improve + * throughput. Value should be between 0ms and 500ms. * @property {object} [gaxOptions] The request configuration options, * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} * for more details. @@ -1888,6 +1892,12 @@ export class Transaction extends Dml { ) { reqOpts.returnCommitStats = (options as CommitOptions).returnCommitStats; } + if ( + 'maxCommitDelay' in options && + (options as CommitOptions).maxCommitDelay + ) { + reqOpts.maxCommitDelay = (options as CommitOptions).maxCommitDelay; + } reqOpts.requestOptions = Object.assign( requestOptions || {}, this.requestOptions diff --git a/test/transaction.ts b/test/transaction.ts index 36d8c6988..11a8647e0 100644 --- a/test/transaction.ts +++ b/test/transaction.ts @@ -1633,7 +1633,14 @@ describe('Transaction', () => { }); it('should accept commit options', done => { - const options = {returnCommitStats: true}; + const maxCommitDelay = new google.protobuf.Duration({ + seconds: 0, // 0 seconds + nanos: 100000000, // 100,000,000 nanoseconds = 100 milliseconds + }); + const options = { + returnCommitStats: true, + maxCommitDelay: maxCommitDelay, + }; transaction.request = config => { assert.strictEqual(config.reqOpts.returnCommitStats, true); done();