Fixed concurrency issues with backup related commands

This commit is contained in:
Rsl1122 2019-02-18 18:03:09 +02:00
parent e1bef920e7
commit 6fbd8ced60
3 changed files with 12 additions and 4 deletions

View File

@ -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();

View File

@ -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()));

View File

@ -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()));