After recovering from a disk-full problem, I started getting these errors in my logs:
java.sql.BatchUpdateException: Deadlock found when trying to get lock; try restarting transaction
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1684)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1108)
at com.dappit.Dapper.adminer.pixelMaster.storage.RemotePixelStorage.flushBufferToDb(RemotePixelStorage.java:120)
...
The Java code (RemotePixelStorage.java:120
):
(119) connection.setAutoCommit(false);
(120) int[] returnCodes = pstmt.executeBatch();
(121) connection.setAutoCommit(true);
(122) connection.commit();
Each statement is a call to the stored procedure add_pixel
, which adds an element to a table and removes older elements if necessary.
What does this jdbc exception mean? How can I overcome this issue? Should I simply try to commit a few times with a catch block?
Best Answer
Looking at the Stored Procedure, I see something rather unnatural.
The thing I see that is unnatural is the
DELETE ... JOIN
query that is mixing an InnoDB table and a MyISAM table. Such JOINs tend to be rather clumsy to mysqld.Let's make the
pixel_window
table. InnoDB. In fact, let's not make it a temporary table. Of course, the hard part is to create a uniquepixel_window
table for the session. The pixel_window temp table will be the prefix 'pixel_window_' with the Connection ID appended.Give it a Try !!!
CAVEAT : Since I created this monster, I needed to slay it as well.