Skip to content

Commit 11e0d46

Browse files
authored
Store: support empty stores in cleanupAndVerify (#116059) (#116117)
Until now if `store.cleanupAndVerify` was called on a store with no commits, it would throw `IndexNotFoundException`. Based on variable naming (`metadataOrEmpty`), this appears to be unintentional, though the issue has been present since the `cleanupAndVerify` method was introduced. This change is motivated by #104473 - I would like to be able to use this method to clean up a store prior to recovery regardless of how far along a previous recovery attempt got.
1 parent f63cf67 commit 11e0d46

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

server/src/main/java/org/elasticsearch/index/store/Store.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,12 @@ public void cleanupAndVerify(String reason, MetadataSnapshot sourceMetadata) thr
687687
}
688688
}
689689
directory.syncMetaData();
690-
final Store.MetadataSnapshot metadataOrEmpty = getMetadata(null);
690+
Store.MetadataSnapshot metadataOrEmpty;
691+
try {
692+
metadataOrEmpty = getMetadata(null);
693+
} catch (IndexNotFoundException e) {
694+
metadataOrEmpty = MetadataSnapshot.EMPTY;
695+
}
691696
verifyAfterCleanup(sourceMetadata, metadataOrEmpty);
692697
} finally {
693698
metadataLock.writeLock().unlock();

server/src/test/java/org/elasticsearch/index/store/StoreTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,15 @@ public void testCleanupFromSnapshot() throws IOException {
733733
IOUtils.close(store);
734734
}
735735

736+
public void testCleanupEmptyStore() throws IOException {
737+
final ShardId shardId = new ShardId("index", "_na_", 1);
738+
Store store = new Store(shardId, INDEX_SETTINGS, StoreTests.newDirectory(random()), new DummyShardLock(shardId));
739+
740+
store.cleanupAndVerify("test", Store.MetadataSnapshot.EMPTY);
741+
742+
IOUtils.close(store);
743+
}
744+
736745
public void testOnCloseCallback() throws IOException {
737746
final ShardId shardId = new ShardId(
738747
new Index(randomRealisticUnicodeOfCodepointLengthBetween(1, 10), "_na_"),

0 commit comments

Comments
 (0)