Skip to content

Batch read connection api native adjustments #2569

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

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
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Internal class for the Spanner Connection API.
Expand Down Expand Up @@ -91,8 +93,7 @@ public static AbstractStatementParser getInstance(Dialect dialect) {
*/

/** Begins a transaction. */
static final ParsedStatement BEGIN_STATEMENT =
AbstractStatementParser.getInstance(Dialect.GOOGLE_STANDARD_SQL).parse(Statement.of("BEGIN"));
static final ParsedStatement BEGIN_STATEMENT;

/**
* Create a COMMIT statement to use with the {@link #commit()} method to allow it to be cancelled,
Expand All @@ -104,14 +105,10 @@ public static AbstractStatementParser getInstance(Dialect dialect) {
* #commit()} method is called directly, we do not have a {@link ParsedStatement}, and the method
* uses this statement instead in order to use the same logic as the other statements.
*/
static final ParsedStatement COMMIT_STATEMENT =
AbstractStatementParser.getInstance(Dialect.GOOGLE_STANDARD_SQL)
.parse(Statement.of("COMMIT"));
static final ParsedStatement COMMIT_STATEMENT;

/** The {@link Statement} and {@link Callable} for rollbacks */
static final ParsedStatement ROLLBACK_STATEMENT =
AbstractStatementParser.getInstance(Dialect.GOOGLE_STANDARD_SQL)
.parse(Statement.of("ROLLBACK"));
static final ParsedStatement ROLLBACK_STATEMENT;

/**
* Create a RUN BATCH statement to use with the {@link #executeBatchUpdate(Iterable)} method to
Expand All @@ -124,9 +121,22 @@ public static AbstractStatementParser getInstance(Dialect dialect) {
* and the method uses this statement instead in order to use the same logic as the other
* statements.
*/
static final ParsedStatement RUN_BATCH_STATEMENT =
AbstractStatementParser.getInstance(Dialect.GOOGLE_STANDARD_SQL)
.parse(Statement.of("RUN BATCH"));
static final ParsedStatement RUN_BATCH_STATEMENT;

static {
try {
BEGIN_STATEMENT = getInstance(Dialect.GOOGLE_STANDARD_SQL).parse(Statement.of("BEGIN"));
COMMIT_STATEMENT = getInstance(Dialect.GOOGLE_STANDARD_SQL).parse(Statement.of("COMMIT"));
ROLLBACK_STATEMENT = getInstance(Dialect.GOOGLE_STANDARD_SQL).parse(Statement.of("ROLLBACK"));
RUN_BATCH_STATEMENT =
getInstance(Dialect.GOOGLE_STANDARD_SQL).parse(Statement.of("RUN BATCH"));

} catch (Throwable ex) {
Logger logger = Logger.getLogger(AbstractStatementParser.class.getName());
Copy link
Member

Choose a reason for hiding this comment

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

Would AbstractStatementParser.class.getName() work when static initialization of failing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. An example of this being invoked when debugging the native configuration:

Aug 04, 2023 6:24:30 PM com.google.cloud.spanner.connection.AbstractStatementParser <clinit>
SEVERE: Static initialization failure.
com.google.cloud.spanner.connection.ClientSideStatementImpl$CompileException: Could not compile statement PARTITION <sql>
	at com.google.cloud.spanner.connection.ClientSideStatementImpl.compile(ClientSideStatementImpl.java:159)
	at com.google.cloud.spanner.connection.ClientSideStatements.getCompiledStatements(ClientSideStatements.java:76)
	at com.google.cloud.spanner.connection.SpannerStatementParser.<init>(SpannerStatementParser.java:41)
	at [email protected]/java.lang.reflect.Constructor.newInstanceWithCaller([Constructor.java:499](https://cs.corp.google.com/#search/&sq=package:%5Epiper$%20project:openjdk&q=java/lang/reflect/Constructor.java:499))
	at [email protected]/java.lang.reflect.ReflectAccess.newInstance([ReflectAccess.java:128](https://cs.corp.google.com/#search/&sq=package:%5Epiper$%20project:openjdk&q=java/lang/reflect/ReflectAccess.java:128))
	at [email protected]/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347)
	at [email protected]/java.lang.Class.newInstance([DynamicHub.java:645](https://cs.corp.google.com/#search/&sq=package:%5Epiper$%20project:openjdk&q=java/lang/DynamicHub.java:645))
	at com.google.cloud.spanner.connection.AbstractStatementParser.getInstance(AbstractStatementParser.java:77)
	at com.google.cloud.spanner.connection.AbstractStatementParser.<clinit>(AbstractStatementParser.java:97)
	at com.google.cloud.spanner.connection.ConnectionImpl.getStatementParser(ConnectionImpl.java:320)
	at com.google.cloud.spanner.connection.ConnectionImpl.parseAndExecuteQuery(ConnectionImpl.java:1145)
	at com.google.cloud.spanner.connection.ConnectionImpl.executeQuery(ConnectionImpl.java:1016)
	at com.google.cloud.spanner.connection.it.ITBulkConnectionTest.lambda$testBulkCreateConnectionsMultiThreaded$0(ITBulkConnectionTest.java:74)
	at [email protected]/java.util.concurrent.FutureTask.run([FutureTask.java:264](https://cs.corp.google.com/#search/&sq=package:%5Epiper$%20project:openjdk&q=java/util/concurrent/FutureTask.java:264))
	at [email protected]/java.util.concurrent.ThreadPoolExecutor.runWorker([ThreadPoolExecutor.java:1136](https://cs.corp.google.com/#search/&sq=package:%5Epiper$%20project:openjdk&q=java/util/concurrent/ThreadPoolExecutor.java:1136))
	at [email protected]/java.util.concurrent.ThreadPoolExecutor$Worker.run([ThreadPoolExecutor.java:635](https://cs.corp.google.com/#search/&sq=package:%5Epiper$%20project:openjdk&q=java/util/concurrent/ThreadPoolExecutor.java:635))
	at [email protected]/java.lang.Thread.run([Thread.java:833](https://cs.corp.google.com/#search/&sq=package:%5Epiper$%20project:openjdk&q=java/lang/Thread.java:833))
	at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine([PlatformThreads.java:775](https://cs.corp.google.com/#search/&q=f:com/oracle/svm/core/thread/PlatformThreads.java:775))
	at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine([PosixPlatformThreads.java:203](https://cs.corp.google.com/#search/&q=f:com/oracle/svm/core/posix/thread/PosixPlatformThreads.java:203))
Caused by: java.lang.ClassNotFoundException: com.google.cloud.spanner.connection.ClientSideStatementPartitionExecutor
	at [email protected]/java.lang.Class.forName([DynamicHub.java:1132](https://cs.corp.google.com/#search/&sq=package:%5Epiper$%20project:openjdk&q=java/lang/DynamicHub.java:1132))
	at [email protected]/java.lang.Class.forName([DynamicHub.java:1105](https://cs.corp.google.com/#search/&sq=package:%5Epiper$%20project:openjdk&q=java/lang/DynamicHub.java:1105))
	at com.google.cloud.spanner.connection.ClientSideStatementImpl.compile(ClientSideStatementImpl.java:154)
	... 18 more

logger.log(Level.SEVERE, "Static initialization failure.", ex);
throw ex;
}
}

/** The type of statement that has been recognized by the parser. */
@InternalApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ final class SpannerFeature implements Feature {
"com.google.cloud.spanner.connection.ClientSideStatementPgBeginExecutor";
private static final String CLIENT_SIDE_STATEMENT_EXPLAIN_EXECUTOR =
"com.google.cloud.spanner.connection.ClientSideStatementExplainExecutor";
private static final String CLIENT_SIDE_STATEMENT_PARTITION_EXECUTOR =
"com.google.cloud.spanner.connection.ClientSideStatementPartitionExecutor";
private static final String CLIENT_SIDE_STATEMENT_RUN_PARTITION_EXECUTOR =
"com.google.cloud.spanner.connection.ClientSideStatementRunPartitionExecutor";
private static final String CLIENT_SIDE_STATEMENT_RUN_PARTITIONED_QUERY_EXECUTOR =
"com.google.cloud.spanner.connection.ClientSideStatementRunPartitionedQueryExecutor";
private static final String ABSTRACT_STATEMENT_PARSER =
"com.google.cloud.spanner.connection.AbstractStatementParser";
private static final String STATEMENT_PARSER =
Expand Down Expand Up @@ -70,6 +76,17 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
if (access.findClassByName(CLIENT_SIDE_STATEMENT_SET_EXECUTOR) != null) {
NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENT_SET_EXECUTOR);
}
if (access.findClassByName(CLIENT_SIDE_STATEMENT_PARTITION_EXECUTOR) != null) {
NativeImageUtils.registerClassForReflection(access, CLIENT_SIDE_STATEMENT_PARTITION_EXECUTOR);
}
if (access.findClassByName(CLIENT_SIDE_STATEMENT_RUN_PARTITION_EXECUTOR) != null) {
NativeImageUtils.registerClassForReflection(
access, CLIENT_SIDE_STATEMENT_RUN_PARTITION_EXECUTOR);
}
if (access.findClassByName(CLIENT_SIDE_STATEMENT_RUN_PARTITIONED_QUERY_EXECUTOR) != null) {
NativeImageUtils.registerClassForReflection(
access, CLIENT_SIDE_STATEMENT_RUN_PARTITIONED_QUERY_EXECUTOR);
}
if (access.findClassByName(CLIENT_SIDE_VALUE_CONVERTER) != null) {
NativeImageUtils.registerClassHierarchyForReflection(access, CLIENT_SIDE_VALUE_CONVERTER);
}
Expand Down