Bug #75333 | Connector J with Tomcat is Read Only | ||
---|---|---|---|
Submitted: | 29 Dec 2014 16:30 | Modified: | 31 Dec 2014 19:28 |
Reporter: | Mahmoud Youssef | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | Connector / J | Severity: | S2 (Serious) |
Version: | 5.1.25 | OS: | Linux (Ubuntu 12.04) |
Assigned to: | CPU Architecture: | Any | |
Tags: | Jasper Server, jdbc, Transaction Read Only |
[29 Dec 2014 16:30]
Mahmoud Youssef
[31 Dec 2014 19:28]
Todd Farmer
Hi Mahmoud, While both Connector/Java and MySQL have read-only properties, neither are enabled by default. MySQL Server 5.6 added optimizations for read-only workloads, and introduces SET TRANSACTION READ ONLY: http://dev.mysql.com/doc/refman/5.6/en/set-transaction.html As of Connector/Java 5.1.23, this syntax is used with 5.6 servers when Connection.setReadOnly(true) is called: "Connection.setReadOnly() will take advantage of server-side support for read-only transactions present in MySQL 5.6 and newer. Calling .isReadOnly() will incur a round-trip if useLocalSessionState is not enabled." http://dev.mysql.com/doc/relnotes/connector-j/en/news-5-1-23.html It seems that something in your code (or libraries you use) is calling Connection.setReadOnly(true), which enforces read-only operations - including those on temporary tables within stored programs. To work around this, you should eliminate calls to setReadOnly(true) when performing operations which do write operations. It's worth noting that there's significant value in the read-only optimizations, as well as tying the read-only state of the driver to that of the transaction on the server. In earlier versions of Connector/Java, a very basic client-side check was done against the SQL being executed to ensure it was read-only. Basically, the client had to parse the SQL statement, eliminating comments, checking multi-statements, etc. and seeing if it started with an "S" (for "SELECT"). That all goes away when we can trust the server to enforce read-only properties. Reverting to client-side enforcement of read-only operations - which is what would happen if we use the suggested SET TRANSACTION READ WRITE command - eliminates all of the performance benefits of read-only transactions in MySQL Server 5.6, and re-introduces poor and performance-sapping client-side checking. If there are reasons that setReadOnly(false) does *NOT* work for your use case, please do let us know so we can consider that in more detail. There are potential use cases which conflict because setReadOnly() is also the trigger for switching between master and slaves in a replication-aware scale-out connection. Stored procedures which create and manipulate data in temporary tables may be safe (even desirable) to execute on a replication slave.