Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(spanner): add maxCommitDelay support #1992

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export interface RequestOptions {
export interface CommitOptions {
requestOptions?: Pick<IRequestOptions, 'priority'>;
returnCommitStats?: boolean;
maxCommitDelay?: spannerClient.protobuf.IDuration;
gaxOptions?: CallOptions;
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion test/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading