mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -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
+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;
|
||||
|
||||
Reference in new issue
Block a user