mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
perf(build): replace quarkus-jdbc extensions with plain JDBC drivers (#3465)
* perf(build): replace quarkus-jdbc extensions with plain JDBC drivers The RDS Data API and Redshift Data API open connections with DriverManager. They never used Agroal, Narayana or the datasource layer that quarkus-jdbc-mysql and quarkus-jdbc-postgresql pull in. Depend on mysql-connector-j and postgresql directly and hand-supply the native image config the extensions provided. * perf(build): cut unused JDBC driver paths from the native image Substitute driver code that cannot be reached against the databases Floci provisions, mirroring what quarkus-jdbc-mysql did for JMX and going a step further for authentication and multi-host URLs. * perf(build): keep the MySQL cleanup thread disabled in JVM mode quarkus-jdbc-mysql set com.mysql.cj.disableAbandonedConnectionCleanup at startup in JVM mode as well as at native build time. The first commit carried only the native build argument and a surefire copy, so quarkus:dev and the JVM Docker image started Connector/J's abandoned connection cleanup thread on the first MySQL Data API call. In dev mode that thread is recreated with every restart and pins the old classloader. * fix(rdsdata): reject PostgreSQL result types the Data API does not support Aurora PostgreSQL answers a result set that holds a point, interval, money, box, circle, line, lseg, path or polygon column with UnsupportedResultException and the message "The result contains the unsupported data type POINT." Floci returned the driver's toString of the value instead. Check the column type names before reading the rows and raise the same error. json and jsonb stay supported, and a column cast to text still reads as a string, which is the workaround AWS documents. * perf(build): drop the PGobject reflection entries pgjdbc builds point, interval, money and the geometric types through reflection only when a result set holds such a column. The Data API now rejects those columns before reading a row, and json and jsonb values are plain PGobject instances the driver creates directly, so none of the ten entries can be reached. * chore(rdsdata): name the tolerated ClassNotFoundException in OpenTelemetryUnavailable * perf(build): keep PGInterval registered for the Redshift Data API Redshift tables can hold INTERVAL YEAR TO MONTH and INTERVAL DAY TO SECOND columns and the Redshift Data API returns them as strings. Floci serves that path from a PostgreSQL container through pgjdbc, which builds an interval value by reflection, so the entry stays. The Redshift Data compat test now reads two interval columns on the native image. * perf(build): keep the geometric reflection entries for the Redshift Data API Redshift refuses point, box, circle, lseg, path and polygon as column types but evaluates them in a select, and its Data API returns the values as strings, checked on a real ra3.large cluster. Floci serves that path through pgjdbc, which builds those values by reflection, so the six entries stay. line stays out because Redshift rejects it, and money never reaches PGmoney because pgjdbc reads it as a double. The Redshift Data compat test selects those expressions and expects the strings Redshift returned. JdbcDriverNativeSupportTest resolves every registered class name. * fix(redshiftdata): fail statements that produce line, json or jsonb like Redshift Redshift has none of these types. A select that names one fails with "ERROR: type "line" not yet implemented" or "ERROR: type "json" does not exist", checked on a real cluster. The PostgreSQL container behind Floci's Redshift evaluates them, so the Data API now checks the result column types and fails the statement with the same text.
This commit is contained in:
1 parent
589b1aba9c
commit
569f9f55e4
16 files changed
+522
-9
No files matched your search
@@ -628,6 +628,39 @@ func TestRdsDataApiGoSdkPostgresV1(t *testing.T) {
|
||||
assert.Equal(t, `{"ok":true}`, awsV1.StringValue(selectOut.Records[0][10].StringValue))
|
||||
assert.Equal(t, "2021-03-04T05:06:07Z", awsV1.StringValue(selectOut.Records[0][11].StringValue))
|
||||
|
||||
// Error code and message checked against Aurora PostgreSQL 17.7 on 2026-09-13.
|
||||
for _, unsupported := range []struct{ sql, typeName string }{
|
||||
{"select point(1, 2)", "POINT"},
|
||||
{"select interval '1 day 2 hours'", "INTERVAL"},
|
||||
{"select 12.34::money", "MONEY"},
|
||||
{"select box '((0,0),(1,1))'", "BOX"},
|
||||
{"select circle '<(0,0),1>'", "CIRCLE"},
|
||||
{"select line '{1,2,3}'", "LINE"},
|
||||
{"select lseg '[(0,0),(1,1)]'", "LSEG"},
|
||||
{"select path '[(0,0),(1,1)]'", "PATH"},
|
||||
{"select polygon '((0,0),(1,1),(1,0))'", "POLYGON"},
|
||||
} {
|
||||
_, err = dataSvc.ExecuteStatement(&rdsdataservice.ExecuteStatementInput{
|
||||
ResourceArn: awsV1.String(resourceArn),
|
||||
SecretArn: awsV1.String(secretArn),
|
||||
Database: awsV1.String(database),
|
||||
Sql: awsV1.String(unsupported.sql),
|
||||
})
|
||||
assertAwsErrorCode(t, err, "UnsupportedResultException")
|
||||
var unsupportedErr awserr.Error
|
||||
require.ErrorAs(t, err, &unsupportedErr)
|
||||
assert.Equal(t, "The result contains the unsupported data type "+unsupported.typeName+".", unsupportedErr.Message())
|
||||
}
|
||||
|
||||
textCastOut, err := dataSvc.ExecuteStatement(&rdsdataservice.ExecuteStatementInput{
|
||||
ResourceArn: awsV1.String(resourceArn),
|
||||
SecretArn: awsV1.String(secretArn),
|
||||
Database: awsV1.String(database),
|
||||
Sql: awsV1.String("select point(1, 2)::text as p"),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "(1,2)", awsV1.StringValue(textCastOut.Records[0][0].StringValue))
|
||||
|
||||
updateOut, err := dataSvc.ExecuteStatement(&rdsdataservice.ExecuteStatementInput{
|
||||
ResourceArn: awsV1.String(resourceArn),
|
||||
SecretArn: awsV1.String(secretArn),
|
||||
|
||||
+88
@@ -83,6 +83,94 @@ class RedshiftDataOperationsTest {
|
||||
assertThat(result.records().get(0).get(1).stringValue()).isEqualTo("a");
|
||||
}
|
||||
|
||||
/**
|
||||
* Redshift stores INTERVAL YEAR TO MONTH and INTERVAL DAY TO SECOND columns and the
|
||||
* Data API returns them as strings, checked against a real cluster on 2026-09-13. pgjdbc
|
||||
* builds the value through reflection, so this also checks that the native image keeps
|
||||
* that metadata.
|
||||
*/
|
||||
@Test
|
||||
@DisplayName("interval columns read back as strings")
|
||||
void intervalColumnsReadBackAsStrings() throws Exception {
|
||||
run("CREATE TABLE compat_intervals (y2m interval year to month, d2s interval day to second)");
|
||||
run("INSERT INTO compat_intervals VALUES (interval '1-2' year to month, interval '2 1:0:0' day to second)");
|
||||
|
||||
String selectId = run("SELECT y2m, d2s FROM compat_intervals");
|
||||
GetStatementResultResponse result = data.getStatementResult(GetStatementResultRequest.builder()
|
||||
.id(selectId)
|
||||
.build());
|
||||
|
||||
assertThat(result.totalNumRows()).isEqualTo(1L);
|
||||
assertThat(result.records().get(0).get(0).stringValue()).isEqualTo("1 years 2 mons");
|
||||
// Redshift prints "2 days 1 hours 0 mins 0.0 secs", Floci drops the zero fields.
|
||||
assertThat(result.records().get(0).get(1).stringValue()).isNotEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Redshift rejects these as column types but evaluates them in a select, and the Data
|
||||
* API returns them as strings. Values checked against a real ra3.large cluster on
|
||||
* 2026-09-13. pgjdbc builds them through reflection, so this also checks that the
|
||||
* native image keeps that metadata.
|
||||
*/
|
||||
@Test
|
||||
@DisplayName("geometric expressions read back as strings")
|
||||
void geometricExpressionsReadBackAsStrings() throws Exception {
|
||||
String selectId = run("SELECT point(1, 2), box '((0,0),(1,1))', circle '<(0,0),1>', lseg '[(0,0),(1,1)]', "
|
||||
+ "path '[(0,0),(1,1)]', polygon '((0,0),(1,1),(1,0))', '12.34'::money");
|
||||
GetStatementResultResponse result = data.getStatementResult(GetStatementResultRequest.builder()
|
||||
.id(selectId)
|
||||
.build());
|
||||
|
||||
assertThat(result.totalNumRows()).isEqualTo(1L);
|
||||
assertThat(result.columnMetadata()).extracting("typeName")
|
||||
.containsExactly("point", "box", "circle", "lseg", "path", "polygon", "money");
|
||||
assertThat(result.records().get(0).get(0).stringValue()).isEqualTo("(1.0,2.0)");
|
||||
assertThat(result.records().get(0).get(1).stringValue()).isEqualTo("(1.0,1.0),(0.0,0.0)");
|
||||
assertThat(result.records().get(0).get(2).stringValue()).isEqualTo("<(0.0,0.0),1.0>");
|
||||
assertThat(result.records().get(0).get(3).stringValue()).isEqualTo("[(0.0,0.0),(1.0,1.0)]");
|
||||
// Redshift prints path as the server text [(0,0),(1,1)], Floci still prints the driver form.
|
||||
assertThat(result.records().get(0).get(4).stringValue()).isNotEmpty();
|
||||
assertThat(result.records().get(0).get(5).stringValue()).isEqualTo("((0.0,0.0),(1.0,1.0),(1.0,0.0))");
|
||||
assertThat(result.records().get(0).get(6).doubleValue()).isEqualTo(12.34);
|
||||
}
|
||||
|
||||
/**
|
||||
* Error text checked against a real cluster on 2026-09-13.
|
||||
*/
|
||||
@Test
|
||||
@DisplayName("PostgreSQL types Redshift lacks fail the statement with the Redshift error")
|
||||
void typesRedshiftLacksFailTheStatement() throws Exception {
|
||||
assertThat(failure("SELECT line '{1,2,3}'")).isEqualTo("ERROR: type \"line\" not yet implemented");
|
||||
assertThat(failure("SELECT '{\"a\":1}'::json")).isEqualTo("ERROR: type \"json\" does not exist");
|
||||
assertThat(failure("SELECT '{\"a\":1}'::jsonb")).isEqualTo("ERROR: type \"jsonb\" does not exist");
|
||||
}
|
||||
|
||||
private String failure(String sql) throws Exception {
|
||||
String id = submit(sql);
|
||||
Instant deadline = Instant.now().plus(Duration.ofSeconds(30));
|
||||
while (Instant.now().isBefore(deadline)) {
|
||||
DescribeStatementResponse describe = describe(id);
|
||||
if (describe.status() == StatusString.FAILED) {
|
||||
return describe.error();
|
||||
}
|
||||
if (describe.status() == StatusString.FINISHED) {
|
||||
throw new IllegalStateException("Statement " + id + " finished but was expected to fail");
|
||||
}
|
||||
Thread.sleep(250);
|
||||
}
|
||||
throw new IllegalStateException("Statement " + id + " did not finish in time");
|
||||
}
|
||||
|
||||
private String submit(String sql) {
|
||||
return data.executeStatement(ExecuteStatementRequest.builder()
|
||||
.clusterIdentifier(clusterId)
|
||||
.dbUser(USERNAME)
|
||||
.database(DATABASE)
|
||||
.sql(sql)
|
||||
.build())
|
||||
.id();
|
||||
}
|
||||
|
||||
private String run(String sql) throws Exception {
|
||||
String id = data.executeStatement(ExecuteStatementRequest.builder()
|
||||
.clusterIdentifier(clusterId)
|
||||
|
||||
@@ -39,6 +39,7 @@ The deprecated `ExecuteSql` operation is recognized at `POST /ExecuteSql` and re
|
||||
- `includeResultMetadata` returns the full AWS `ColumnMetadata` shape per column: `label`, `name`, `type`, `typeName`, `tableName`, `schemaName`, `nullable`, `precision`, `scale`, `isSigned`, `isCaseSensitive`, `isCurrency`, `isAutoIncrement`, and `arrayBaseColumnType`. `label` is the result-set label (the alias when the query aliases a column) and `name` is the underlying column name, falling back to the label for computed columns — clients that hydrate rows by `label` need it present. `type` is a JDBC type code and `typeName` is the engine's own type name (for example `4` and `int4` for a PostgreSQL integer), both taken from the driver so they match the engine actually serving the query. `arrayBaseColumnType` is always `0` because array columns are not mapped to `arrayValue` fields yet.
|
||||
- `ExecuteStatement` returns `generatedFields` for statements that report an update count on MySQL and MariaDB, carrying the auto-increment keys the engine generated. As on Aurora PostgreSQL, PostgreSQL resources always return an empty list — use a `RETURNING` clause to read generated values. `generatedFields` is omitted for statements that return a result set.
|
||||
- `BatchExecuteStatement` runs the statement once per entry in `parameterSets` through a JDBC batch and returns one `updateResults` entry per set, each carrying the `generatedFields` that set produced under the same engine rules as `ExecuteStatement` — a set inserting several rows reports one field per generated key. On MySQL and MariaDB the sets are executed one at a time so each entry owns its own keys, because `getGeneratedKeys()` after a JDBC batch reports every key the batch generated with nothing tying a key back to the set that produced it. It accepts `transactionId`, so a batch can take part in a Data API transaction; without one the batch commits automatically. An absent or empty `parameterSets` runs nothing and returns an empty `updateResults`: AWS runs the statement once per parameter set provided and points a caller who wants a single parameterless execution at one empty set (`[[]]`, which runs once here) or at `ExecuteStatement`. A statement that returns rows rather than an update count — a `SELECT`, or a CTE ending in one — is rejected with `BadRequestException` before any set runs, because a batch reports one `UpdateResult` per set and has nowhere to carry a result set, and AWS documents the operation as taking a DML statement. The check reads the driver's description of the prepared statement, so nothing executes first, and a DML statement that also reports rows through a PostgreSQL `RETURNING` clause is left alone: the batch still performs its writes, and `generatedFields` is empty on PostgreSQL anyway.
|
||||
- A PostgreSQL result set with a `point`, `box`, `circle`, `line`, `lseg`, `path`, `polygon`, `interval`, or `money` column is rejected with `UnsupportedResultException`, as on Aurora PostgreSQL. Cast the column to text to read it.
|
||||
- SQL errors are returned as `DatabaseErrorException` so AWS SDK callers can handle database failures with normal AWS error decoding.
|
||||
- If `secretArn` points to a local Secrets Manager secret with JSON credentials (`username` or `user`, plus `password`), those credentials are used. If the secret is missing or cannot be parsed, Floci falls back to the resolved RDS resource's master credentials for local development convenience.
|
||||
- `formatRecordsAs=JSON`, `formattedRecords`, and `resultSetOptions` are not implemented yet, and `ExecuteStatement` requests asking for those result modes return `BadRequestException`. They are `ExecuteStatement`-only fields in the AWS API, so `BatchExecuteStatement` — whose input is limited to `resourceArn`, `secretArn`, `sql`, `database`, `schema`, `parameterSets`, and `transactionId` — ignores them as AWS does rather than rejecting them.
|
||||
|
||||
@@ -54,7 +54,7 @@ A request identifies its target cluster one of two ways:
|
||||
- **`CancelStatement`** returns `{ "Status": true }`. In Floci a statement is already terminal by the time it can be cancelled, so `CancelStatement` sets `Status=ABORTED` only when the statement was not already `FINISHED`. An unknown statement id returns `ResourceNotFoundException`.
|
||||
- **`WithEvent`** is accepted and ignored: no EventBridge event is published.
|
||||
- **`ExecuteSql` and `BatchExecuteSql`** (the deprecated pre-2020 operations) return `ValidationException`.
|
||||
- **Type mapping.** JDBC `BOOLEAN` and `BIT` map to `booleanValue`; integer types to `longValue`; floating-point types to `doubleValue`; `NUMERIC` and `DECIMAL` to `stringValue` (as AWS does); binary types to `blobValue`; everything else, including dates, timestamps, uuid, and json, to `stringValue`. A SQL `NULL` maps to `isNull`.
|
||||
- **Type mapping.** JDBC `BOOLEAN` and `BIT` map to `booleanValue`; integer types to `longValue`; floating-point types to `doubleValue`; `NUMERIC` and `DECIMAL` to `stringValue` (as AWS does); binary types to `blobValue`; everything else, including dates, timestamps, and uuid, to `stringValue`. A SQL `NULL` maps to `isNull`. A result column of type `line`, `json`, or `jsonb` fails the statement with the Redshift error text.
|
||||
|
||||
## Configuration
|
||||
|
||||
|
||||
@@ -399,12 +399,17 @@
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-jdbc-mysql</artifactId>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-jdbc-postgresql</artifactId>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.graalvm.sdk</groupId>
|
||||
<artifactId>nativeimage</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package io.github.hectorvent.floci.services.rdsdata;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
/**
|
||||
* Registers the JDBC driver classes that are instantiated by name in a native image.
|
||||
* DriverManager loads the drivers through ServiceLoader, MySQL Connector/J creates its
|
||||
* connection URL, socket factory, logger and exceptions through Class.forName, and the
|
||||
* PostgreSQL driver builds interval and geometric values through reflection. Redshift
|
||||
* tables hold intervals, and a Redshift select can evaluate point, box, circle, lseg,
|
||||
* path and polygon expressions.
|
||||
*/
|
||||
@RegisterForReflection(classNames = {
|
||||
"com.mysql.cj.jdbc.Driver",
|
||||
"com.mysql.cj.conf.url.SingleConnectionUrl",
|
||||
"com.mysql.cj.protocol.StandardSocketFactory",
|
||||
"com.mysql.cj.log.StandardLogger",
|
||||
"com.mysql.cj.exceptions.AssertionFailedException",
|
||||
"com.mysql.cj.exceptions.CJCommunicationsException",
|
||||
"com.mysql.cj.exceptions.CJConnectionFeatureNotAvailableException",
|
||||
"com.mysql.cj.exceptions.CJException",
|
||||
"com.mysql.cj.exceptions.CJOperationNotSupportedException",
|
||||
"com.mysql.cj.exceptions.CJPacketTooBigException",
|
||||
"com.mysql.cj.exceptions.CJTimeoutException",
|
||||
"com.mysql.cj.exceptions.ClosedOnExpiredPasswordException",
|
||||
"com.mysql.cj.exceptions.ConnectionIsClosedException",
|
||||
"com.mysql.cj.exceptions.DataConversionException",
|
||||
"com.mysql.cj.exceptions.DataReadException",
|
||||
"com.mysql.cj.exceptions.DataTruncationException",
|
||||
"com.mysql.cj.exceptions.FeatureNotAvailableException",
|
||||
"com.mysql.cj.exceptions.InvalidConnectionAttributeException",
|
||||
"com.mysql.cj.exceptions.NumberOutOfRange",
|
||||
"com.mysql.cj.exceptions.OperationCancelledException",
|
||||
"com.mysql.cj.exceptions.PasswordExpiredException",
|
||||
"com.mysql.cj.exceptions.PropertyNotModifiableException",
|
||||
"com.mysql.cj.exceptions.RSAException",
|
||||
"com.mysql.cj.exceptions.SSLParamsException",
|
||||
"com.mysql.cj.exceptions.StatementIsClosedException",
|
||||
"com.mysql.cj.exceptions.UnableToConnectException",
|
||||
"com.mysql.cj.exceptions.UnsupportedConnectionStringException",
|
||||
"com.mysql.cj.exceptions.WrongArgumentException",
|
||||
"org.postgresql.Driver",
|
||||
"org.postgresql.util.PGInterval",
|
||||
"org.postgresql.geometric.PGbox",
|
||||
"org.postgresql.geometric.PGcircle",
|
||||
"org.postgresql.geometric.PGlseg",
|
||||
"org.postgresql.geometric.PGpath",
|
||||
"org.postgresql.geometric.PGpoint",
|
||||
"org.postgresql.geometric.PGpolygon"
|
||||
}, methods = false, fields = false, ignoreNested = true)
|
||||
public class JdbcDriverNativeSupport {}
|
||||
+174
@@ -0,0 +1,174 @@
|
||||
package io.github.hectorvent.floci.services.rdsdata;
|
||||
|
||||
import com.mysql.cj.Messages;
|
||||
import com.mysql.cj.conf.ConnectionUrl;
|
||||
import com.mysql.cj.exceptions.ExceptionFactory;
|
||||
import com.mysql.cj.jdbc.JdbcConnection;
|
||||
import com.mysql.cj.jdbc.ha.LoadBalancedConnection;
|
||||
import com.mysql.cj.jdbc.ha.ReplicationConnection;
|
||||
import com.mysql.cj.protocol.a.NativePacketPayload;
|
||||
import com.mysql.cj.telemetry.TelemetryHandler;
|
||||
import com.mysql.cj.telemetry.TelemetrySpan;
|
||||
import com.mysql.cj.telemetry.TelemetrySpanName;
|
||||
import com.oracle.svm.core.annotate.Substitute;
|
||||
import com.oracle.svm.core.annotate.TargetClass;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
/**
|
||||
* Native image substitutions for MySQL Connector/J, mirroring the quarkus-jdbc-mysql extension.
|
||||
* The OCI and OpenTelemetry references point at libraries that are not on the classpath, and the
|
||||
* native build links every reachable class at build time. JMX registration, Kerberos and LDAP SASL
|
||||
* authentication cannot be used against the databases Floci provisions, and leaving them reachable
|
||||
* pulls the JMX server, GSS and SASL parts of the JDK into the image. Floci only opens single-host
|
||||
* connections, so the failover, load-balanced and replication URL forms are cut as well.
|
||||
*/
|
||||
final class MySqlDriverSubstitutions {
|
||||
|
||||
static final String UNAVAILABLE = " is not available in the native image";
|
||||
|
||||
private MySqlDriverSubstitutions() {
|
||||
}
|
||||
}
|
||||
|
||||
@TargetClass(className = "com.mysql.cj.jdbc.ConnectionGroupManager")
|
||||
final class Target_com_mysql_cj_jdbc_ConnectionGroupManager {
|
||||
|
||||
@Substitute
|
||||
public static void registerJmx() throws SQLException {
|
||||
throw new IllegalStateException("JMX" + MySqlDriverSubstitutions.UNAVAILABLE);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetClass(className = "com.mysql.cj.jdbc.jmx.LoadBalanceConnectionGroupManager")
|
||||
final class Target_com_mysql_cj_jdbc_jmx_LoadBalanceConnectionGroupManager {
|
||||
|
||||
@Substitute
|
||||
public synchronized void registerJmx() throws SQLException {
|
||||
throw new IllegalStateException("JMX" + MySqlDriverSubstitutions.UNAVAILABLE);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetClass(className = "com.mysql.cj.jdbc.jmx.ReplicationGroupManager")
|
||||
final class Target_com_mysql_cj_jdbc_jmx_ReplicationGroupManager {
|
||||
|
||||
@Substitute
|
||||
public synchronized void registerJmx() throws SQLException {
|
||||
throw new IllegalStateException("JMX" + MySqlDriverSubstitutions.UNAVAILABLE);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetClass(className = "com.mysql.cj.jdbc.ha.ReplicationConnectionGroupManager")
|
||||
final class Target_com_mysql_cj_jdbc_ha_ReplicationConnectionGroupManager {
|
||||
|
||||
@Substitute
|
||||
public static void registerJmx() throws SQLException {
|
||||
throw new IllegalStateException("JMX" + MySqlDriverSubstitutions.UNAVAILABLE);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetClass(className = "com.mysql.cj.protocol.a.authentication.AuthenticationKerberosClient")
|
||||
final class Target_com_mysql_cj_protocol_a_authentication_AuthenticationKerberosClient {
|
||||
|
||||
@Substitute
|
||||
public boolean nextAuthenticationStep(NativePacketPayload fromServer, List<NativePacketPayload> toServer) {
|
||||
throw ExceptionFactory.createException("Kerberos authentication" + MySqlDriverSubstitutions.UNAVAILABLE);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetClass(className = "com.mysql.cj.protocol.a.authentication.AuthenticationLdapSaslClientPlugin")
|
||||
final class Target_com_mysql_cj_protocol_a_authentication_AuthenticationLdapSaslClientPlugin {
|
||||
|
||||
@Substitute
|
||||
public boolean nextAuthenticationStep(NativePacketPayload fromServer, List<NativePacketPayload> toServer) {
|
||||
throw ExceptionFactory.createException("LDAP SASL authentication" + MySqlDriverSubstitutions.UNAVAILABLE);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetClass(className = "com.mysql.cj.protocol.a.authentication.AuthenticationOciClient")
|
||||
final class Target_com_mysql_cj_protocol_a_authentication_AuthenticationOciClient {
|
||||
|
||||
@Substitute
|
||||
private void loadOciConfig() {
|
||||
throw ExceptionFactory.createException("OCI authentication" + MySqlDriverSubstitutions.UNAVAILABLE);
|
||||
}
|
||||
|
||||
@Substitute
|
||||
private void initializePrivateKey() {
|
||||
throw ExceptionFactory.createException("OCI authentication" + MySqlDriverSubstitutions.UNAVAILABLE);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetClass(className = "com.mysql.cj.otel.OpenTelemetryHandler", onlyWith = OpenTelemetryUnavailable.class)
|
||||
final class Target_com_mysql_cj_otel_OpenTelemetryHandler implements TelemetryHandler {
|
||||
|
||||
@Substitute
|
||||
Target_com_mysql_cj_otel_OpenTelemetryHandler() {
|
||||
throw ExceptionFactory.createException(Messages.getString("Connection.OtelApiNotFound"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Substitute
|
||||
public TelemetrySpan startSpan(TelemetrySpanName spanName, Object... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Substitute
|
||||
public void addLinkTarget(TelemetrySpan span) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Substitute
|
||||
public void removeLinkTarget(TelemetrySpan span) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Substitute
|
||||
public void propagateContext(BiConsumer<String, String> traceparentConsumer) {
|
||||
}
|
||||
}
|
||||
|
||||
final class OpenTelemetryUnavailable implements BooleanSupplier {
|
||||
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
try {
|
||||
Class.forName("io.opentelemetry.api.GlobalOpenTelemetry");
|
||||
return false;
|
||||
} catch (ClassNotFoundException expected) {
|
||||
// The OpenTelemetry API is not on the classpath, which is what this check detects.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@TargetClass(className = "com.mysql.cj.jdbc.ha.FailoverConnectionProxy")
|
||||
final class Target_com_mysql_cj_jdbc_ha_FailoverConnectionProxy {
|
||||
|
||||
@Substitute
|
||||
public static JdbcConnection createProxyInstance(ConnectionUrl connectionUrl) throws SQLException {
|
||||
throw new SQLException("Failover connection URLs are" + MySqlDriverSubstitutions.UNAVAILABLE);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetClass(className = "com.mysql.cj.jdbc.ha.LoadBalancedConnectionProxy")
|
||||
final class Target_com_mysql_cj_jdbc_ha_LoadBalancedConnectionProxy {
|
||||
|
||||
@Substitute
|
||||
public static LoadBalancedConnection createProxyInstance(ConnectionUrl connectionUrl) throws SQLException {
|
||||
throw new SQLException("Load-balanced connection URLs are" + MySqlDriverSubstitutions.UNAVAILABLE);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetClass(className = "com.mysql.cj.jdbc.ha.ReplicationConnectionProxy")
|
||||
final class Target_com_mysql_cj_jdbc_ha_ReplicationConnectionProxy {
|
||||
|
||||
@Substitute
|
||||
public static ReplicationConnection createProxyInstance(ConnectionUrl connectionUrl) throws SQLException {
|
||||
throw new SQLException("Replication connection URLs are" + MySqlDriverSubstitutions.UNAVAILABLE);
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package io.github.hectorvent.floci.services.rdsdata;
|
||||
|
||||
import com.oracle.svm.core.annotate.Substitute;
|
||||
import com.oracle.svm.core.annotate.TargetClass;
|
||||
import org.postgresql.core.PGStream;
|
||||
import org.postgresql.util.PSQLException;
|
||||
import org.postgresql.util.PSQLState;
|
||||
|
||||
/**
|
||||
* Native image substitution for the PostgreSQL driver. GSS authentication cannot be used against
|
||||
* the databases Floci provisions, and leaving it reachable pulls the JDK GSS stack into the image.
|
||||
*/
|
||||
final class PostgresDriverSubstitutions {
|
||||
|
||||
private PostgresDriverSubstitutions() {
|
||||
}
|
||||
}
|
||||
|
||||
@TargetClass(className = "org.postgresql.gss.MakeGSS")
|
||||
final class Target_org_postgresql_gss_MakeGSS {
|
||||
|
||||
@Substitute
|
||||
public static void authenticate(boolean encrypted, PGStream pgStream, String host, String user, char[] password,
|
||||
String jaasApplicationName, String kerberosServerName, boolean useSpnego,
|
||||
boolean jaasLogin, boolean logServerErrorDetail, boolean gssUseDefaultCreds)
|
||||
throws PSQLException {
|
||||
throw new PSQLException("GSS authentication is not available in the native image",
|
||||
PSQLState.CONNECTION_REJECTED);
|
||||
}
|
||||
}
|
||||
+6
@@ -11,6 +11,12 @@ import java.util.Properties;
|
||||
@ApplicationScoped
|
||||
class RdsDataConnectionFactory {
|
||||
|
||||
static {
|
||||
// quarkus-jdbc-mysql set this at startup in JVM mode. Connector/J reads it once, in
|
||||
// the static initializer that otherwise starts its abandoned connection cleanup thread.
|
||||
System.setProperty("com.mysql.cj.disableAbandonedConnectionCleanup", "true");
|
||||
}
|
||||
|
||||
Connection open(RdsDataResourceResolver.DatabaseTarget target,
|
||||
String username,
|
||||
String password,
|
||||
|
||||
@@ -429,6 +429,7 @@ public class RdsDataService implements Resettable {
|
||||
if (hasResultSet) {
|
||||
try (ResultSet rs = statement.getResultSet()) {
|
||||
ResultSetMetaData meta = rs.getMetaData();
|
||||
rejectUnsupportedResultTypes(meta, engine);
|
||||
if (includeMetadata) {
|
||||
response.set("columnMetadata", RdsDataColumnMetadata.toColumnMetadata(objectMapper, meta));
|
||||
}
|
||||
@@ -466,6 +467,28 @@ public class RdsDataService implements Resettable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Aurora PostgreSQL answers a result set holding one of these column types with
|
||||
* UnsupportedResultException (checked 2026-09-13). Casting the column to text is the
|
||||
* documented way to read it.
|
||||
*/
|
||||
private static final Set<String> UNSUPPORTED_POSTGRES_RESULT_TYPES = Set.of(
|
||||
"point", "interval", "money", "box", "circle", "line", "lseg", "path", "polygon");
|
||||
|
||||
static void rejectUnsupportedResultTypes(ResultSetMetaData meta, DatabaseEngine engine) throws SQLException {
|
||||
if (engine != DatabaseEngine.POSTGRES) {
|
||||
return;
|
||||
}
|
||||
for (int i = 1; i <= meta.getColumnCount(); i++) {
|
||||
String typeName = meta.getColumnTypeName(i);
|
||||
if (typeName != null && UNSUPPORTED_POSTGRES_RESULT_TYPES.contains(typeName.toLowerCase(Locale.ROOT))) {
|
||||
throw new AwsException("UnsupportedResultException",
|
||||
"The result contains the unsupported data type " + typeName.toUpperCase(Locale.ROOT) + ".",
|
||||
400);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayNode records(ResultSet rs, ResultSetMetaData meta) throws SQLException {
|
||||
ArrayNode records = objectMapper.createArrayNode();
|
||||
int columnCount = meta.getColumnCount();
|
||||
|
||||
+20
@@ -13,6 +13,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
@@ -82,6 +83,24 @@ public class RedshiftDataService implements Resettable {
|
||||
stored.updatedAt = Instant.now();
|
||||
}
|
||||
|
||||
/**
|
||||
* Redshift has no line, json or jsonb type and fails a statement that produces one with
|
||||
* exactly these messages (checked on a real cluster 2026-09-13).
|
||||
*/
|
||||
private static final Map<String, String> RESULT_TYPE_ERRORS = Map.of(
|
||||
"line", "ERROR: type \"line\" not yet implemented",
|
||||
"json", "ERROR: type \"json\" does not exist",
|
||||
"jsonb", "ERROR: type \"jsonb\" does not exist");
|
||||
|
||||
static void rejectResultTypesRedshiftLacks(ResultSetMetaData meta) throws SQLException {
|
||||
for (int i = 1; i <= meta.getColumnCount(); i++) {
|
||||
String error = RESULT_TYPE_ERRORS.get(meta.getColumnTypeName(i));
|
||||
if (error != null) {
|
||||
throw new SQLException(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void runOnConnection(RedshiftDataStatementStore.StoredStatement stored,
|
||||
Connection connection, String sql, Map<String, String> parameters)
|
||||
throws SQLException {
|
||||
@@ -92,6 +111,7 @@ public class RedshiftDataService implements Resettable {
|
||||
boolean hasResultSet = statement.execute();
|
||||
if (hasResultSet) {
|
||||
try (ResultSet rs = statement.getResultSet()) {
|
||||
rejectResultTypesRedshiftLacks(rs.getMetaData());
|
||||
stored.columnMetadata = RedshiftDataColumnMetadata.toColumnMetadata(objectMapper, rs.getMetaData());
|
||||
stored.rows = RedshiftDataFieldMapper.rows(objectMapper, rs);
|
||||
stored.hasResultSet = true;
|
||||
|
||||
@@ -28,13 +28,14 @@ quarkus:
|
||||
require-localhost: false
|
||||
limits:
|
||||
max-body-size: ${floci.protocols.max-request-size}M
|
||||
datasource:
|
||||
active: false
|
||||
shutdown:
|
||||
# Enables the pre-shutdown phase so stop hooks run before the HTTP server stops.
|
||||
# No 'delay' value is set - observers run synchronously, no artificial sleep is introduced.
|
||||
delay-enabled: true
|
||||
native:
|
||||
# quarkus-jdbc-mysql used to force this. Without it the image has only UTF-8, UTF-16,
|
||||
# ISO-8859-1 and US-ASCII, which breaks latin1 MySQL columns and non-UTF-8 mail bodies.
|
||||
add-all-charsets: true
|
||||
resources:
|
||||
# The Pricing service reads its bundled snapshot, EC2 reads its image
|
||||
# catalog (ec2/image-catalog.yaml), IAM reads its AWS managed-policy
|
||||
@@ -53,6 +54,10 @@ quarkus:
|
||||
- iam/*.json
|
||||
- i18n/*.properties
|
||||
- org/apache/velocity/runtime/defaults/*.properties
|
||||
# DriverManager finds the JDBC drivers through ServiceLoader, and the MySQL
|
||||
# driver reads its time zone table at connect time.
|
||||
- META-INF/services/java.sql.Driver
|
||||
- com/mysql/cj/util/TimeZoneMapping.properties
|
||||
# snappy-java registers 27 JNI libraries, one per platform. Only the one
|
||||
# for the running platform loads, so 23 are dropped. Linux x86_64 and
|
||||
# aarch64 cover the published images, Mac covers a local native build.
|
||||
@@ -99,6 +104,12 @@ quarkus:
|
||||
# bundled JNI library from the static initializers of these two classes.
|
||||
- --initialize-at-run-time=org.xerial.snappy.Snappy
|
||||
- --initialize-at-run-time=org.xerial.snappy.SnappyLoader
|
||||
- --initialize-at-run-time=org.postgresql.util.PasswordUtil$SecureRandomHolder
|
||||
- --initialize-at-run-time=org.postgresql.util.LazyCleanerImpl
|
||||
# Build-time property. The MySQL driver's AbandonedConnectionCleanupThread starts an
|
||||
# executor thread in its static initializer unless this is set, and a started thread
|
||||
# in the image heap fails the build.
|
||||
- -J-Dcom.mysql.cj.disableAbandonedConnectionCleanup=true
|
||||
|
||||
|
||||
floci:
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package io.github.hectorvent.floci.services.rdsdata;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
class JdbcDriverNativeSupportTest {
|
||||
|
||||
@Test
|
||||
void everyRegisteredClassNameExistsInTheDrivers() {
|
||||
RegisterForReflection registration = JdbcDriverNativeSupport.class.getAnnotation(RegisterForReflection.class);
|
||||
assertNotNull(registration);
|
||||
ClassLoader loader = JdbcDriverNativeSupport.class.getClassLoader();
|
||||
for (String className : registration.classNames()) {
|
||||
assertDoesNotThrow(() -> Class.forName(className, false, loader), className);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,34 @@ class RdsDataServiceTest {
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* Message and error code checked against Aurora PostgreSQL 17.7 through the real
|
||||
* Data API on 2026-09-13.
|
||||
*/
|
||||
@Test
|
||||
void rejectsPostgresResultTypesTheDataApiDoesNotSupport() throws Exception {
|
||||
ResultSetMetaData meta = mock(ResultSetMetaData.class);
|
||||
when(meta.getColumnCount()).thenReturn(2);
|
||||
when(meta.getColumnTypeName(1)).thenReturn("jsonb");
|
||||
when(meta.getColumnTypeName(2)).thenReturn("point");
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> RdsDataService.rejectUnsupportedResultTypes(meta, DatabaseEngine.POSTGRES));
|
||||
assertEquals("UnsupportedResultException", error.getErrorCode());
|
||||
assertEquals("The result contains the unsupported data type POINT.", error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void acceptsPostgresResultTypesTheDataApiSupports() throws Exception {
|
||||
ResultSetMetaData meta = mock(ResultSetMetaData.class);
|
||||
when(meta.getColumnCount()).thenReturn(3);
|
||||
when(meta.getColumnTypeName(1)).thenReturn("int4");
|
||||
when(meta.getColumnTypeName(2)).thenReturn("jsonb");
|
||||
when(meta.getColumnTypeName(3)).thenReturn("text");
|
||||
|
||||
RdsDataService.rejectUnsupportedResultTypes(meta, DatabaseEngine.POSTGRES);
|
||||
}
|
||||
|
||||
@Test
|
||||
void executesSqlAndMapsDataApiResultShape() throws Exception {
|
||||
TestHarness harness = new TestHarness();
|
||||
|
||||
+25
@@ -8,6 +8,8 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Clock;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -59,6 +61,29 @@ class RedshiftDataServiceTest {
|
||||
return om.createObjectNode().put("Id", id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Messages checked against a real Redshift cluster on 2026-09-13.
|
||||
*/
|
||||
@Test
|
||||
void rejectsResultTypesRedshiftLacksWithTheRedshiftMessage() throws Exception {
|
||||
ResultSetMetaData meta = mock(ResultSetMetaData.class);
|
||||
when(meta.getColumnCount()).thenReturn(2);
|
||||
when(meta.getColumnTypeName(1)).thenReturn("int4");
|
||||
|
||||
when(meta.getColumnTypeName(2)).thenReturn("line");
|
||||
SQLException lineError = assertThrows(SQLException.class,
|
||||
() -> RedshiftDataService.rejectResultTypesRedshiftLacks(meta));
|
||||
assertEquals("ERROR: type \"line\" not yet implemented", lineError.getMessage());
|
||||
|
||||
when(meta.getColumnTypeName(2)).thenReturn("jsonb");
|
||||
SQLException jsonbError = assertThrows(SQLException.class,
|
||||
() -> RedshiftDataService.rejectResultTypesRedshiftLacks(meta));
|
||||
assertEquals("ERROR: type \"jsonb\" does not exist", jsonbError.getMessage());
|
||||
|
||||
when(meta.getColumnTypeName(2)).thenReturn("point");
|
||||
RedshiftDataService.rejectResultTypesRedshiftLacks(meta);
|
||||
}
|
||||
|
||||
@Test
|
||||
void executeStoresFinishedResultAndDescribeReportsIt() {
|
||||
String createId = service.executeStatement(req("create table t (id int, name varchar(20))"), REGION)
|
||||
|
||||
@@ -4,8 +4,6 @@ quarkus:
|
||||
test-port: 0
|
||||
limits:
|
||||
max-body-size: ${floci.protocols.max-request-size}M
|
||||
datasource:
|
||||
active: false
|
||||
# Groovy (a REST Assured dependency) starts DFA-cache-cleaner threads that never stop.
|
||||
# Loaded parent-first they live in the shared system classloader, so they cannot pin a
|
||||
# per-profile application classloader across the many app restarts of a test run.
|
||||
|
||||
Reference in new issue
Block a user