Skip to content

Commit 3aa4e6b

Browse files
committed
Acquire seacher on closing engine should throw AlreadyClosedException
Closes elastic#33330
1 parent ce635f5 commit 3aa4e6b

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,12 +1994,14 @@ protected final void closeNoLock(String reason, CountDownLatch closedLatch) {
19941994

19951995
@Override
19961996
public Searcher acquireSearcher(String source, SearcherScope scope) {
1997-
/* Acquire order here is store -> manager since we need
1998-
* to make sure that the store is not closed before
1999-
* the searcher is acquired. */
2000-
store.incRef();
2001-
Releasable releasable = store::decRef;
1997+
ensureOpen();
1998+
Releasable releasable = null;
20021999
try {
2000+
/* Acquire order here is store -> manager since we need
2001+
* to make sure that the store is not closed before
2002+
* the searcher is acquired. */
2003+
store.incRef();
2004+
releasable = store::decRef;
20032005
final ReferenceManager<IndexSearcher> referenceManager;
20042006
switch (scope) {
20052007
case INTERNAL:

server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5020,6 +5020,11 @@ public void testLastRefreshCheckpoint() throws Exception {
50205020
assertThat(engine.lastRefreshedCheckpoint(), equalTo(engine.getLocalCheckpoint()));
50215021
}
50225022

5023+
public void testAcquireSearcherOnClosingEngine() throws Exception {
5024+
engine.close();
5025+
expectThrows(AlreadyClosedException.class, () -> engine.acquireSearcher("test"));
5026+
}
5027+
50235028
private static void trimUnsafeCommits(EngineConfig config) throws IOException {
50245029
final Store store = config.getStore();
50255030
final TranslogConfig translogConfig = config.getTranslogConfig();

0 commit comments

Comments
 (0)