Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Non-Verbose Snapshot List Missing Empty Snapshots (#52433) #52456

Merged
merged 1 commit into from
Feb 18, 2020
Merged
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
Expand Up @@ -180,10 +180,9 @@ private List<SnapshotInfo> buildSimpleSnapshotInfos(final Set<SnapshotId> toReso
}
}
}
for (Map.Entry<SnapshotId, List<String>> entry : snapshotsToIndices.entrySet()) {
final List<String> indices = entry.getValue();
for (SnapshotId snapshotId : toResolve) {
final List<String> indices = snapshotsToIndices.getOrDefault(snapshotId, Collections.emptyList());
CollectionUtil.timSort(indices);
final SnapshotId snapshotId = entry.getKey();
snapshotInfos.add(new SnapshotInfo(snapshotId, indices, repositoryData.getSnapshotState(snapshotId)));
}
CollectionUtil.timSort(snapshotInfos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;

public class SnapshotStatusApisIT extends AbstractSnapshotIntegTestCase {

Expand Down Expand Up @@ -167,4 +169,26 @@ public void testExceptionOnMissingShardLevelSnapBlob() throws IOException {
expectThrows(SnapshotMissingException.class, () -> client().admin().cluster()
.prepareSnapshotStatus("test-repo").setSnapshots("test-snap").execute().actionGet());
}

public void testGetSnapshotsWithoutIndices() {
logger.info("--> creating repository");
assertAcked(client().admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings(
Settings.builder().put("location", randomRepoPath()).build()));

logger.info("--> snapshot");
final SnapshotInfo snapshotInfo =
client().admin().cluster().prepareCreateSnapshot("test-repo", "test-snap")
.setIndices().setWaitForCompletion(true).get().getSnapshotInfo();

assertThat(snapshotInfo.state(), is(SnapshotState.SUCCESS));
assertThat(snapshotInfo.totalShards(), is(0));

logger.info("--> verify that snapshot without index shows up in non-verbose listing");
final List<SnapshotInfo> snapshotInfos =
client().admin().cluster().prepareGetSnapshots("test-repo").setVerbose(false).get().getSnapshots();
assertThat(snapshotInfos, hasSize(1));
final SnapshotInfo found = snapshotInfos.get(0);
assertThat(found.snapshotId(), is(snapshotInfo.snapshotId()));
assertThat(found.state(), is(SnapshotState.SUCCESS));
}
}