Skip to content

Commit c1923bb

Browse files
Fix Non-Verbose Snapshot List Missing Empty Snapshots (#52433) (#52457)
We were not including snapshots without indices in the non-verbose listing because we used the snapshot -> indices mapping to get the snapshots.
1 parent ac66441 commit c1923bb

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/TransportGetSnapshotsAction.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,9 @@ private List<SnapshotInfo> buildSimpleSnapshotInfos(final Set<SnapshotId> toReso
177177
}
178178
}
179179
}
180-
for (Map.Entry<SnapshotId, List<String>> entry : snapshotsToIndices.entrySet()) {
181-
final List<String> indices = entry.getValue();
180+
for (SnapshotId snapshotId : toResolve) {
181+
final List<String> indices = snapshotsToIndices.getOrDefault(snapshotId, Collections.emptyList());
182182
CollectionUtil.timSort(indices);
183-
final SnapshotId snapshotId = entry.getKey();
184183
snapshotInfos.add(new SnapshotInfo(snapshotId, indices, repositoryData.getSnapshotState(snapshotId)));
185184
}
186185
CollectionUtil.timSort(snapshotInfos);

server/src/test/java/org/elasticsearch/snapshots/SnapshotStatusApisIT.java

+24
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
4242
import static org.hamcrest.Matchers.equalTo;
4343
import static org.hamcrest.Matchers.greaterThan;
44+
import static org.hamcrest.Matchers.hasSize;
45+
import static org.hamcrest.Matchers.is;
4446

4547
public class SnapshotStatusApisIT extends AbstractSnapshotIntegTestCase {
4648

@@ -167,4 +169,26 @@ public void testExceptionOnMissingShardLevelSnapBlob() throws IOException {
167169
expectThrows(SnapshotMissingException.class, () -> client().admin().cluster()
168170
.prepareSnapshotStatus("test-repo").setSnapshots("test-snap").execute().actionGet());
169171
}
172+
173+
public void testGetSnapshotsWithoutIndices() {
174+
logger.info("--> creating repository");
175+
assertAcked(client().admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings(
176+
Settings.builder().put("location", randomRepoPath()).build()));
177+
178+
logger.info("--> snapshot");
179+
final SnapshotInfo snapshotInfo =
180+
client().admin().cluster().prepareCreateSnapshot("test-repo", "test-snap")
181+
.setIndices().setWaitForCompletion(true).get().getSnapshotInfo();
182+
183+
assertThat(snapshotInfo.state(), is(SnapshotState.SUCCESS));
184+
assertThat(snapshotInfo.totalShards(), is(0));
185+
186+
logger.info("--> verify that snapshot without index shows up in non-verbose listing");
187+
final List<SnapshotInfo> snapshotInfos =
188+
client().admin().cluster().prepareGetSnapshots("test-repo").setVerbose(false).get().getSnapshots();
189+
assertThat(snapshotInfos, hasSize(1));
190+
final SnapshotInfo found = snapshotInfos.get(0);
191+
assertThat(found.snapshotId(), is(snapshotInfo.snapshotId()));
192+
assertThat(found.state(), is(SnapshotState.SUCCESS));
193+
}
170194
}

0 commit comments

Comments
 (0)