|
20 | 20 | package org.elasticsearch.index.engine;
|
21 | 21 |
|
22 | 22 | import org.apache.logging.log4j.Logger;
|
23 |
| -import org.apache.logging.log4j.message.ParameterizedMessage; |
24 | 23 | import org.apache.lucene.document.Field;
|
25 | 24 | import org.apache.lucene.document.NumericDocValuesField;
|
26 | 25 | import org.apache.lucene.index.DirectoryReader;
|
|
53 | 52 | import org.elasticsearch.common.Nullable;
|
54 | 53 | import org.elasticsearch.common.SuppressForbidden;
|
55 | 54 | import org.elasticsearch.common.lease.Releasable;
|
56 |
| -import org.elasticsearch.common.lease.Releasables; |
57 | 55 | import org.elasticsearch.common.lucene.LoggerInfoStream;
|
58 | 56 | import org.elasticsearch.common.lucene.Lucene;
|
59 | 57 | import org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader;
|
@@ -1527,19 +1525,11 @@ final void refresh(String source, SearcherScope scope) throws EngineException {
|
1527 | 1525 | if (store.tryIncRef()) {
|
1528 | 1526 | // increment the ref just to ensure nobody closes the store during a refresh
|
1529 | 1527 | try {
|
1530 |
| - switch (scope) { |
1531 |
| - case EXTERNAL: |
1532 |
| - // even though we maintain 2 managers we really do the heavy-lifting only once. |
1533 |
| - // the second refresh will only do the extra work we have to do for warming caches etc. |
1534 |
| - externalSearcherManager.maybeRefreshBlocking(); |
1535 |
| - // the break here is intentional we never refresh both internal / external together |
1536 |
| - break; |
1537 |
| - case INTERNAL: |
1538 |
| - internalSearcherManager.maybeRefreshBlocking(); |
1539 |
| - break; |
1540 |
| - default: |
1541 |
| - throw new IllegalArgumentException("unknown scope: " + scope); |
1542 |
| - } |
| 1528 | + // even though we maintain 2 managers we really do the heavy-lifting only once. |
| 1529 | + // the second refresh will only do the extra work we have to do for warming caches etc. |
| 1530 | + ReferenceManager<IndexSearcher> referenceManager = getReferenceManager(scope); |
| 1531 | + // it is intentional that we never refresh both internal / external together |
| 1532 | + referenceManager.maybeRefreshBlocking(); |
1543 | 1533 | } finally {
|
1544 | 1534 | store.decRef();
|
1545 | 1535 | }
|
@@ -2090,37 +2080,14 @@ protected final void closeNoLock(String reason, CountDownLatch closedLatch) {
|
2090 | 2080 | }
|
2091 | 2081 |
|
2092 | 2082 | @Override
|
2093 |
| - public Searcher acquireSearcher(String source, SearcherScope scope) { |
2094 |
| - /* Acquire order here is store -> manager since we need |
2095 |
| - * to make sure that the store is not closed before |
2096 |
| - * the searcher is acquired. */ |
2097 |
| - if (store.tryIncRef() == false) { |
2098 |
| - throw new AlreadyClosedException(shardId + " store is closed", failedEngine.get()); |
2099 |
| - } |
2100 |
| - Releasable releasable = store::decRef; |
2101 |
| - try { |
2102 |
| - final ReferenceManager<IndexSearcher> referenceManager; |
2103 |
| - switch (scope) { |
2104 |
| - case INTERNAL: |
2105 |
| - referenceManager = internalSearcherManager; |
2106 |
| - break; |
2107 |
| - case EXTERNAL: |
2108 |
| - referenceManager = externalSearcherManager; |
2109 |
| - break; |
2110 |
| - default: |
2111 |
| - throw new IllegalStateException("unknown scope: " + scope); |
2112 |
| - } |
2113 |
| - EngineSearcher engineSearcher = new EngineSearcher(source, referenceManager, store, logger); |
2114 |
| - releasable = null; // success - hand over the reference to the engine searcher |
2115 |
| - return engineSearcher; |
2116 |
| - } catch (AlreadyClosedException ex) { |
2117 |
| - throw ex; |
2118 |
| - } catch (Exception ex) { |
2119 |
| - ensureOpen(ex); // throw EngineCloseException here if we are already closed |
2120 |
| - logger.error(() -> new ParameterizedMessage("failed to acquire searcher, source {}", source), ex); |
2121 |
| - throw new EngineException(shardId, "failed to acquire searcher, source " + source, ex); |
2122 |
| - } finally { |
2123 |
| - Releasables.close(releasable); |
| 2083 | + protected final ReferenceManager<IndexSearcher> getReferenceManager(SearcherScope scope) { |
| 2084 | + switch (scope) { |
| 2085 | + case INTERNAL: |
| 2086 | + return internalSearcherManager; |
| 2087 | + case EXTERNAL: |
| 2088 | + return externalSearcherManager; |
| 2089 | + default: |
| 2090 | + throw new IllegalStateException("unknown scope: " + scope); |
2124 | 2091 | }
|
2125 | 2092 | }
|
2126 | 2093 |
|
|
0 commit comments