Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc
title: Incremental backup failures now report the original error instead of an unrelated missing zk_backup directory exception
type: fixed
authors:
- name: Prithvi S
links:
- name: SOLR-18303
url: https://issues.apache.org/jira/browse/SOLR-18303
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,16 @@ public void call(AdminCmdContext adminCmdContext, ZkNodeProps message, NamedList
"Error happened during incremental backup for collection: {}",
collectionName,
e);
CollectionHandlingUtils.cleanBackup(
repository, backupUri, backupMgr.getBackupId(), ccc);
try {
CollectionHandlingUtils.cleanBackup(
repository, backupUri, backupMgr.getBackupId(), ccc);
} catch (Exception cleanupException) {
log.warn(
"Unable to clean up incomplete backup for collection: {}",
collectionName,
cleanupException);
e.addSuppressed(cleanupException);
}
throw e;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.net.URI;
import java.nio.file.NoSuchFileException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -206,13 +207,14 @@ void deleteBackupIds(
.map(ShardBackupId::getBackupMetadataFilename)
.collect(Collectors.toList()));
repository.delete(incBackupFiles.getIndexDir(), unusedFiles);
try {
for (BackupId backupId : backupIdsDeletes) {
repository.deleteDirectory(
repository.resolveDirectory(backupUri, BackupFilePaths.getZkStateDir(backupId)));
for (BackupId backupId : backupIdsDeletes) {
URI zkStateDir =
repository.resolveDirectory(backupUri, BackupFilePaths.getZkStateDir(backupId));
try {
repository.deleteDirectory(zkStateDir);
} catch (FileNotFoundException | NoSuchFileException e) {
// zk_backup_* is created after shard copy, so a failed incremental backup may not have it
}
} catch (FileNotFoundException e) {
// ignore this
}

// add details to result before deleting backupPropFiles
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.cloud.api.collections;

import java.io.IOException;
import java.net.URI;
import java.util.Set;
import java.util.UUID;
import org.apache.solr.SolrTestCase;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.backup.BackupFilePaths;
import org.apache.solr.core.backup.BackupId;
import org.apache.solr.core.backup.repository.BackupRepository;
import org.apache.solr.core.backup.repository.LocalFileSystemRepository;
import org.junit.Before;
import org.junit.Test;

/** Unit tests for {@link DeleteBackupCmd}. */
public class DeleteBackupCmdTest extends SolrTestCase {

private BackupRepository repository;
private URI backupUri;

@Before
public void setUpRepo() throws Exception {
repository = new LocalFileSystemRepository();
backupUri =
repository.createDirectoryURI(
createTempDir("backup_" + UUID.randomUUID()).toAbsolutePath().toString());
new BackupFilePaths(repository, backupUri).createIncrementalBackupFolders();
}

@Test
public void testDeleteBackupIdsIgnoresMissingZkStateDir() throws Exception {
NamedList<Object> results = new NamedList<>();
new DeleteBackupCmd(null)
.deleteBackupIds(backupUri, repository, Set.of(BackupId.zero()), results);

assertNotNull(results.get("deleted"));
assertFalse(repository.exists(zkStateDir(BackupId.zero())));
}

@Test
public void testDeleteBackupIdsRemovesExistingZkStateDir() throws Exception {
URI zkStateDir = zkStateDir(BackupId.zero());
repository.createDirectory(zkStateDir);
assertTrue(repository.exists(zkStateDir));

new DeleteBackupCmd(null)
.deleteBackupIds(backupUri, repository, Set.of(BackupId.zero()), new NamedList<>());

assertFalse(repository.exists(zkStateDir));
}

@Test
public void testDeleteBackupIdsPropagatesUnexpectedDeleteErrors() {
BackupRepository failingRepository =
new LocalFileSystemRepository() {
@Override
public void deleteDirectory(URI path) throws IOException {
throw new IOException("simulated repository failure");
}
};

IOException thrown =
expectThrows(
IOException.class,
() ->
new DeleteBackupCmd(null)
.deleteBackupIds(
backupUri, failingRepository, Set.of(BackupId.zero()), new NamedList<>()));
assertEquals("simulated repository failure", thrown.getMessage());
}

private URI zkStateDir(BackupId backupId) {
return repository.resolveDirectory(backupUri, BackupFilePaths.getZkStateDir(backupId));
}
}