From f4418fb181881d5e5158fc97b01291210599e7a8 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Fri, 26 Oct 2012 00:27:29 +0200 Subject: [PATCH] lucene 4: fix segments info usage --- .../elasticsearch/common/lucene/Lucene.java | 4 +- .../index/engine/robin/RobinEngine.java | 41 ++++++++----------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/elasticsearch/common/lucene/Lucene.java b/src/main/java/org/elasticsearch/common/lucene/Lucene.java index 6929b163224..1e7e8688cb4 100644 --- a/src/main/java/org/elasticsearch/common/lucene/Lucene.java +++ b/src/main/java/org/elasticsearch/common/lucene/Lucene.java @@ -312,9 +312,9 @@ public class Lucene { segmentReaderSegmentInfoField = segmentReaderSegmentInfoFieldX; } - public static SegmentInfo getSegmentInfo(SegmentReader reader) { + public static SegmentInfoPerCommit getSegmentInfo(SegmentReader reader) { try { - return (SegmentInfo) segmentReaderSegmentInfoField.get(reader); + return (SegmentInfoPerCommit) segmentReaderSegmentInfoField.get(reader); } catch (IllegalAccessException e) { return null; } 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 7505aa2e9da..0734d7e589f 100644 --- a/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java +++ b/src/main/java/org/elasticsearch/index/engine/robin/RobinEngine.java @@ -1179,21 +1179,20 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { // first, go over and compute the search ones... Searcher searcher = searcher(); try { - IndexReader[] readers = searcher.reader().getSequentialSubReaders(); - for (IndexReader reader : readers) { - assert reader instanceof SegmentReader; - SegmentInfo info = Lucene.getSegmentInfo((SegmentReader) reader); - assert !segments.containsKey(info.name); - Segment segment = new Segment(info.name); + for (AtomicReaderContext reader : searcher.reader().leaves()) { + assert reader.reader() instanceof SegmentReader; + SegmentInfoPerCommit info = Lucene.getSegmentInfo((SegmentReader) reader.reader()); + assert !segments.containsKey(info.info.name); + Segment segment = new Segment(info.info.name); segment.search = true; - segment.docCount = reader.numDocs(); - segment.delDocCount = reader.numDeletedDocs(); + segment.docCount = reader.reader().numDocs(); + segment.delDocCount = reader.reader().numDeletedDocs(); try { - segment.sizeInBytes = info.sizeInBytes(true); + segment.sizeInBytes = info.sizeInBytes(); } catch (IOException e) { - logger.trace("failed to get size for [{}]", e, info.name); + logger.trace("failed to get size for [{}]", e, info.info.name); } - segments.put(info.name, segment); + segments.put(info.info.name, segment); } } finally { searcher.release(); @@ -1202,24 +1201,20 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine { // now, correlate or add the committed ones... if (lastCommittedSegmentInfos != null) { SegmentInfos infos = lastCommittedSegmentInfos; - for (SegmentInfo info : infos) { - Segment segment = segments.get(info.name); + for (SegmentInfoPerCommit info : infos) { + Segment segment = segments.get(info.info.name); if (segment == null) { - segment = new Segment(info.name); + segment = new Segment(info.info.name); segment.search = false; segment.committed = true; - segment.docCount = info.docCount; + segment.docCount = info.info.getDocCount(); + segment.delDocCount = info.getDelCount(); try { - segment.delDocCount = indexWriter.numDeletedDocs(info); + segment.sizeInBytes = info.sizeInBytes(); } catch (IOException e) { - logger.trace("failed to get deleted docs for committed segment", e); + logger.trace("failed to get size for [{}]", e, info.info.name); } - try { - segment.sizeInBytes = info.sizeInBytes(true); - } catch (IOException e) { - logger.trace("failed to get size for [{}]", e, info.name); - } - segments.put(info.name, segment); + segments.put(info.info.name, segment); } else { segment.committed = true; }