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: async connection api #290

Closed
wants to merge 59 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
e5e8df8
feat: add async api
olavloite Feb 20, 2020
c7db649
feat: session pool is non-blocking
olavloite Feb 23, 2020
e485709
tests: fix integration tests that assumed tx was blocking
olavloite Feb 24, 2020
e3ebeb3
feat: add read methods support
olavloite Feb 25, 2020
54629ad
tests: test async runner
olavloite Feb 25, 2020
8a10b64
feat: create async runner
olavloite Feb 25, 2020
91253cf
tests: centralize some commonly used test objects
olavloite Feb 26, 2020
a2d28cd
feat: keep session checked out until async finishes
olavloite Feb 26, 2020
2a63e62
fix: fix span test cases after rebase
olavloite Feb 26, 2020
9d58bc3
fix: fix async runner tests
olavloite Feb 27, 2020
4f79632
fix: make async runner wait for async operations
olavloite Feb 28, 2020
cfd1802
examples: add example integration test
olavloite Feb 28, 2020
a2e28a5
examples: add more examples
olavloite Feb 28, 2020
fa61e7d
tests: fix flaky tests
olavloite Feb 28, 2020
fc53dbf
rebase: rebase on current master
olavloite Mar 16, 2020
0eee1f6
fix: run code formatter
olavloite Mar 20, 2020
d3d2ffc
feat: add support for poller
olavloite Mar 23, 2020
2e01ca7
tests: support more param types
olavloite Apr 2, 2020
5e63f2b
fix: fix race conditions
olavloite Apr 8, 2020
abe455e
feat: return ApiFuture to monitor end of AsyncResultSet
olavloite Apr 9, 2020
cc091e8
feat: add helper method for create test result sets
olavloite Apr 19, 2020
944c701
merge: merge latest changes from master
olavloite Apr 21, 2020
d75f979
feat: add batchUpdateAsync
olavloite Apr 21, 2020
7f06e84
fix: add ignored interface differences
olavloite Apr 26, 2020
c1b0615
merge: merge master into async branch
olavloite Apr 26, 2020
00b83d2
refactor: use future as waiter in SessionPool
olavloite Apr 26, 2020
2ea27d7
Merge branch 'master' into async-api
olavloite Apr 27, 2020
17fb940
merge: merge with latest from master
olavloite Apr 29, 2020
51b5113
format: run code formatter
olavloite Apr 29, 2020
a03380b
tests: fix test case + remove commented code
olavloite Apr 29, 2020
8bc3a13
fix: AsyncResultSet should throw Cancelled
olavloite Apr 29, 2020
0927957
Merge branch 'master' into async-api
olavloite May 6, 2020
e486c54
feat: expose DatabaseId.of(String name)
olavloite May 11, 2020
a7dd1dd
deps: set version to 1.53 to match bom
olavloite May 12, 2020
c662ed7
feat: steps to add async support for tx manager
olavloite Jun 9, 2020
226f91b
review: process review comments
olavloite Jun 11, 2020
a10b61c
fix: run formatter
olavloite Jun 11, 2020
64b8a34
chore: remove unused code
olavloite Jun 11, 2020
3354344
clirr: add ignored differences to clirr
olavloite Jun 11, 2020
2b2a6a4
Merge branch 'master' into async-api
olavloite Jun 12, 2020
1fada1c
fix: call listeners after all rows have been consumed
olavloite Jun 12, 2020
35743e6
feat: towards AsyncTransactionManager
olavloite Jun 12, 2020
48de42e
Merge branch 'master' into async-api
olavloite Jun 13, 2020
888edd8
fix: session leaks + code format
olavloite Jun 13, 2020
b2a7176
fix: more session leak fixes
olavloite Jun 13, 2020
fba270f
feat: further work on AsyncTransactionManager
olavloite Jun 14, 2020
8a0ad3f
fix: fix test failures
olavloite Jun 15, 2020
8022457
fix: fix several race conditions
olavloite Jun 15, 2020
5e84d34
tests: increase test timeout
olavloite Jun 15, 2020
707382b
Merge branch 'master' into async-api
olavloite Jun 21, 2020
fcf37fd
feat: further towards AsyncTransactionManager
olavloite Jun 21, 2020
910b6c7
feat: require executor for transaction functions
olavloite Jun 21, 2020
86f85c0
revert: remove async connection api from branch
olavloite Jun 21, 2020
cfa8e79
revert: remove async connection api from branch
olavloite Jun 21, 2020
46708c8
feat: async connection api
olavloite Jun 21, 2020
6dfeac5
chore: run code formatter
olavloite Jun 21, 2020
6763a59
chore: fix flaky test case
olavloite Jun 21, 2020
60f0304
Merge branch 'master' into connection-api-async
olavloite Aug 5, 2020
6843515
feat: async connection api
olavloite Aug 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.google.cloud.spanner.connection;

import com.google.cloud.spanner.connection.ConnectionImpl.LeakedConnectionException;
import org.threeten.bp.Instant;

abstract class AbstractBaseConnection implements BaseConnection {
private static final String CLOSED_ERROR_MSG = "This connection is closed";
private static final String ONLY_ALLOWED_IN_AUTOCOMMIT =
"This method may only be called while in autocommit mode";
private static final String NOT_ALLOWED_IN_AUTOCOMMIT =
"This method may not be called while in autocommit mode";

/**
* Exception that is used to register the stacktrace of the code that opened a {@link Connection}.
* This exception is logged if the application closes without first closing the connection.
*/
static class LeakedConnectionException extends RuntimeException {
private static final long serialVersionUID = 7119433786832158700L;

private LeakedConnectionException() {
super("Connection was opened at " + Instant.now());
}
}

private volatile LeakedConnectionException leakedException = new LeakedConnectionException();
private final SpannerPool spannerPool;
private final StatementParser parser = StatementParser.INSTANCE;
/**
* The {@link ConnectionStatementExecutor} is responsible for translating parsed {@link
* ClientSideStatement}s into actual method calls on this {@link ConnectionImpl}. I.e. the {@link
* ClientSideStatement} 'SET AUTOCOMMIT ON' will be translated into the method call {@link
* ConnectionImpl#setAutocommit(boolean)} with value <code>true</code>.
*/
private final ConnectionStatementExecutor connectionStatementExecutor =
new ConnectionStatementExecutorImpl(this);

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.cloud.spanner.connection;

import com.google.cloud.spanner.AsyncResultSet;
import com.google.cloud.spanner.ErrorCode;
import com.google.cloud.spanner.Options.QueryOption;
import com.google.cloud.spanner.ReadContext;
Expand Down Expand Up @@ -73,6 +74,16 @@ public ResultSet call() throws Exception {
});
}

@Override
public AsyncResultSet executeQueryAsync(
final ParsedStatement statement,
final AnalyzeMode analyzeMode,
final QueryOption... options) {
Preconditions.checkArgument(statement.isQuery(), "Statement is not a query");
checkValidTransaction();
return getReadContext().executeQueryAsync(statement.getStatement(), options);
}

ResultSet internalExecuteQuery(
final ParsedStatement statement, AnalyzeMode analyzeMode, QueryOption... options) {
if (analyzeMode == AnalyzeMode.NONE) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.spanner.connection;

import com.google.api.core.ApiFuture;
import com.google.cloud.spanner.AsyncResultSet;
import com.google.cloud.spanner.Options.QueryOption;
import com.google.cloud.spanner.SpannerException;
import com.google.cloud.spanner.StructReader;
import com.google.cloud.spanner.connection.StatementParser.ParsedStatement;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import java.util.concurrent.Executor;

class AsyncChecksumResultSet extends ChecksumResultSet implements AsyncResultSet {
private AsyncResultSet delegate;

AsyncChecksumResultSet(
ReadWriteTransaction transaction,
AsyncResultSet delegate,
ParsedStatement statement,
AnalyzeMode analyzeMode,
QueryOption... options) {
super(transaction, delegate, statement, analyzeMode, options);
this.delegate = delegate;
}

@Override
public CursorState tryNext() throws SpannerException {
return delegate.tryNext();
}

@Override
public ApiFuture<Void> setCallback(Executor exec, ReadyCallback cb) {
return delegate.setCallback(exec, cb);
}

@Override
public void cancel() {
delegate.cancel();
}

@Override
public void resume() {
delegate.resume();
}

@Override
public <T> ApiFuture<ImmutableList<T>> toListAsync(
Function<StructReader, T> transformer, Executor executor) {
return delegate.toListAsync(transformer, executor);
}

@Override
public <T> ImmutableList<T> toList(Function<StructReader, T> transformer)
throws SpannerException {
return delegate.toList(transformer);
}
}