mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-15 05:41:51 +08:00
Fixed concurrency issues with backup related commands
This commit is contained in:
parent
e1bef920e7
commit
6fbd8ced60
@ -43,6 +43,7 @@ import com.djrapitops.plugin.utilities.Verify;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This command is used to backup a database to a .db file.
|
* 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;
|
String fileName = dbName + "-backup-" + timeStamp;
|
||||||
backupDB = sqliteFactory.usingFileCalled(fileName);
|
backupDB = sqliteFactory.usingFileCalled(fileName);
|
||||||
backupDB.init();
|
backupDB.init();
|
||||||
backupDB.executeTransaction(new BackupCopyTransaction(copyFromDB, backupDB));
|
backupDB.executeTransaction(new BackupCopyTransaction(copyFromDB, backupDB)).get();
|
||||||
} catch (DBException e) {
|
} catch (DBException | ExecutionException e) {
|
||||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
backupDB.close();
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
} finally {
|
} finally {
|
||||||
if (backupDB != null) {
|
if (backupDB != null) {
|
||||||
backupDB.close();
|
backupDB.close();
|
||||||
|
@ -112,7 +112,7 @@ public class ManageMoveCommand extends CommandNode {
|
|||||||
try {
|
try {
|
||||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
|
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));
|
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
|
||||||
|
|
||||||
@ -120,6 +120,8 @@ public class ManageMoveCommand extends CommandNode {
|
|||||||
if (movingToCurrentDB) {
|
if (movingToCurrentDB) {
|
||||||
sender.sendMessage(locale.getString(ManageLang.HOTSWAP_REMINDER, toDatabase.getType().getConfigName()));
|
sender.sendMessage(locale.getString(ManageLang.HOTSWAP_REMINDER, toDatabase.getType().getConfigName()));
|
||||||
}
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||||
|
@ -124,9 +124,11 @@ public class ManageRestoreCommand extends CommandNode {
|
|||||||
|
|
||||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_START));
|
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));
|
sender.sendMessage(locale.getString(ManageLang.PROGRESS_SUCCESS));
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||||
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
sender.sendMessage(locale.getString(ManageLang.PROGRESS_FAIL, e.getMessage()));
|
||||||
|
Loading…
Reference in New Issue
Block a user