Skip to content

Commit 3be960d

Browse files
authored
Minor cleanup in the InternalEngine (#29241)
Fix a couple of minor things in the InternalEngine: * Rename loadOrGenerateHistoryUUID to reflect that it always generates a UUID * Move .acquire() call next to the associated try {} block.
1 parent 40d1953 commit 3be960d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ public InternalEngine(EngineConfig engineConfig) {
184184
new CombinedDeletionPolicy(logger, translogDeletionPolicy, translog::getLastSyncedGlobalCheckpoint);
185185
writer = createWriter();
186186
bootstrapAppendOnlyInfoFromWriter(writer);
187-
historyUUID = loadOrGenerateHistoryUUID(writer);
188-
Objects.requireNonNull(historyUUID, "history uuid should not be null");
187+
historyUUID = loadHistoryUUID(writer);
189188
indexWriter = writer;
190189
} catch (IOException | TranslogCorruptedException e) {
191190
throw new EngineCreationFailureException(shardId, "failed to create engine", e);
@@ -275,10 +274,11 @@ protected IndexSearcher refreshIfNeeded(IndexSearcher referenceToRefresh) throws
275274
// steal it by calling incRef on the "stolen" reader
276275
internalSearcherManager.maybeRefreshBlocking();
277276
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;
281277
try {
278+
final IndexReader previousReader = referenceToRefresh.getIndexReader();
279+
assert previousReader instanceof ElasticsearchDirectoryReader:
280+
"searcher's IndexReader should be an ElasticsearchDirectoryReader, but got " + previousReader;
281+
282282
final IndexReader newReader = acquire.getIndexReader();
283283
if (newReader == previousReader) {
284284
// nothing has changed - both ref managers share the same instance so we can use reference equality
@@ -473,7 +473,7 @@ private String loadTranslogUUIDFromLastCommit() throws IOException {
473473
/**
474474
* Reads the current stored history ID from the IW commit data.
475475
*/
476-
private String loadOrGenerateHistoryUUID(final IndexWriter writer) throws IOException {
476+
private String loadHistoryUUID(final IndexWriter writer) throws IOException {
477477
final String uuid = commitDataAsMap(writer).get(HISTORY_UUID_KEY);
478478
if (uuid == null) {
479479
throw new IllegalStateException("commit doesn't contain history uuid");

0 commit comments

Comments
 (0)