Skip to content

Commit 41909b8

Browse files
Fix Non-Verbose Snapshot List Missing Empty Snapshots (#52433)
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 616fc3b commit 41909b8

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
@@ -242,10 +242,9 @@ private static List<SnapshotInfo> buildSimpleSnapshotInfos(final Set<SnapshotId>
242242
}
243243
}
244244
}
245-
for (Map.Entry<SnapshotId, List<String>> entry : snapshotsToIndices.entrySet()) {
246-
final List<String> indices = entry.getValue();
245+
for (SnapshotId snapshotId : toResolve) {
246+
final List<String> indices = snapshotsToIndices.getOrDefault(snapshotId, Collections.emptyList());
247247
CollectionUtil.timSort(indices);
248-
final SnapshotId snapshotId = entry.getKey();
249248
snapshotInfos.add(new SnapshotInfo(snapshotId, indices, repositoryData.getSnapshotState(snapshotId)));
250249
}
251250
CollectionUtil.timSort(snapshotInfos);

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

+24
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
4343
import static org.hamcrest.Matchers.equalTo;
4444
import static org.hamcrest.Matchers.greaterThan;
45+
import static org.hamcrest.Matchers.hasSize;
4546
import static org.hamcrest.Matchers.instanceOf;
47+
import static org.hamcrest.Matchers.is;
4648

4749
public class SnapshotStatusApisIT extends AbstractSnapshotIntegTestCase {
4850

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

0 commit comments

Comments
 (0)