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

fix: read time should be used for transaction reads #1171

Merged

Conversation

danieljbruce
Copy link
Contributor

@danieljbruce danieljbruce commented Oct 13, 2023

Right now, read calls with a transaction do not use the provided snapshot read time. The code change in src ensures that read options always gets passed along to the Gapic layer. Read options contain the read time so ensuring read options are passed along to the gapic layer ensures that read time is passed along to the gapic layer and sent in the grpc call to be used.

A separate unit test file was created for the test because all of the current unit test files have mocks that we don't want to use. Mocking out functions in the Gapic layer is becoming a common use case so we create a file that allows us to mock out runQuery for each test and write a test there with the intention of writing more tests there in the future.

Latency is caused by the call to getProjectId from Google auth. This change allows the project id to be retrieved if it is set in the client at creation time thereby reducing call latency.
A test file is created where we mock out commit in the Gapic layer. The mock allows us to get the results passed to the commit endpoint in the Gapic layer.
To prove that the change works to reduce latency, a test is written. The test checks to see that the amount of time that passes between the time when the initial call is made in the user’s code and the time when the call reaches the gapic layer is sufficiently small. It will be a very small amount of time if the program does not need to do an auth lookup.
Run the linter so that spacing in the PR gets fixed for some of the lines of code.
The license header needs to be added to the top of the new test file that is used for mocking out commit.
This is going to be a test for investigating the latency of the client.
Measure the latency between the original call and the mock server.
Do check external to function after async call. Add log for call time.
Other mock doesn’t require lazy client initialization.
Eliminate the fake datastore client because we need to do assertion checks that are specific to each test. This means there is no point in defining runQuery once in a mock because each test will mock it out differently.
Add the code change that will add read time to read options for transactions.

# Conflicts:
#	test/transaction.ts
The idea is to test that read time got passed along for transactions specifically. This will be necessary for snapshot reads to work.
Need the entire test suite to run
The before hook is not necessary. Just mock out the data client at the start.
@product-auto-label product-auto-label bot added size: l Pull request size is large. api: datastore Issues related to the googleapis/nodejs-datastore API. labels Oct 13, 2023
@danieljbruce danieljbruce changed the title fix: Not use read time for run tx fix: read time should be used for transaction reads Oct 13, 2023
Files were cherry-picked that weren’t helpful for solving the problem. Remove them.
@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: l Pull request size is large. labels Oct 13, 2023
Right now, providing a transaction id is necessary to run the request as a transaction.
The integration test looks at the data from the snapshot read time for transactions and ensures that the read has no data thereby exercising the read time parameter.
…into not-use-read-time-for-run-tx

# Conflicts:
#	system-test/datastore.ts
@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Oct 30, 2023
Fix the indents in the system test folder
@product-auto-label product-auto-label bot removed the size: l Pull request size is large. label Oct 30, 2023
@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Oct 30, 2023
danieljbruce and others added 7 commits April 4, 2024 10:46
beginTransaction needs to be mocked out now that a transaction will begin if runQuery is called.
Add a sleep. Instead of changing the current test, add a new test because it means the reader of the PR can be sure that test coverage wasn’t reduced which is better.
Modify the test so that sleeps are long enough to create predictable results and tests actually check for the right values.
The test setup sometimes prepares before data with 0 entries and sometimes prepares before data with 1 entry so a less restrictive test is required in order for it to consistently pass.
@danieljbruce danieljbruce added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 4, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 4, 2024
@danieljbruce danieljbruce added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 4, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 4, 2024
@danieljbruce danieljbruce marked this pull request as ready for review April 4, 2024 19:08
@danieljbruce danieljbruce requested review from a team as code owners April 4, 2024 19:08
@danieljbruce danieljbruce added the owlbot:run Add this label to trigger the Owlbot post processor. label Apr 4, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Apr 4, 2024
@danieljbruce danieljbruce merged commit 73a0a39 into googleapis:main Apr 4, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the googleapis/nodejs-datastore API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants