Fix the problem that it is always in deleting phase after deleting backups (#4462)

#### What type of PR is this?

/kind bug
/area core
/milestone 2.9.x

#### What this PR does / why we need it:

Before this, if we deleted a backup without filename, the BackupReconciler would get stuck infinitely. And no further backups would be reconciled.

This PR fixes the problem that it is always in deleting phase after deleting backups.

#### Does this PR introduce a user-facing change?

```release-note
修复因备份数据状态不正常导致无法正常删除备份的问题。
```
pull/3444/head
John Niang 2023-08-23 12:16:13 +08:00 committed by GitHub
parent 3e5e50fea5
commit 67a101efeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -26,6 +26,7 @@ import org.springframework.core.io.Resource;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.server.ServerWebInputException;
import reactor.core.Exceptions;
import reactor.core.publisher.Flux;
@ -145,7 +146,8 @@ public class MigrationServiceImpl implements MigrationService {
public Mono<Void> cleanup(Backup backup) {
return Mono.<Void>create(sink -> {
var status = backup.getStatus();
if (status == null || status.getFilename() == null) {
if (status == null || !StringUtils.hasText(status.getFilename())) {
sink.success();
return;
}
var filename = status.getFilename();

View File

@ -153,6 +153,15 @@ class MigrationServiceImplTest {
assertTrue(Files.notExists(backupFile));
}
@Test
void cleanupBackupWithNoFilename() {
var backup = createSucceededBackup("fake-backup", null);
StepVerifier.create(migrationService.cleanup(backup))
.verifyComplete();
verify(haloProperties, never()).getWorkDir();
verify(backupRoot, never()).get();
}
@Test
void downloadBackupTest() throws IOException {
var backupFile = tempDir.resolve("workdir").resolve("backups").resolve("backup.zip");