Search in sources :

Example 6 with SegmentReader

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;
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) SegmentReader(org.apache.lucene.index.SegmentReader)

Example 7 with SegmentReader

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());
    }
}
Also used : LeafReaderContext(org.apache.lucene.index.LeafReaderContext) SegmentReader(org.apache.lucene.index.SegmentReader)

Example 8 with SegmentReader

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;
    }
}
Also used : PrintStream(java.io.PrintStream) CodecReader(org.apache.lucene.index.CodecReader) LeafReader(org.apache.lucene.index.LeafReader) FilterLeafReader(org.apache.lucene.index.FilterLeafReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SegmentReader(org.apache.lucene.index.SegmentReader)

Aggregations

SegmentReader (org.apache.lucene.index.SegmentReader)8 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)5 IndexSearcher (org.apache.lucene.search.IndexSearcher)4 IOException (java.io.IOException)3 FilterLeafReader (org.apache.lucene.index.FilterLeafReader)3 LeafReader (org.apache.lucene.index.LeafReader)3 HashMap (java.util.HashMap)2 SegmentCommitInfo (org.apache.lucene.index.SegmentCommitInfo)2 SearcherManager (org.apache.lucene.search.SearcherManager)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)1 Supplier (org.apache.logging.log4j.util.Supplier)1 Document (org.apache.lucene.document.Document)1 CodecReader (org.apache.lucene.index.CodecReader)1 DirectoryReader (org.apache.lucene.index.DirectoryReader)1 IndexWriter (org.apache.lucene.index.IndexWriter)1 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)1 SegmentInfos (org.apache.lucene.index.SegmentInfos)1