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.
This commit is contained in:
parent
40d19532bc
commit
3be960d1c2
|
@ -184,8 +184,7 @@ public class InternalEngine extends Engine {
|
||||||
new CombinedDeletionPolicy(logger, translogDeletionPolicy, translog::getLastSyncedGlobalCheckpoint);
|
new CombinedDeletionPolicy(logger, translogDeletionPolicy, translog::getLastSyncedGlobalCheckpoint);
|
||||||
writer = createWriter();
|
writer = createWriter();
|
||||||
bootstrapAppendOnlyInfoFromWriter(writer);
|
bootstrapAppendOnlyInfoFromWriter(writer);
|
||||||
historyUUID = loadOrGenerateHistoryUUID(writer);
|
historyUUID = loadHistoryUUID(writer);
|
||||||
Objects.requireNonNull(historyUUID, "history uuid should not be null");
|
|
||||||
indexWriter = writer;
|
indexWriter = writer;
|
||||||
} catch (IOException | TranslogCorruptedException e) {
|
} catch (IOException | TranslogCorruptedException e) {
|
||||||
throw new EngineCreationFailureException(shardId, "failed to create engine", e);
|
throw new EngineCreationFailureException(shardId, "failed to create engine", e);
|
||||||
|
@ -275,10 +274,11 @@ public class InternalEngine extends Engine {
|
||||||
// steal it by calling incRef on the "stolen" reader
|
// steal it by calling incRef on the "stolen" reader
|
||||||
internalSearcherManager.maybeRefreshBlocking();
|
internalSearcherManager.maybeRefreshBlocking();
|
||||||
IndexSearcher acquire = internalSearcherManager.acquire();
|
IndexSearcher acquire = internalSearcherManager.acquire();
|
||||||
|
try {
|
||||||
final IndexReader previousReader = referenceToRefresh.getIndexReader();
|
final IndexReader previousReader = referenceToRefresh.getIndexReader();
|
||||||
assert previousReader instanceof ElasticsearchDirectoryReader:
|
assert previousReader instanceof ElasticsearchDirectoryReader:
|
||||||
"searcher's IndexReader should be an ElasticsearchDirectoryReader, but got " + previousReader;
|
"searcher's IndexReader should be an ElasticsearchDirectoryReader, but got " + previousReader;
|
||||||
try {
|
|
||||||
final IndexReader newReader = acquire.getIndexReader();
|
final IndexReader newReader = acquire.getIndexReader();
|
||||||
if (newReader == previousReader) {
|
if (newReader == previousReader) {
|
||||||
// nothing has changed - both ref managers share the same instance so we can use reference equality
|
// nothing has changed - both ref managers share the same instance so we can use reference equality
|
||||||
|
@ -473,7 +473,7 @@ public class InternalEngine extends Engine {
|
||||||
/**
|
/**
|
||||||
* Reads the current stored history ID from the IW commit data.
|
* 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);
|
final String uuid = commitDataAsMap(writer).get(HISTORY_UUID_KEY);
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
throw new IllegalStateException("commit doesn't contain history uuid");
|
throw new IllegalStateException("commit doesn't contain history uuid");
|
||||||
|
|
Loading…
Reference in New Issue