use of org.apache.lucene.index.SegmentReader in project elasticsearch by elastic.
the class Engine method segmentsStats.
/**
* Global stats on segments.
*/
public final SegmentsStats segmentsStats(boolean includeSegmentFileSizes) {
ensureOpen();
try (Searcher searcher = acquireSearcher("segments_stats")) {
SegmentsStats stats = new SegmentsStats();
for (LeafReaderContext reader : searcher.reader().leaves()) {
final SegmentReader segmentReader = segmentReader(reader.reader());
stats.add(1, segmentReader.ramBytesUsed());
stats.addTermsMemoryInBytes(guardedRamBytesUsed(segmentReader.getPostingsReader()));
stats.addStoredFieldsMemoryInBytes(guardedRamBytesUsed(segmentReader.getFieldsReader()));
stats.addTermVectorsMemoryInBytes(guardedRamBytesUsed(segmentReader.getTermVectorsReader()));
stats.addNormsMemoryInBytes(guardedRamBytesUsed(segmentReader.getNormsReader()));
stats.addPointsMemoryInBytes(guardedRamBytesUsed(segmentReader.getPointsReader()));
stats.addDocValuesMemoryInBytes(guardedRamBytesUsed(segmentReader.getDocValuesReader()));
if (includeSegmentFileSizes) {
// TODO: consider moving this to StoreStats
stats.addFileSizes(getSegmentFileSizes(segmentReader));
}
}
writerSegmentStats(stats);
return stats;
}
}
use of org.apache.lucene.index.SegmentReader in project lucene-solr by apache.
the class TestMergePolicyConfig method assertCompoundSegments.
/**
* Given an IndexReader, asserts that there is at least one AtomcReader leaf,
* and that all LeafReader leaves are SegmentReader's that have a compound
* file status that matches the expected input.
*/
private static void assertCompoundSegments(IndexReader reader, boolean compound) {
assertNotNull("Null leaves", reader.leaves());
assertTrue("no leaves", 0 < reader.leaves().size());
for (LeafReaderContext atomic : reader.leaves()) {
assertTrue("not a segment reader: " + atomic.reader().toString(), atomic.reader() instanceof SegmentReader);
assertEquals("Compound status incorrect for: " + atomic.reader().toString(), compound, ((SegmentReader) atomic.reader()).getSegmentInfo().info.getUseCompoundFile());
}
}
use of org.apache.lucene.index.SegmentReader in project lucene-solr by apache.
the class TestUtil method checkReader.
public static void checkReader(LeafReader reader, boolean crossCheckTermVectors) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
PrintStream infoStream = new PrintStream(bos, false, IOUtils.UTF_8);
final CodecReader codecReader;
if (reader instanceof CodecReader) {
codecReader = (CodecReader) reader;
reader.checkIntegrity();
} else {
codecReader = SlowCodecReaderWrapper.wrap(reader);
}
CheckIndex.testLiveDocs(codecReader, infoStream, true);
CheckIndex.testFieldInfos(codecReader, infoStream, true);
CheckIndex.testFieldNorms(codecReader, infoStream, true);
CheckIndex.testPostings(codecReader, infoStream, false, true, Version.LUCENE_7_0_0);
CheckIndex.testStoredFields(codecReader, infoStream, true);
CheckIndex.testTermVectors(codecReader, infoStream, false, crossCheckTermVectors, true, Version.LUCENE_7_0_0);
CheckIndex.testDocValues(codecReader, infoStream, true);
CheckIndex.testPoints(codecReader, infoStream, true);
// some checks really against the reader API
checkReaderSanity(reader);
if (LuceneTestCase.INFOSTREAM) {
System.out.println(bos.toString(IOUtils.UTF_8));
}
LeafReader unwrapped = FilterLeafReader.unwrap(reader);
if (unwrapped instanceof SegmentReader) {
SegmentReader sr = (SegmentReader) unwrapped;
long bytesUsed = sr.ramBytesUsed();
if (sr.ramBytesUsed() < 0) {
throw new IllegalStateException("invalid ramBytesUsed for reader: " + bytesUsed);
}
assert Accountables.toString(sr) != null;
}
}
Aggregations