From 6fbd8ced60ec82bc235f6db0f1faefbc94260b1f Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Mon, 18 Feb 2019 18:03:09 +0200 Subject: [PATCH] Fixed concurrency issues with backup related commands --- .../plan/command/commands/manage/ManageBackupCommand.java | 8 ++++++-- .../plan/command/commands/manage/ManageMoveCommand.java | 4 +++- .../command/commands/manage/ManageRestoreCommand.java | 4 +++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java index f589ec756..4ec81e974 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java @@ -43,6 +43,7 @@ import com.djrapitops.plugin.utilities.Verify; import javax.inject.Inject; import javax.inject.Singleton; import java.util.Arrays; +import java.util.concurrent.ExecutionException; /** * This command is used to backup a database to a .db file. @@ -136,9 +137,12 @@ public class ManageBackupCommand extends CommandNode { String fileName = dbName + "-backup-" + timeStamp; backupDB = sqliteFactory.usingFileCalled(fileName); backupDB.init(); - backupDB.executeTransaction(new BackupCopyTransaction(copyFromDB, backupDB)); - } catch (DBException e) { + backupDB.executeTransaction(new BackupCopyTransaction(copyFromDB, backupDB)).get(); + } catch (DBException | ExecutionException e) { errorHandler.log(L.ERROR, this.getClass(), e); + } catch (InterruptedException e) { + backupDB.close(); + Thread.currentThread().interrupt(); } finally { if (backupDB != null) { backupDB.close(); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageMoveCommand.java b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageMoveCommand.java index 063d5e652..a2028edd5 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageMoveCommand.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageMoveCommand.java @@ -112,7 +112,7 @@ public class ManageMoveCommand extends CommandNode { try { sender.sendMessage(locale.getString(ManageLang.PROGRESS_START)); - toDatabase.executeTransaction(new BackupCopyTransaction(fromDatabase, toDatabase)); + toDatabase.executeTransaction(new BackupCopyTransaction(fromDatabase, toDatabase)).get(); sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS)); @@ -120,6 +120,8 @@ public class ManageMoveCommand extends CommandNode { if (movingToCurrentDB) { sender.sendMessage(locale.getString(ManageLang.HOTSWAP_REMINDER, toDatabase.getType().getConfigName())); } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } catch (Exception e) { errorHandler.log(L.ERROR, this.getClass(), e); sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage())); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRestoreCommand.java b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRestoreCommand.java index 37cd3d6e5..a40b3ae30 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRestoreCommand.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageRestoreCommand.java @@ -124,9 +124,11 @@ public class ManageRestoreCommand extends CommandNode { sender.sendMessage(locale.getString(ManageLang.PROGRESS_START)); - database.executeTransaction(new BackupCopyTransaction(backupDB, database)); + database.executeTransaction(new BackupCopyTransaction(backupDB, database)).get(); sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS)); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } catch (Exception e) { errorHandler.log(L.ERROR, this.getClass(), e); sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));