makssent opened a new issue, #40257: URL: https://github.com/apache/shardingsphere/issues/40257
### Before reporting a bug - [x] I have searched open and closed [GitHub issues](https://github.com/apache/shardingsphere/issues). - [x] I have read the [ShardingSphere documentation](https://shardingsphere.apache.org/document/current/en/overview). ### ShardingSphere version master, commit [`01446d4fad4`](https://github.com/apache/shardingsphere/commit/01446d4fad48450e7fc3eb3b3631b25d6bf411df) ### ShardingSphere project ShardingSphere-Proxy ### Expected behavior The proxy should accept a connection with the DPB items [`isc_dpb_max_inline_blob_size`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/include/firebird/impl/consts_pub.h#L136) and [`isc_dpb_max_blob_cache_size`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/include/firebird/impl/consts_pub.h#L135) in [`op_attach`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/remote/server/server.cpp#L5077-L5079) as the Firebird server does. If the proxy does not use a DPB item, it should skip it, as the Firebird server [does](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/jrd/jrd.cpp#L7330-L7331), instead of rejecting the connection. ### Actual behavior The proxy rejects a connection with either of these DPB items, so the client cannot connect. Jaybird [sends](https://github.com/FirebirdSQL/jaybird/blob/v6.0.7/src/main/org/firebirdsql/jaybird/props/internal/StandardConnectionPropertyDefiner.java#L120-L123) the connection property [`maxInlineBlobSize`](https://github.com/FirebirdSQL/jaybird/blob/v6.0.7/src/main/org/firebirdsql/jaybird/props/PropertyNames.java#L93) as [`isc_dpb_max_inline_blob_size`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/include/firebird/impl/consts_pub.h#L136) and [`maxBlobCacheSize`](https://github.com/FirebirdSQL/jaybird/blob/v6.0.7/src/main/org/firebirdsql/jaybird/props/PropertyNames.java#L94) as [`isc_dpb_max_blob_cache_size`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/include/firebird/impl/consts_pub.h#L135). The same steps were executed directly on the Firebird server and through the proxy, and the rows were read directly from the server: | Steps | Firebird server | Proxy | | --- | --- | --- | | Connect with [`maxInlineBlobSize`](https://github.com/FirebirdSQL/jaybird/blob/v6.0.7/src/main/org/firebirdsql/jaybird/props/PropertyNames.java#L93)`=0` | Success | Error [`isc_random`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/include/firebird/impl/msg/jrd.h#L63) "Unknown exception. More details: java.lang.NullPointerException: Cannot find code '%d' in dpb type [104]" | | Insert a row with ID = 8981 without auto-commit, read it and commit | Success | Not executed, there is no connection | | Connect with [`maxBlobCacheSize`](https://github.com/FirebirdSQL/jaybird/blob/v6.0.7/src/main/org/firebirdsql/jaybird/props/PropertyNames.java#L94)`=1000` | Success | Error [`isc_random`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/include/firebird/impl/msg/jrd.h#L63) "Unknown exception. More details: java.lang.NullPointerException: Cannot find code '%d' in dpb type [103]" | | Insert a row with ID = 8982 without auto-commit, read it and commit | Success | Not executed, there is no connection | | Read the rows with ID = 8981 and ID = 8982 directly on the server | The rows are saved | The rows are lost | So an application that sets [`maxInlineBlobSize`](https://github.com/FirebirdSQL/jaybird/blob/v6.0.7/src/main/org/firebirdsql/jaybird/props/PropertyNames.java#L93) or [`maxBlobCacheSize`](https://github.com/FirebirdSQL/jaybird/blob/v6.0.7/src/main/org/firebirdsql/jaybird/props/PropertyNames.java#L94) cannot work through the proxy at all, although it works with the Firebird server. ### Reason analysis - [`FirebirdAuthenticationEngine#processAttach`](https://github.com/apache/shardingsphere/blob/01446d4fad48450e7fc3eb3b3631b25d6bf411df/proxy/frontend/dialect/firebird/src/main/java/org/apache/shardingsphere/proxy/frontend/firebird/authentication/FirebirdAuthenticationEngine.java#L95-L101) creates [`FirebirdAttachPacket`](https://github.com/apache/shardingsphere/blob/01446d4fad48450e7fc3eb3b3631b25d6bf411df/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdAttachPacket.java#L38-L42), which parses the DPB of [`op_attach`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/remote/server/server.cpp#L5077-L5079) with [`FirebirdParameterBuffer#parseBuffer`](https://github.com/apache/shardingsphere/blob/01446d4fad48450e7fc3eb3b3631b25d6bf411df/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/constant/buffer/FirebirdParameterBuffer.java#L51-L57). The meth od [converts](https://github.com/apache/shardingsphere/blob/01446d4fad48450e7fc3eb3b3631b25d6bf411df/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/constant/buffer/FirebirdParameterBuffer.java#L54) the code of every item to a known type, so one unknown item fails the whole [`op_attach`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/remote/server/server.cpp#L5077-L5079). - [`FirebirdDatabaseParameterBufferType`](https://github.com/apache/shardingsphere/blob/01446d4fad48450e7fc3eb3b3631b25d6bf411df/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/constant/buffer/type/FirebirdDatabaseParameterBufferType.java#L35) [ends](https://github.com/apache/shardingsphere/blob/01446d4fad48450e7fc3eb3b3631b25d6bf411df/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/constant/buffer/type/FirebirdDatabaseParameterBufferType.java#L143-L145) with the codes 100 and 101, and [`FirebirdDatabaseParameterBufferType#valueOf`](https://github.com/apache/shardingsphere/blob/01446d4fad48450e7fc3eb3b3631b25d6bf411df/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/constant/buffer/type/FirebirdDatabaseParameterBufferType.java#L169-L173) throws `NullPointerException` "Cannot find code '%d' in dpb type" for the codes 103 ([ `isc_dpb_max_blob_cache_size`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/include/firebird/impl/consts_pub.h#L135)) and 104 ([`isc_dpb_max_inline_blob_size`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/include/firebird/impl/consts_pub.h#L136)). The proxy answers [`op_attach`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/remote/server/server.cpp#L5077-L5079) with [`isc_random`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/include/firebird/impl/msg/jrd.h#L63) "Unknown exception.". - The Firebird server reads the DPB in [`DatabaseOptions::get`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/jrd/jrd.cpp#L6905) and [skips](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/jrd/jrd.cpp#L7330-L7331) the items it does not use, so these items do not fail the connection. ### Steps to reproduce #### Environment - Firebird server 5.0. - Client: Jaybird 6.0.7. #### Steps 1. Create the table on the Firebird server: ```sql CREATE TABLE T_PLAIN (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR(20)); ``` 2. Start ShardingSphere-Proxy with this configuration: ```yaml # global.yaml authority: users: - user: root@% password: root privilege: type: ALL_PERMITTED props: proxy-frontend-database-protocol-type: Firebird ``` ```yaml # database-firebird.yaml databaseName: firebird_db dataSources: ds_0: url: jdbc:firebirdsql://<host>/<database file> username: <user> password: <password> rules: - !SINGLE tables: - "*.*" ``` 3. Execute the steps from the table under "Actual behavior" through the proxy and directly on the Firebird server, and compare the results. "Example code" runs all of them. ### Example code All cases on Jaybird 6.0.7, one method per case. The comment above each method shows what it prints against the Firebird server and through the proxy. ```java import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; public class DpbBlobItems { // The proxy; put the URL of the Firebird server here to compare static final String URL = "jdbc:firebirdsql://<proxy host>:<proxy port>/firebird_db?encoding=UTF8&wireCrypt=DISABLED"; static final String USER = "root"; static final String PASSWORD = "root"; // The Firebird server, to read the rows directly static final String SERVER_URL = "jdbc:firebirdsql://<host>/<database file>"; static final String SERVER_USER = "<user>"; static final String SERVER_PASSWORD = "<password>"; public static void main(final String[] args) throws Exception { executeOnServer("DELETE FROM T_PLAIN WHERE ID BETWEEN 8981 AND 8982"); maxInlineBlobSize(); maxBlobCacheSize(); executeOnServer("DELETE FROM T_PLAIN WHERE ID BETWEEN 8981 AND 8982"); } // Firebird server: "connect: success", "INSERT: 1 row", "SELECT: ID = 8981", "COMMIT: success", "ID = 8981: the row is saved"; // proxy: "connect: Unknown exception." and "More details: java.lang.NullPointerException: Cannot find code '%d' in dpb type [104]", // "ID = 8981: the row is lost" static void maxInlineBlobSize() throws SQLException { // Jaybird sends isc_dpb_max_inline_blob_size (104) in op_attach session("maxInlineBlobSize", "0", 8981); } // Firebird server: "connect: success", "INSERT: 1 row", "SELECT: ID = 8982", "COMMIT: success", "ID = 8982: the row is saved"; // proxy: "connect: Unknown exception." and "More details: java.lang.NullPointerException: Cannot find code '%d' in dpb type [103]", // "ID = 8982: the row is lost" static void maxBlobCacheSize() throws SQLException { // Jaybird sends isc_dpb_max_blob_cache_size (103) in op_attach session("maxBlobCacheSize", "1000", 8982); } // Connects with the given connection property, inserts the row without auto-commit, reads it and commits static void session(final String property, final String value, final int id) throws SQLException { Properties properties = new Properties(); properties.setProperty("user", USER); properties.setProperty("password", PASSWORD); properties.setProperty(property, value); Connection connection; try { connection = DriverManager.getConnection(URL, properties); System.out.println("connect: success"); } catch (final SQLException ex) { System.out.println("connect: " + ex.getMessage()); printRow(id); return; } try (connection; Statement statement = connection.createStatement()) { connection.setAutoCommit(false); System.out.println("INSERT: " + statement.executeUpdate("INSERT INTO T_PLAIN (ID, NAME) VALUES (" + id + ", '" + value + "')") + " row"); try (ResultSet resultSet = statement.executeQuery("SELECT ID FROM T_PLAIN WHERE ID = " + id)) { System.out.println("SELECT: " + (resultSet.next() ? "ID = " + resultSet.getInt(1) : "no row")); } connection.commit(); System.out.println("COMMIT: success"); } printRow(id); } // Reads the row directly on the Firebird server static void printRow(final int id) throws SQLException { try (Connection connection = DriverManager.getConnection(SERVER_URL, SERVER_USER, SERVER_PASSWORD); ResultSet resultSet = connection.createStatement().executeQuery("SELECT NAME FROM T_PLAIN WHERE ID = " + id)) { System.out.println("ID = " + id + ": " + (resultSet.next() ? "the row is saved" : "the row is lost")); } } static void executeOnServer(final String sql) throws SQLException { try (Connection connection = DriverManager.getConnection(SERVER_URL, SERVER_USER, SERVER_PASSWORD)) { connection.createStatement().execute(sql); } } } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
