From eee90cc3e34f4e5a7d562ee9e60c66a61816985c Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Tue, 16 Oct 2007 20:19:45 +0000
Subject: [PATCH] Issue 2368: tasks should be interruptable. The four schedulable task (import-ldif, export-ldif, backup, and restore) can now be interrupted for purposes of cancellation. The manage-tasks utility now allows the user to cancel any one of these tasks if they are currently running. If interrupted while executing, the tasks try to break out of their work loop as soon as possible and return a 'stopped by administrator' status. Both the backup and export-ldif tasks perform some cleanup (removing the abandoned backup or exported LDIF file) if they are cancelled.
---
opends/src/server/org/opends/server/backends/jeb/BackupManager.java | 25 ++++++++++++++++++-------
1 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/opends/src/server/org/opends/server/backends/jeb/BackupManager.java b/opends/src/server/org/opends/server/backends/jeb/BackupManager.java
index ccd5b5c..6b88b97 100644
--- a/opends/src/server/org/opends/server/backends/jeb/BackupManager.java
+++ b/opends/src/server/org/opends/server/backends/jeb/BackupManager.java
@@ -476,7 +476,8 @@
if (latestFileName != null)
{
ArrayList<String> unchangedList = new ArrayList<String>();
- while (indexCurrent < logFiles.length)
+ while (indexCurrent < logFiles.length &&
+ !backupConfig.isCancelled())
{
File logFile = logFiles[indexCurrent];
String logFileName = logFile.getName();
@@ -528,13 +529,15 @@
{
boolean deletedFiles = false;
- while (indexCurrent < logFiles.length)
+ while (indexCurrent < logFiles.length &&
+ !backupConfig.isCancelled())
{
File logFile = logFiles[indexCurrent];
try
{
- latestFileSize = archiveFile(zipStream, mac, digest, logFile);
+ latestFileSize = archiveFile(zipStream, mac, digest,
+ logFile, backupConfig);
latestFileName = logFile.getName();
}
catch (FileNotFoundException e)
@@ -695,6 +698,13 @@
throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
message, e);
}
+
+ // Remove the backup if this operation was cancelled since the
+ // backup may be incomplete
+ if (backupConfig.isCancelled())
+ {
+ removeBackup(backupDir, backupID);
+ }
}
@@ -991,7 +1001,7 @@
// Iterate through the entries in the zip file.
ZipEntry zipEntry = zipStream.getNextEntry();
- while (zipEntry != null)
+ while (zipEntry != null && !restoreConfig.isCancelled())
{
String name = zipEntry.getName();
@@ -1078,7 +1088,7 @@
long totalBytesRead = 0;
byte[] buffer = new byte[8192];
int bytesRead = zipStream.read(buffer);
- while (bytesRead > 0)
+ while (bytesRead > 0 && !restoreConfig.isCancelled())
{
totalBytesRead += bytesRead;
@@ -1153,7 +1163,8 @@
* @throws IOException If an I/O error occurs while archiving the file.
*/
private long archiveFile(ZipOutputStream zipStream,
- Mac mac, MessageDigest digest, File file)
+ Mac mac, MessageDigest digest, File file,
+ BackupConfig backupConfig)
throws IOException, FileNotFoundException
{
ZipEntry zipEntry = new ZipEntry(file.getName());
@@ -1179,7 +1190,7 @@
long totalBytesRead = 0;
byte[] buffer = new byte[8192];
int bytesRead = inputStream.read(buffer);
- while (bytesRead > 0)
+ while (bytesRead > 0 && !backupConfig.isCancelled())
{
if (mac != null)
{
--
Gitblit v1.10.0