Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform a retry when error code 3101 is returned from the MySQL DB #2583

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class JDBCConnection implements ObjectStoreConnection {

private static final int MYSQL_ER_OPTION_PREVENTS_STATEMENT = 1290;
private static final int MYSQL_ER_OPTION_DUPLICATE_ENTRY = 1062;
private static final int MYSQL_ER_TRANSACTION_ROLLBACK_DURING_COMMIT = 3101;

private static final String MYSQL_EXC_STATE_DEADLOCK = "40001";
private static final String MYSQL_EXC_STATE_COMM_ERROR = "08S01";
Expand Down Expand Up @@ -6974,8 +6975,8 @@ RuntimeException sqlError(SQLException ex, String caller) {

// check to see if this is a conflict error in which case
// we're going to let the server to retry the caller
// The two SQL states that are 'retry-able' are 08S01
// for a communications error, and 40001 for deadlock.
// The SQL states that are 'retry-able' are 08S01
// for a communications error, and 40001 for deadlock, 3101 for transaction rollback.
// also check for the error code where the mysql server is
// in read-mode which could happen if we had a failover
// and the connections are still going to the old master
Expand All @@ -6986,6 +6987,9 @@ RuntimeException sqlError(SQLException ex, String caller) {
if (MYSQL_EXC_STATE_COMM_ERROR.equals(sqlState) || MYSQL_EXC_STATE_DEADLOCK.equals(sqlState)) {
code = ResourceException.CONFLICT;
msg = "Concurrent update conflict, please retry your operation later.";
} else if (ex.getErrorCode() == MYSQL_ER_TRANSACTION_ROLLBACK_DURING_COMMIT) {
code = ResourceException.CONFLICT;
msg = "Plugin instructed the server to rollback the current transaction.";
} else if (ex.getErrorCode() == MYSQL_ER_OPTION_PREVENTS_STATEMENT) {
code = ResourceException.GONE;
msg = "MySQL Database running in read-only mode";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7680,6 +7680,10 @@ public void testSqlError() throws SQLException {
rEx = (ResourceException) jdbcConn.sqlError(ex, "sqlError");
assertEquals(ResourceException.CONFLICT, rEx.getCode());

ex = new SQLException("sql-reason", "sql-state", 3101);
rEx = (ResourceException) jdbcConn.sqlError(ex, "sqlError");
assertEquals(ResourceException.CONFLICT, rEx.getCode());

ex = new SQLException("sql-reason", "sql-state", 1290);
rEx = (ResourceException) jdbcConn.sqlError(ex, "sqlError");
assertEquals(ResourceException.GONE, rEx.getCode());
Expand Down