Skip to content

Commit

Permalink
Minor cleanup in the InternalEngine (#29241)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DaveCTurner committed Apr 2, 2018
1 parent 40d1953 commit 3be960d
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ public InternalEngine(EngineConfig engineConfig) {
new CombinedDeletionPolicy(logger, translogDeletionPolicy, translog::getLastSyncedGlobalCheckpoint);
writer = createWriter();
bootstrapAppendOnlyInfoFromWriter(writer);
historyUUID = loadOrGenerateHistoryUUID(writer);
Objects.requireNonNull(historyUUID, "history uuid should not be null");
historyUUID = loadHistoryUUID(writer);
indexWriter = writer;
} catch (IOException | TranslogCorruptedException e) {
throw new EngineCreationFailureException(shardId, "failed to create engine", e);
Expand Down Expand Up @@ -275,10 +274,11 @@ protected IndexSearcher refreshIfNeeded(IndexSearcher referenceToRefresh) throws
// steal it by calling incRef on the "stolen" reader
internalSearcherManager.maybeRefreshBlocking();
IndexSearcher acquire = internalSearcherManager.acquire();
final IndexReader previousReader = referenceToRefresh.getIndexReader();
assert previousReader instanceof ElasticsearchDirectoryReader:
"searcher's IndexReader should be an ElasticsearchDirectoryReader, but got " + previousReader;
try {
final IndexReader previousReader = referenceToRefresh.getIndexReader();
assert previousReader instanceof ElasticsearchDirectoryReader:
"searcher's IndexReader should be an ElasticsearchDirectoryReader, but got " + previousReader;

final IndexReader newReader = acquire.getIndexReader();
if (newReader == previousReader) {
// nothing has changed - both ref managers share the same instance so we can use reference equality
Expand Down Expand Up @@ -473,7 +473,7 @@ private String loadTranslogUUIDFromLastCommit() throws IOException {
/**
* Reads the current stored history ID from the IW commit data.
*/
private String loadOrGenerateHistoryUUID(final IndexWriter writer) throws IOException {
private String loadHistoryUUID(final IndexWriter writer) throws IOException {
final String uuid = commitDataAsMap(writer).get(HISTORY_UUID_KEY);
if (uuid == null) {
throw new IllegalStateException("commit doesn't contain history uuid");
Expand Down

0 comments on commit 3be960d

Please sign in to comment.