lucene 4: fix warmup process

also removed ExtendedIndexSearcher, we should do whats needed with the new context and leaves methods
This commit is contained in:
Shay Banon 2012-10-26 00:51:18 +02:00
parent 0c24928ef4
commit 81d148b4e4
4 changed files with 16 additions and 73 deletions

View File

@ -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);
}
}

View File

@ -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

View File

@ -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<IndexReader> 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

View File

@ -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) {