lucene 4: fix segments info usage
This commit is contained in:
parent
7972f6f959
commit
f4418fb181
|
@ -312,9 +312,9 @@ public class Lucene {
|
||||||
segmentReaderSegmentInfoField = segmentReaderSegmentInfoFieldX;
|
segmentReaderSegmentInfoField = segmentReaderSegmentInfoFieldX;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SegmentInfo getSegmentInfo(SegmentReader reader) {
|
public static SegmentInfoPerCommit getSegmentInfo(SegmentReader reader) {
|
||||||
try {
|
try {
|
||||||
return (SegmentInfo) segmentReaderSegmentInfoField.get(reader);
|
return (SegmentInfoPerCommit) segmentReaderSegmentInfoField.get(reader);
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1179,21 +1179,20 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine {
|
||||||
// first, go over and compute the search ones...
|
// first, go over and compute the search ones...
|
||||||
Searcher searcher = searcher();
|
Searcher searcher = searcher();
|
||||||
try {
|
try {
|
||||||
IndexReader[] readers = searcher.reader().getSequentialSubReaders();
|
for (AtomicReaderContext reader : searcher.reader().leaves()) {
|
||||||
for (IndexReader reader : readers) {
|
assert reader.reader() instanceof SegmentReader;
|
||||||
assert reader instanceof SegmentReader;
|
SegmentInfoPerCommit info = Lucene.getSegmentInfo((SegmentReader) reader.reader());
|
||||||
SegmentInfo info = Lucene.getSegmentInfo((SegmentReader) reader);
|
assert !segments.containsKey(info.info.name);
|
||||||
assert !segments.containsKey(info.name);
|
Segment segment = new Segment(info.info.name);
|
||||||
Segment segment = new Segment(info.name);
|
|
||||||
segment.search = true;
|
segment.search = true;
|
||||||
segment.docCount = reader.numDocs();
|
segment.docCount = reader.reader().numDocs();
|
||||||
segment.delDocCount = reader.numDeletedDocs();
|
segment.delDocCount = reader.reader().numDeletedDocs();
|
||||||
try {
|
try {
|
||||||
segment.sizeInBytes = info.sizeInBytes(true);
|
segment.sizeInBytes = info.sizeInBytes();
|
||||||
} catch (IOException e) {
|
} 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 {
|
} finally {
|
||||||
searcher.release();
|
searcher.release();
|
||||||
|
@ -1202,24 +1201,20 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine {
|
||||||
// now, correlate or add the committed ones...
|
// now, correlate or add the committed ones...
|
||||||
if (lastCommittedSegmentInfos != null) {
|
if (lastCommittedSegmentInfos != null) {
|
||||||
SegmentInfos infos = lastCommittedSegmentInfos;
|
SegmentInfos infos = lastCommittedSegmentInfos;
|
||||||
for (SegmentInfo info : infos) {
|
for (SegmentInfoPerCommit info : infos) {
|
||||||
Segment segment = segments.get(info.name);
|
Segment segment = segments.get(info.info.name);
|
||||||
if (segment == null) {
|
if (segment == null) {
|
||||||
segment = new Segment(info.name);
|
segment = new Segment(info.info.name);
|
||||||
segment.search = false;
|
segment.search = false;
|
||||||
segment.committed = true;
|
segment.committed = true;
|
||||||
segment.docCount = info.docCount;
|
segment.docCount = info.info.getDocCount();
|
||||||
|
segment.delDocCount = info.getDelCount();
|
||||||
try {
|
try {
|
||||||
segment.delDocCount = indexWriter.numDeletedDocs(info);
|
segment.sizeInBytes = info.sizeInBytes();
|
||||||
} catch (IOException e) {
|
} 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 {
|
segments.put(info.info.name, segment);
|
||||||
segment.sizeInBytes = info.sizeInBytes(true);
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.trace("failed to get size for [{}]", e, info.name);
|
|
||||||
}
|
|
||||||
segments.put(info.name, segment);
|
|
||||||
} else {
|
} else {
|
||||||
segment.committed = true;
|
segment.committed = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue