Skip to content

Commit 8cc76e4

Browse files
authored
Store: support empty stores in cleanupAndVerify (#116059)
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 7ab02be commit 8cc76e4

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
@@ -696,7 +696,12 @@ public void cleanupAndVerify(String reason, MetadataSnapshot sourceMetadata) thr
696696
}
697697
}
698698
directory.syncMetaData();
699-
final Store.MetadataSnapshot metadataOrEmpty = getMetadata(null);
699+
Store.MetadataSnapshot metadataOrEmpty;
700+
try {
701+
metadataOrEmpty = getMetadata(null);
702+
} catch (IndexNotFoundException e) {
703+
metadataOrEmpty = MetadataSnapshot.EMPTY;
704+
}
700705
verifyAfterCleanup(sourceMetadata, metadataOrEmpty);
701706
} finally {
702707
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
@@ -732,6 +732,15 @@ public void testCleanupFromSnapshot() throws IOException {
732732
IOUtils.close(store);
733733
}
734734

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

0 commit comments

Comments
 (0)