From 233a930c9c705aa0465859899a031d6cece8c203 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Thu, 28 Feb 2019 12:54:31 +0200 Subject: [PATCH] Made transaction wait delay configurable --- .../src/main/java/com/djrapitops/plan/db/SQLDB.java | 11 +++++++++-- .../plan/db/access/transactions/Transaction.java | 5 +++++ .../plan/system/settings/paths/TimeSettings.java | 1 + Plan/common/src/main/resources/bungeeconfig.yml | 2 ++ Plan/common/src/main/resources/config.yml | 2 ++ 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/SQLDB.java b/Plan/common/src/main/java/com/djrapitops/plan/db/SQLDB.java index 4ca7655c1..6e93ed469 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/SQLDB.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/SQLDB.java @@ -28,6 +28,7 @@ import com.djrapitops.plan.db.access.transactions.init.OperationCriticalTransact import com.djrapitops.plan.db.patches.*; import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.settings.config.PlanConfig; +import com.djrapitops.plan.system.settings.paths.TimeSettings; import com.djrapitops.plan.utilities.java.ThrowableUtils; import com.djrapitops.plugin.api.TimeAmount; import com.djrapitops.plugin.logging.L; @@ -112,8 +113,14 @@ public abstract class SQLDB extends AbstractDatabase { } transactionExecutor.shutdown(); try { - if (!transactionExecutor.awaitTermination(20L, TimeUnit.SECONDS)) { - return transactionExecutor.shutdownNow(); + Long waitMs = config.get(TimeSettings.DB_TRANSACTION_FINISH_WAIT_DELAY); + if (!transactionExecutor.awaitTermination(waitMs, TimeUnit.MILLISECONDS)) { + List unfinished = transactionExecutor.shutdownNow(); + int unfinishedCount = unfinished.size(); + if (unfinishedCount > 0) { + logger.warn(unfinishedCount + " unfinished database transactions were not executed."); + } + return unfinished; } } catch (InterruptedException e) { Thread.currentThread().interrupt(); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/access/transactions/Transaction.java b/Plan/common/src/main/java/com/djrapitops/plan/db/access/transactions/Transaction.java index 954ad8ffb..6cf0d1957 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/access/transactions/Transaction.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/access/transactions/Transaction.java @@ -148,4 +148,9 @@ public abstract class Transaction { protected UUID getServerUUID() { return db.getServerUUIDSupplier().get(); } + + @Override + public String toString() { + return getClass().getSimpleName() + (success ? " (finished)" : ""); + } } \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/settings/paths/TimeSettings.java b/Plan/common/src/main/java/com/djrapitops/plan/system/settings/paths/TimeSettings.java index 9a14bba31..90c46a49d 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/settings/paths/TimeSettings.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/settings/paths/TimeSettings.java @@ -31,6 +31,7 @@ public class TimeSettings { public static final Setting USE_SERVER_TIME = new BooleanSetting("Time.Use_server_timezone"); public static final Setting PING_SERVER_ENABLE_DELAY = new TimeSetting("Time.Delays.Ping_server_enable_delay"); public static final Setting PING_PLAYER_LOGIN_DELAY = new TimeSetting("Time.Delays.Ping_player_join_delay"); + public static final Setting DB_TRANSACTION_FINISH_WAIT_DELAY = new TimeSetting("Time.Delays.Wait_for_DB_Transactions_on_disable"); public static final Setting AFK_THRESHOLD = new TimeSetting("Time.Thresholds.AFK_threshold"); public static final Setting ACTIVE_LOGIN_THRESHOLD = new IntegerSetting("Time.Thresholds.Activity_index.Login_threshold", Setting::timeValidator); public static final Setting ACTIVE_PLAY_THRESHOLD = new TimeSetting("Time.Thresholds.Activity_index.Playtime_threshold"); diff --git a/Plan/common/src/main/resources/bungeeconfig.yml b/Plan/common/src/main/resources/bungeeconfig.yml index d5d2c4385..713e9c1d0 100644 --- a/Plan/common/src/main/resources/bungeeconfig.yml +++ b/Plan/common/src/main/resources/bungeeconfig.yml @@ -70,6 +70,8 @@ Time: Unit: SECONDS Ping_player_join_delay: 30 Unit: SECONDS + Wait_for_DB_Transactions_on_disable: + Unit: SECONDS Thresholds: # How long player needs to be idle until Plan considers them AFK AFK_threshold: 3 diff --git a/Plan/common/src/main/resources/config.yml b/Plan/common/src/main/resources/config.yml index 61249c756..90d23af6b 100644 --- a/Plan/common/src/main/resources/config.yml +++ b/Plan/common/src/main/resources/config.yml @@ -75,6 +75,8 @@ Time: Unit: SECONDS Ping_player_join_delay: 30 Unit: SECONDS + Wait_for_DB_Transactions_on_disable: 20 + Unit: SECONDS Thresholds: # How long player needs to be idle until Plan considers them AFK AFK_threshold: 3