Skip to content

Commit d9859cb

Browse files
committed
Minor cleanup in the InternalEngine (#29241)
* Rename loadOrGenerateHistoryUUID to reflect that it always generates a UUID * Move .acquire() call next to the associated try {} block.
1 parent a8a19bf commit d9859cb

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public InternalEngine(EngineConfig engineConfig) {
185185
new CombinedDeletionPolicy(logger, translogDeletionPolicy, translog::getLastSyncedGlobalCheckpoint);
186186
writer = createWriter();
187187
bootstrapAppendOnlyInfoFromWriter(writer);
188-
historyUUID = Objects.requireNonNull(loadOrGenerateHistoryUUID(writer), "history uuid should not be null");
188+
historyUUID = loadHistoryUUID(writer);
189189
indexWriter = writer;
190190
} catch (IOException | TranslogCorruptedException e) {
191191
throw new EngineCreationFailureException(shardId, "failed to create engine", e);
@@ -275,10 +275,11 @@ protected IndexSearcher refreshIfNeeded(IndexSearcher referenceToRefresh) throws
275275
// steal it by calling incRef on the "stolen" reader
276276
internalSearcherManager.maybeRefreshBlocking();
277277
IndexSearcher acquire = internalSearcherManager.acquire();
278-
final IndexReader previousReader = referenceToRefresh.getIndexReader();
279-
assert previousReader instanceof ElasticsearchDirectoryReader:
280-
"searcher's IndexReader should be an ElasticsearchDirectoryReader, but got " + previousReader;
281278
try {
279+
final IndexReader previousReader = referenceToRefresh.getIndexReader();
280+
assert previousReader instanceof ElasticsearchDirectoryReader:
281+
"searcher's IndexReader should be an ElasticsearchDirectoryReader, but got " + previousReader;
282+
282283
final IndexReader newReader = acquire.getIndexReader();
283284
if (newReader == previousReader) {
284285
// nothing has changed - both ref managers share the same instance so we can use reference equality
@@ -481,7 +482,7 @@ private String loadTranslogUUIDFromLastCommit() throws IOException {
481482
/**
482483
* Reads the current stored history ID from the IW commit data.
483484
*/
484-
private String loadOrGenerateHistoryUUID(final IndexWriter writer) throws IOException {
485+
private String loadHistoryUUID(final IndexWriter writer) throws IOException {
485486
final String uuid = commitDataAsMap(writer).get(HISTORY_UUID_KEY);
486487
if (uuid == null) {
487488
throw new IllegalStateException("commit doesn't contain history uuid");

0 commit comments

Comments
 (0)