From 81d148b4e4d95243ec0d74a5e31504e5200d05f9 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Fri, 26 Oct 2012 00:51:18 +0200 Subject: [PATCH] lucene 4: fix warmup process also removed ExtendedIndexSearcher, we should do whats needed with the new context and leaves methods --- .../lucene/index/ExtendedIndexSearcher.java | 49 ------------------- .../elasticsearch/index/engine/Engine.java | 7 ++- .../index/engine/robin/RobinEngine.java | 26 ++++------ .../search/internal/ContextIndexSearcher.java | 7 ++- 4 files changed, 16 insertions(+), 73 deletions(-) delete mode 100644 src/main/java/org/apache/lucene/index/ExtendedIndexSearcher.java diff --git a/src/main/java/org/apache/lucene/index/ExtendedIndexSearcher.java b/src/main/java/org/apache/lucene/index/ExtendedIndexSearcher.java deleted file mode 100644 index a3bd3846771..00000000000 --- a/src/main/java/org/apache/lucene/index/ExtendedIndexSearcher.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.lucene.index; - -import org.apache.lucene.search.IndexSearcher; - -/** - * - */ -public class ExtendedIndexSearcher extends IndexSearcher { - - public ExtendedIndexSearcher(ExtendedIndexSearcher searcher) { - super(searcher.getIndexReader(), searcher.subReaders(), searcher.docStarts()); - setSimilarity(searcher.getSimilarity()); - } - - public ExtendedIndexSearcher(IndexReader r) { - super(r); - } - - public IndexReader[] subReaders() { - return this.subReaders; - } - - public int[] docStarts() { - return this.docStarts; - } - - public int readerIndex(int doc) { - return DirectoryReader.readerIndex(doc, docStarts, subReaders.length); - } -} diff --git a/src/main/java/org/elasticsearch/index/engine/Engine.java b/src/main/java/org/elasticsearch/index/engine/Engine.java index 0a5f15e7138..e08d2cb4f0c 100644 --- a/src/main/java/org/elasticsearch/index/engine/Engine.java +++ b/src/main/java/org/elasticsearch/index/engine/Engine.java @@ -21,7 +21,6 @@ package org.elasticsearch.index.engine; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.document.Document; -import org.apache.lucene.index.ExtendedIndexSearcher; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; import org.apache.lucene.search.Filter; @@ -156,7 +155,7 @@ public interface Engine extends IndexShardComponent, CloseableComponent { IndexReader reader(); - ExtendedIndexSearcher searcher(); + IndexSearcher searcher(); } static class SimpleSearcher implements Searcher { @@ -173,8 +172,8 @@ public interface Engine extends IndexShardComponent, CloseableComponent { } @Override - public ExtendedIndexSearcher searcher() { - return (ExtendedIndexSearcher) searcher; + public IndexSearcher searcher() { + return searcher; } @Override diff --git a/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java b/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java index 0734d7e589f..449ac47798d 100644 --- a/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java +++ b/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java @@ -1419,8 +1419,8 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { } @Override - public ExtendedIndexSearcher searcher() { - return (ExtendedIndexSearcher) searcher; + public IndexSearcher searcher() { + return searcher; } @Override @@ -1468,13 +1468,13 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { @Override public IndexSearcher newSearcher(IndexReader reader) throws IOException { - ExtendedIndexSearcher searcher = new ExtendedIndexSearcher(reader); + IndexSearcher searcher = new IndexSearcher(reader); searcher.setSimilarity(similarityService.defaultSearchSimilarity()); if (warmer != null) { // we need to pass a custom searcher that does not release anything on Engine.Search Release, // we will release explicitly Searcher currentSearcher = null; - ExtendedIndexSearcher newSearcher = null; + IndexSearcher newSearcher = null; boolean closeNewSearcher = false; try { if (searcherManager == null) { @@ -1484,21 +1484,21 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { currentSearcher = searcher(); // figure out the newSearcher, with only the new readers that are relevant for us List readers = Lists.newArrayList(); - for (IndexReader subReader : searcher.subReaders()) { + for (AtomicReaderContext newReaderContext : searcher.getIndexReader().leaves()) { boolean found = false; - for (IndexReader currentReader : currentSearcher.searcher().subReaders()) { - if (currentReader.getCoreCacheKey().equals(subReader.getCoreCacheKey())) { + for (AtomicReaderContext currentReaderContext : currentSearcher.reader().leaves()) { + if (currentReaderContext.reader().getCoreCacheKey().equals(newReaderContext.reader().getCoreCacheKey())) { found = true; break; } } if (!found) { - readers.add(subReader); + readers.add(newReaderContext.reader()); } } if (!readers.isEmpty()) { // we don't want to close the inner readers, just increase ref on them - newSearcher = new ExtendedIndexSearcher(new MultiReader(readers.toArray(new IndexReader[readers.size()]), false)); + newSearcher = new IndexSearcher(new MultiReader(readers.toArray(new IndexReader[readers.size()]), false)); closeNewSearcher = true; } } @@ -1520,13 +1520,7 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { } if (newSearcher != null && closeNewSearcher) { try { - newSearcher.close(); - } catch (Exception e) { - // ignore - } - try { - // close the reader as well, since closing the searcher does nothing - // and we want to decRef the inner readers + // close the reader since we want decRef the inner readers newSearcher.getIndexReader().close(); } catch (IOException e) { // ignore diff --git a/src/main/java/org/elasticsearch/search/internal/ContextIndexSearcher.java b/src/main/java/org/elasticsearch/search/internal/ContextIndexSearcher.java index 3056befe761..ab5f2c46271 100644 --- a/src/main/java/org/elasticsearch/search/internal/ContextIndexSearcher.java +++ b/src/main/java/org/elasticsearch/search/internal/ContextIndexSearcher.java @@ -22,7 +22,6 @@ package org.elasticsearch.search.internal; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import org.apache.lucene.index.ExtendedIndexSearcher; import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.*; import org.elasticsearch.common.lucene.MinimumScoreCollector; @@ -39,7 +38,7 @@ import java.util.Map; /** * */ -public class ContextIndexSearcher extends ExtendedIndexSearcher { +public class ContextIndexSearcher extends IndexSearcher { public static final class Scopes { public static final String MAIN = "_main_"; @@ -58,9 +57,9 @@ public class ContextIndexSearcher extends ExtendedIndexSearcher { private String processingScope; public ContextIndexSearcher(SearchContext searchContext, Engine.Searcher searcher) { - super(searcher.searcher()); + super(searcher.reader()); this.searchContext = searchContext; - this.reader = searcher.searcher().getIndexReader(); + this.reader = searcher.reader(); } public void dfSource(CachedDfSource dfSource) {