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: add async api #81

Merged
merged 59 commits into from Jun 30, 2020
Merged

feat: add async api #81

merged 59 commits into from Jun 30, 2020

Conversation

olavloite
Copy link
Contributor

@olavloite olavloite commented Feb 21, 2020

Adds an async API to the Spanner client library. Most notable changes:

All calls to the session pool are now non-blocking

This also applies to the current API, which means that the following statements will always be non-blocking, regardless whether a session was already available in the session pool or not:

Database client = spanner.getDatabaseClient(...);
ResultSet rs = client.singleUse().executeQuery(Statement.Of("SELECT 1"));

Instead, the first call to ResultSet#next() will be blocking:

  1. It will potentially block until a session could be returned from the pool.
  2. It will block until the executeStreamingSql call has returned the first results.

Adds Async methods to ReadContext

The ReadContext interface is extended with the following methods:

  • readAsync(...)
  • readUsingIndexAsync(...)
  • executeQueryAsync(...)
  • readRowAsync(...)
  • readRowUsingIndexAsync(...)

The first three of the above methods return an AsyncResultSet. AsyncResultSet is an extension of the existing ResultSet interface that allows the user to register a callback that will be called asynchronously for each row in the result set.

The latter two methods return instances of ApiFuture<Struct>.

Point for discussion:
It would also be possible to add the setCallback(...) method to the existing ResultSet interface instead of creating an additional AsyncResultSet interface. That would mean that we would not need to add the -Async methods above. Instead, all ResultSets could be consumed asynchronously by calling the setCallback(...) method.

Adds AsyncRunner

The method DatabaseClient#runAsync() is added which returns an AsyncRunner. This runner can be used to execute a read/write transaction asynchronously.

@olavloite olavloite added do not merge api: spanner labels Feb 21, 2020
@googlebot googlebot added the cla: yes label Feb 21, 2020
@olavloite olavloite force-pushed the async-api branch 2 times, most recently from 987b77f to 80d023a Compare Feb 28, 2020
@olavloite olavloite added the kokoro:force-run label Mar 1, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run label Mar 1, 2020
@olavloite olavloite requested a review from elefeint Jun 21, 2020
@olavloite
Copy link
Contributor Author

@olavloite olavloite commented Jun 21, 2020

@elefeint I've processed all your review comments, and now also added support for an AsyncTransactionManager. This again will be used to create async support for the connection API. I suggest we do that in a separate PR, as this PR is already huge.

@skuruppu
Copy link
Contributor

@skuruppu skuruppu commented Jun 30, 2020

Thanks very much for the review @elefeint and @dzou. @olavloite please merge this in when you're ready.

@olavloite olavloite merged commit 462839b into master Jun 30, 2020
23 checks passed
@olavloite olavloite deleted the async-api branch Jun 30, 2020
gcf-merge-on-green bot pushed a commit that referenced this issue Jul 7, 2020
/**
* Returns the {@link ExecutorProvider} to use for async methods that need a background executor.
*/
public ExecutorProvider getAsyncExecutorProvider() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do we set asyncExecutorProvider?

Copy link
Contributor Author

@olavloite olavloite Jun 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's currently not configurable, and it will automatically use the default provided here:

static CloseableExecutorProvider createDefaultAsyncExecutorProvider() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the quick reply Knut Olav .
Is there a plan to make it configurable?

Copy link
Contributor Author

@olavloite olavloite Jun 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no concrete plan for it, but this feels like an omission to me. Would you mind submitting a feature request here: https://github.com/googleapis/java-spanner/issues/new?assignees=&labels=&template=feature_request.md

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks so much.
just created this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner cla: yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants