Only pull SegmentReader once in getSegmentInfo (#27121)
This commit is contained in:
parent
0174d13ca2
commit
1460a3feac
|
@ -708,12 +708,11 @@ public abstract class Engine implements Closeable {
|
||||||
protected Segment[] getSegmentInfo(SegmentInfos lastCommittedSegmentInfos, boolean verbose) {
|
protected Segment[] getSegmentInfo(SegmentInfos lastCommittedSegmentInfos, boolean verbose) {
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
Map<String, Segment> segments = new HashMap<>();
|
Map<String, Segment> segments = new HashMap<>();
|
||||||
|
|
||||||
// first, go over and compute the search ones...
|
// first, go over and compute the search ones...
|
||||||
Searcher searcher = acquireSearcher("segments");
|
try (Searcher searcher = acquireSearcher("segments")){
|
||||||
try {
|
|
||||||
for (LeafReaderContext reader : searcher.reader().leaves()) {
|
for (LeafReaderContext reader : searcher.reader().leaves()) {
|
||||||
SegmentCommitInfo info = segmentReader(reader.reader()).getSegmentInfo();
|
final SegmentReader segmentReader = segmentReader(reader.reader());
|
||||||
|
SegmentCommitInfo info = segmentReader.getSegmentInfo();
|
||||||
assert !segments.containsKey(info.info.name);
|
assert !segments.containsKey(info.info.name);
|
||||||
Segment segment = new Segment(info.info.name);
|
Segment segment = new Segment(info.info.name);
|
||||||
segment.search = true;
|
segment.search = true;
|
||||||
|
@ -726,7 +725,6 @@ public abstract class Engine implements Closeable {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.trace((Supplier<?>) () -> new ParameterizedMessage("failed to get size for [{}]", info.info.name), e);
|
logger.trace((Supplier<?>) () -> new ParameterizedMessage("failed to get size for [{}]", info.info.name), e);
|
||||||
}
|
}
|
||||||
final SegmentReader segmentReader = segmentReader(reader.reader());
|
|
||||||
segment.memoryInBytes = segmentReader.ramBytesUsed();
|
segment.memoryInBytes = segmentReader.ramBytesUsed();
|
||||||
segment.segmentSort = info.info.getIndexSort();
|
segment.segmentSort = info.info.getIndexSort();
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
|
@ -736,8 +734,6 @@ public abstract class Engine implements Closeable {
|
||||||
// TODO: add more fine grained mem stats values to per segment info here
|
// TODO: add more fine grained mem stats values to per segment info here
|
||||||
segments.put(info.info.name, segment);
|
segments.put(info.info.name, segment);
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
searcher.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// now, correlate or add the committed ones...
|
// now, correlate or add the committed ones...
|
||||||
|
|
Loading…
Reference in New Issue