mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-02-11 18:02:35 +01:00
Added more context for errorcode 1213
There was not enough context to appropriately figure out if the exception was logged due to 3 attempts failing beforehand. Attempt limit was increased to 5 Affects issues: - Close #1522
This commit is contained in:
parent
b2b983b05a
commit
01ffe8cbe1
@ -128,6 +128,9 @@ public class DBOpException extends IllegalStateException implements ExceptionWit
|
|||||||
context.related("Missing privilege")
|
context.related("Missing privilege")
|
||||||
.whatToDo("Grant the required privileges to your MySQL user (often 'REFERENCES' privilege is missing).");
|
.whatToDo("Grant the required privileges to your MySQL user (often 'REFERENCES' privilege is missing).");
|
||||||
break;
|
break;
|
||||||
|
case 1213:
|
||||||
|
context.related("Deadlock");
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
context.related("Unknown SQL Error code");
|
context.related("Unknown SQL Error code");
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ import com.djrapitops.plan.storage.database.DBType;
|
|||||||
import com.djrapitops.plan.storage.database.Database;
|
import com.djrapitops.plan.storage.database.Database;
|
||||||
import com.djrapitops.plan.storage.database.SQLDB;
|
import com.djrapitops.plan.storage.database.SQLDB;
|
||||||
import com.djrapitops.plan.storage.database.queries.Query;
|
import com.djrapitops.plan.storage.database.queries.Query;
|
||||||
|
import com.djrapitops.plan.utilities.logging.ErrorContext;
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
@ -37,7 +38,7 @@ public abstract class Transaction {
|
|||||||
// SQLite version on 1.8.8 does not support savepoints, see createSavePoint() method
|
// SQLite version on 1.8.8 does not support savepoints, see createSavePoint() method
|
||||||
private static final AtomicBoolean SUPPORTS_SAVE_POINTS = new AtomicBoolean(true);
|
private static final AtomicBoolean SUPPORTS_SAVE_POINTS = new AtomicBoolean(true);
|
||||||
// Limit for Deadlock attempts.
|
// Limit for Deadlock attempts.
|
||||||
private static final int ATTEMPT_LIMIT = 3;
|
private static final int ATTEMPT_LIMIT = 5;
|
||||||
|
|
||||||
private SQLDB db;
|
private SQLDB db;
|
||||||
protected DBType dbType;
|
protected DBType dbType;
|
||||||
@ -87,7 +88,8 @@ public abstract class Transaction {
|
|||||||
int errorCode = statementFail.getErrorCode();
|
int errorCode = statementFail.getErrorCode();
|
||||||
boolean mySQLDeadlock = dbType == DBType.MYSQL && errorCode == 1213;
|
boolean mySQLDeadlock = dbType == DBType.MYSQL && errorCode == 1213;
|
||||||
boolean h2Deadlock = dbType == DBType.H2 && errorCode == 40001;
|
boolean h2Deadlock = dbType == DBType.H2 && errorCode == 40001;
|
||||||
boolean deadlocked = mySQLDeadlock || h2Deadlock || statementFail instanceof SQLTransactionRollbackException;
|
boolean deadlocked = mySQLDeadlock || h2Deadlock
|
||||||
|
|| statementFail instanceof SQLTransactionRollbackException;
|
||||||
if (deadlocked && attempts < ATTEMPT_LIMIT) {
|
if (deadlocked && attempts < ATTEMPT_LIMIT) {
|
||||||
executeTransaction(db); // Recurse to attempt again.
|
executeTransaction(db); // Recurse to attempt again.
|
||||||
return;
|
return;
|
||||||
@ -96,7 +98,9 @@ public abstract class Transaction {
|
|||||||
failMsg += " (Attempted " + attempts + " times)";
|
failMsg += " (Attempted " + attempts + " times)";
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new DBOpException(failMsg + rollbackStatusMsg, statementFail);
|
throw new DBOpException(failMsg + rollbackStatusMsg, statementFail, ErrorContext.builder()
|
||||||
|
.related("Attempts: " + attempts)
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String rollbackTransaction() {
|
private String rollbackTransaction() {
|
||||||
|
Loading…
Reference in New Issue
Block a user