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

chore: Improve error message for Read-only transaction with bounded staleness #2207

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c62584c
chore: integration test fix
surbhigarg92 Jan 11, 2024
e7d385b
Merge branch 'googleapis:main' into main
surbhigarg92 Mar 4, 2024
e57b897
Merge branch 'googleapis:main' into main
surbhigarg92 Mar 4, 2024
c0c935e
Merge branch 'googleapis:main' into main
surbhigarg92 Mar 8, 2024
8875f2c
Merge branch 'googleapis:main' into main
surbhigarg92 Mar 26, 2024
a903eec
Merge branch 'googleapis:main' into main
surbhigarg92 Apr 9, 2024
50914dc
Merge branch 'googleapis:main' into main
surbhigarg92 Jun 17, 2024
95aa578
Merge branch 'googleapis:main' into main
surbhigarg92 Jun 26, 2024
738804b
Merge branch 'googleapis:main' into main
surbhigarg92 Jul 3, 2024
b53a82f
Merge branch 'googleapis:main' into main
surbhigarg92 Jul 31, 2024
eb858ac
Merge branch 'googleapis:main' into main
surbhigarg92 Aug 6, 2024
163699b
Merge branch 'googleapis:main' into main
surbhigarg92 Aug 8, 2024
0f6fda3
Merge branch 'googleapis:main' into main
surbhigarg92 Sep 23, 2024
4b173ba
Merge branch 'googleapis:main' into main
surbhigarg92 Sep 30, 2024
4261105
Merge branch 'googleapis:main' into main
surbhigarg92 Oct 10, 2024
6a77a21
Merge branch 'googleapis:main' into main
surbhigarg92 Oct 21, 2024
c597b74
Merge remote-tracking branch 'upstream/main'
surbhigarg92 Oct 21, 2024
56df6b4
Merge branch 'googleapis:main' into main
surbhigarg92 Oct 22, 2024
bd4647c
Merge branch 'googleapis:main' into main
surbhigarg92 Oct 24, 2024
4b2f196
Merge branch 'googleapis:main' into main
surbhigarg92 Oct 28, 2024
207b382
Merge branch 'googleapis:main' into main
surbhigarg92 Oct 30, 2024
e3b4394
Merge branch 'googleapis:main' into main
surbhigarg92 Nov 7, 2024
22b1c5d
Merge branch 'googleapis:main' into main
surbhigarg92 Nov 8, 2024
fb26cc4
Merge branch 'googleapis:main' into main
surbhigarg92 Nov 11, 2024
02c4c1f
Merge branch 'googleapis:main' into main
surbhigarg92 Nov 12, 2024
9f4e1e8
chore: Improve error message for Read-only transaction with bounded s…
surbhigarg92 Dec 24, 2024
0674b8a
Merge branch 'main' into ro_boundedstaleness
surbhigarg92 Dec 24, 2024
2f4b07e
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Dec 24, 2024
65fd842
Merge branch 'main' into ro_boundedstaleness
surbhigarg92 Dec 24, 2024
9805c4d
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Dec 24, 2024
dba262c
Merge branch 'ro_boundedstaleness' of https://github.com/googleapis/n…
gcf-owl-bot[bot] Dec 24, 2024
7097697
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Dec 24, 2024
699656d
Merge branch 'ro_boundedstaleness' of https://github.com/googleapis/n…
gcf-owl-bot[bot] Dec 24, 2024
db2938b
review comments
surbhigarg92 Dec 26, 2024
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
13 changes: 13 additions & 0 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
LongRunningCallback,
NormalCallback,
PagedOptionsWithFilter,
CLOUD_RESOURCE_HEADER,

Check warning on line 88 in src/database.ts

View workflow job for this annotation

GitHub Actions / lint

'CLOUD_RESOURCE_HEADER' is defined but never used
PagedResponse,
RequestCallback,
ResourceCallback,
Expand Down Expand Up @@ -2095,6 +2095,19 @@
? (optionsOrCallback as TimestampBounds)
: {};

if (options !=null && (options['maxStaleness'] != null || options['minReadTimestamp'] != null)) {

Check failure on line 2098 in src/database.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `options·!=null·&&·(options['maxStaleness']·!=·null·||·options['minReadTimestamp']·!=·null)` with `⏎······options·!=·null·&&⏎······(options['maxStaleness']·!=·null·||·options['minReadTimestamp']·!=·null)⏎····`

Check failure on line 2098 in src/database.ts

View workflow job for this annotation

GitHub Actions / lint

Expected '!==' and instead saw '!='

Check failure on line 2098 in src/database.ts

View workflow job for this annotation

GitHub Actions / lint

Expected '!==' and instead saw '!='

Check failure on line 2098 in src/database.ts

View workflow job for this annotation

GitHub Actions / lint

Expected '!==' and instead saw '!='
const error = Object.assign(
new Error(
'maxStaleness / minReadTimestamp is not supported for multi-use read-only transactions.'
),
{
code: 3, // invalid argument
}
) as ServiceError;
callback!(error);
return;
}

return startTrace('Database.getSnapshot', this._traceConfig, span => {
this.pool_.getSession((err, session) => {
if (err) {
Expand Down
33 changes: 33 additions & 0 deletions test/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2307,6 +2307,39 @@ describe('Database', () => {
assert.strictEqual(bounds, fakeTimestampBounds);
});

it('should throw error if maxStaleness is passed in the timestamp bounds to the snapshot', () => {
const fakeTimestampBounds = {maxStaleness: 10};
surbhigarg92 marked this conversation as resolved.
Show resolved Hide resolved

database.getSnapshot(fakeTimestampBounds, err => {
assert.strictEqual(err.code, 3);
assert.strictEqual(
err.message,
'maxStaleness / minReadTimestamp is not supported for multi-use read-only transactions.'
);
});
});

it('should throw error if minReadTimestamp is passed in the timestamp bounds to the snapshot', () => {
const fakeTimestampBounds = {minReadTimestamp: 10};

database.getSnapshot(fakeTimestampBounds, err => {
assert.strictEqual(err.code, 3);
assert.strictEqual(
err.message,
'maxStaleness / minReadTimestamp is not supported for multi-use read-only transactions.'
);
});
});

it('should pass when maxStaleness is undefined', () => {
const fakeTimestampBounds = {minReadTimestamp: undefined};

database.getSnapshot(fakeTimestampBounds, assert.ifError);

const bounds = snapshotStub.lastCall.args[0];
assert.strictEqual(bounds, fakeTimestampBounds);
});

it('should begin a snapshot', () => {
beginSnapshotStub.callsFake(() => {});

Expand Down
Loading