Skip to content

Commit b59b0ad

Browse files
committed
Ignore error when removing data that was already removed
Affects issues: - Fixed #4035
1 parent 0d3d54e commit b59b0ad

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

Plan/common/src/main/java/com/djrapitops/plan/exceptions/database/DBOpException.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class DBOpException extends IllegalStateException implements ExceptionWit
3131

3232
public static final String CONSTRAINT_VIOLATION = "Constraint Violation";
3333
public static final String DUPLICATE_KEY = "Duplicate key";
34+
public static final String MODIFIED_SINCE_LAST_READ = "Modified since last read";
3435
private final ErrorContext context;
3536

3637
public DBOpException(String message) {
@@ -147,6 +148,9 @@ public static DBOpException forCause(String sql, SQLException e) {
147148
context.related("column byte length exceeded")
148149
.whatToDo("Update your MySQL, column key size was exceeded (max key length is 767 bytes in 5.6) - MySQL 5.7 increases the limit.");
149150
break;
151+
case 1020: // MySQL error 'Record has changed since last read in table'
152+
context.related(MODIFIED_SINCE_LAST_READ);
153+
break;
150154
default:
151155
context.related("Unknown SQL Error code");
152156
}
@@ -171,4 +175,9 @@ public boolean isDuplicateKeyViolation() {
171175
return context != null
172176
&& context.getRelated().contains(DBOpException.DUPLICATE_KEY);
173177
}
178+
179+
public boolean isModifiedSinceLastReadViolation() {
180+
return context != null
181+
&& context.getRelated().contains(DBOpException.MODIFIED_SINCE_LAST_READ);
182+
}
174183
}

Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/init/RemoveOldSampledDataTransaction.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.djrapitops.plan.storage.database.transactions.init;
1818

1919
import com.djrapitops.plan.delivery.domain.DateObj;
20+
import com.djrapitops.plan.exceptions.database.DBOpException;
2021
import com.djrapitops.plan.identification.ServerUUID;
2122
import com.djrapitops.plan.storage.database.queries.objects.TPSQueries;
2223
import com.djrapitops.plan.storage.database.sql.tables.PingTable;
@@ -57,8 +58,15 @@ public RemoveOldSampledDataTransaction(
5758
protected void performOperations() {
5859
Optional<Integer> allTimePeak = query(TPSQueries.fetchAllTimePeakPlayerCount(serverUUID)).map(DateObj::getValue);
5960

60-
execute(cleanTPSTable(allTimePeak.orElse(-1)));
61-
execute(cleanPingTable());
61+
try {
62+
execute(cleanTPSTable(allTimePeak.orElse(-1)));
63+
execute(cleanPingTable());
64+
} catch (DBOpException e) {
65+
if (e.isModifiedSinceLastReadViolation()) {
66+
return;
67+
}
68+
throw e;
69+
}
6270
}
6371

6472
private Executable cleanTPSTable(int allTimePlayerPeak) {

0 commit comments

Comments
 (0)