Skip to content

Commit

Permalink
Fix Non-Verbose Snapshot List Missing Empty Snapshots (elastic#52433)
Browse files Browse the repository at this point in the history
We were not including snapshots without indices in the non-verbose
listing because we used the snapshot -> indices mapping to get the
snapshots.
  • Loading branch information
original-brownbear committed Feb 18, 2020
1 parent 2071f85 commit ca1147a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
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));
}
}

0 comments on commit ca1147a

Please sign in to comment.