Skip to content

Commit

Permalink
#XD-465 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
penemue committed Sep 10, 2015
1 parent 80c33f0 commit d928ee2
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,28 @@ public static File backup(@NotNull final Backupable target, @NotNull final File
final String fileName = getTimeStampedTarGzFileName();
backupFile = new File(backupRoot, backupNamePrefix == null ? fileName : backupNamePrefix + fileName);
archive = new TarArchiveOutputStream(new GZIPOutputStream(
new BufferedOutputStream(new FileOutputStream(backupFile)), 0x1000));
new BufferedOutputStream(new FileOutputStream(backupFile))));
}
for (final BackupStrategy.FileDescriptor fd : strategy.listFiles()) {
final File file = fd.getFile();
if (file.isFile()) {
final long fileSize = Math.min(fd.getFileSize(), strategy.acceptFile(file));
if (fileSize > 0L) {
archiveFile(archive, fd.getPath(), file, fileSize);
try (ArchiveOutputStream aos = archive) {
for (final BackupStrategy.FileDescriptor fd : strategy.listFiles()) {
if (strategy.isInterrupted()) {
break;
}
final File file = fd.getFile();
if (file.isFile()) {
final long fileSize = Math.min(fd.getFileSize(), strategy.acceptFile(file));
if (fileSize > 0L) {
archiveFile(aos, fd.getPath(), file, fileSize);
}
}
}
}
archive.close();
logger.info("Backup file \"" + backupFile.getName() + "\" created.");
if (strategy.isInterrupted()) {
logger.info("Backup interrupted, deleting \"" + backupFile.getName() + "\"...");
IOUtil.deleteFile(backupFile);
} else {
logger.info("Backup file \"" + backupFile.getName() + "\" created.");
}
} catch (Throwable t) {
strategy.onError(t);
throw ExodusException.toExodusException(t, "Backup failed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package jetbrains.exodus.entitystore;

import jetbrains.exodus.BackupStrategy;
import jetbrains.exodus.Backupable;
import jetbrains.exodus.TestUtil;
import jetbrains.exodus.core.execution.Job;
import jetbrains.exodus.core.execution.JobProcessor;
Expand Down Expand Up @@ -90,6 +91,48 @@ public void testStressWithBackupBean() throws Exception {
doStressTest(true);
}

public void testInterruptedIsDeleted() throws Exception {
testSingular();
final File backupDir = TestUtil.createTempDir();
try {
final BackupStrategy storeBackupStrategy = getEntityStore().getBackupStrategy();
final File backup = CompressBackupUtil.backup(new Backupable() {
@Override
public BackupStrategy getBackupStrategy() {
return new BackupStrategy() {
@Override
public void beforeBackup() throws Exception {
storeBackupStrategy.beforeBackup();
}

@Override
public Iterable<FileDescriptor> listFiles() {
return storeBackupStrategy.listFiles();
}

@Override
public void afterBackup() throws Exception {
storeBackupStrategy.afterBackup();
}

@Override
public boolean isInterrupted() {
return true;
}

@Override
public long acceptFile(@NotNull File file) {
return storeBackupStrategy.acceptFile(file);
}
};
}
}, backupDir, null, true);
assertFalse(backup.exists());
} finally {
IOUtil.deleteRecursively(backupDir);
}
}

public void doStressTest(final boolean useBackupBean) throws Exception {
final PersistentEntityStoreImpl store = getEntityStore();
store.getConfig().setMaxInPlaceBlobSize(0); // no in-place blobs
Expand Down
4 changes: 4 additions & 0 deletions openAPI/src/main/java/jetbrains/exodus/BackupStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public void beforeBackup() throws Exception {
public void afterBackup() throws Exception {
}

public boolean isInterrupted() {
return false;
}

public void onError(Throwable t) {
}

Expand Down

0 comments on commit d928ee2

Please sign in to comment.