mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-29 19:41:35 +01:00
Database open failure now disables the plugin
Affects issues: - Fixed #1394
This commit is contained in:
parent
57d9a2762c
commit
fef717cd33
@ -21,7 +21,7 @@ package com.djrapitops.plan.exceptions;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class EnableException extends Exception {
|
||||
public class EnableException extends IllegalStateException {
|
||||
|
||||
public EnableException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
|
@ -16,9 +16,15 @@
|
||||
*/
|
||||
package com.djrapitops.plan.exceptions.database;
|
||||
|
||||
import com.djrapitops.plan.utilities.logging.ErrorContext;
|
||||
|
||||
public class FatalDBException extends DBOpException {
|
||||
|
||||
public FatalDBException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public FatalDBException(String message, DBOpException cause) {
|
||||
super(message + cause.getMessage(), cause.getCause(), cause.getContext().orElse(ErrorContext.builder().build()));
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package com.djrapitops.plan.storage.database;
|
||||
|
||||
import com.djrapitops.plan.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.exceptions.EnableException;
|
||||
import com.djrapitops.plan.storage.database.transactions.Transaction;
|
||||
import com.djrapitops.plan.storage.database.transactions.init.OperationCriticalTransaction;
|
||||
|
||||
@ -58,7 +58,7 @@ public class DBAccessLock {
|
||||
synchronized (lockObject) {
|
||||
lockObject.wait();
|
||||
if (database.getState() == Database.State.CLOSED) {
|
||||
throw new DBOpException("Database failed to open, Query has failed. (This exception is necessary to not keep query threads waiting)");
|
||||
throw new EnableException("Database failed to open, Query has failed. (This exception is necessary to not keep query threads waiting)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,10 +42,7 @@ import org.apache.commons.lang3.concurrent.BasicThreadFactory;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Supplier;
|
||||
@ -259,13 +256,20 @@ public abstract class SQLDB extends AbstractDatabase {
|
||||
if (throwable == null) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
if (throwable instanceof FatalDBException) {
|
||||
if (throwable.getCause() instanceof FatalDBException) {
|
||||
logger.error("Database failed to open, " + transaction.getClass().getName() + " failed to be executed.");
|
||||
FatalDBException actual = (FatalDBException) throwable.getCause();
|
||||
Optional<String> whatToDo = actual.getContext().flatMap(ErrorContext::getWhatToDo);
|
||||
whatToDo.ifPresent(message -> logger.error("What to do: " + message));
|
||||
if (!whatToDo.isPresent()) logger.error("Error msg: " + actual.getMessage());
|
||||
setState(State.CLOSED);
|
||||
}
|
||||
ThrowableUtils.appendEntryPointToCause(throwable, origin);
|
||||
|
||||
errorLogger.log(L.ERROR, throwable, ErrorContext.builder()
|
||||
.related("Transaction: " + transaction.getClass()).build());
|
||||
errorLogger.log(getState() == State.CLOSED ? L.CRITICAL : L.ERROR, throwable, ErrorContext.builder()
|
||||
.related("Transaction: " + transaction.getClass())
|
||||
.related("DB State: " + getState())
|
||||
.build());
|
||||
return CompletableFuture.completedFuture(null);
|
||||
};
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.djrapitops.plan.storage.database.transactions.init;
|
||||
|
||||
import com.djrapitops.plan.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.exceptions.database.FatalDBException;
|
||||
import com.djrapitops.plan.storage.database.SQLDB;
|
||||
import com.djrapitops.plan.storage.database.transactions.Transaction;
|
||||
@ -31,9 +32,13 @@ public abstract class OperationCriticalTransaction extends Transaction {
|
||||
|
||||
@Override
|
||||
public void executeTransaction(SQLDB db) {
|
||||
super.executeTransaction(db);
|
||||
if (!success) {
|
||||
throw new FatalDBException(getClass().getSimpleName() + " failed to execute and database can not be opened.");
|
||||
try {
|
||||
super.executeTransaction(db);
|
||||
if (!success) {
|
||||
throw new FatalDBException(getClass().getName() + " failed to execute and database could not be opened.");
|
||||
}
|
||||
} catch (DBOpException e) {
|
||||
throw new FatalDBException(getClass().getName() + " failed to execute and database could not be opened: ", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -51,6 +51,7 @@ public class ErrorContext {
|
||||
|
||||
public void merge(ErrorContext context) {
|
||||
this.related.addAll(context.related);
|
||||
if (this.whatToDo == null && context.whatToDo != null) this.whatToDo = context.whatToDo;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
Loading…
Reference in New Issue
Block a user