From 9e3b813b6299727279f70d4a896e9dc3e1272677 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Sat, 18 Apr 2020 11:37:41 -0400 Subject: [PATCH] Ensure not to open directory reader on transport thread (#55419) This change adds an assertion making sure that we won't accidentally open directory readers using transport threads. --- .../java/org/elasticsearch/index/engine/ReadOnlyEngine.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java b/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java index e083299f7a3..9c8858a91ff 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java +++ b/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java @@ -41,6 +41,7 @@ import org.elasticsearch.index.translog.TranslogConfig; import org.elasticsearch.index.translog.TranslogDeletionPolicy; import org.elasticsearch.index.translog.TranslogStats; import org.elasticsearch.search.suggest.completion.CompletionStats; +import org.elasticsearch.transport.Transports; import java.io.Closeable; import java.io.IOException; @@ -178,6 +179,7 @@ public class ReadOnlyEngine extends Engine { } protected DirectoryReader open(IndexCommit commit) throws IOException { + assert Transports.assertNotTransportThread("opening index commit of a read-only engine"); return DirectoryReader.open(commit, OFF_HEAP_READER_ATTRIBUTES); } @@ -514,6 +516,7 @@ public class ReadOnlyEngine extends Engine { } protected static DirectoryReader openDirectory(Directory directory, boolean wrapSoftDeletes) throws IOException { + assert Transports.assertNotTransportThread("opening directory reader of a read-only engine"); final DirectoryReader reader = DirectoryReader.open(directory, OFF_HEAP_READER_ATTRIBUTES); if (wrapSoftDeletes) { return new SoftDeletesDirectoryReaderWrapper(reader, Lucene.SOFT_DELETES_FIELD);