Search in sources :

Example 6 with Accountable

use of org.apache.lucene.util.Accountable in project elasticsearch by elastic.

the class IndicesFieldDataCache method onRemoval.

@Override
public void onRemoval(RemovalNotification<Key, Accountable> notification) {
    Key key = notification.getKey();
    assert key != null && key.listeners != null;
    IndexFieldCache indexCache = key.indexCache;
    final Accountable value = notification.getValue();
    for (IndexFieldDataCache.Listener listener : key.listeners) {
        try {
            listener.onRemoval(key.shardId, indexCache.fieldName, notification.getRemovalReason() == RemovalNotification.RemovalReason.EVICTED, value.ramBytesUsed());
        } catch (Exception e) {
            // load anyway since listeners should not throw exceptions
            logger.error("Failed to call listener on field data cache unloading", e);
        }
    }
}
Also used : IndexFieldDataCache(org.elasticsearch.index.fielddata.IndexFieldDataCache) Accountable(org.apache.lucene.util.Accountable)

Example 7 with Accountable

use of org.apache.lucene.util.Accountable in project lucene-solr by apache.

the class TestLRUCache method testMaxRamSize.

public void testMaxRamSize() throws Exception {
    LRUCache<String, Accountable> accountableLRUCache = new LRUCache<>();
    accountableLRUCache.initializeMetrics(metricManager, registry, scope);
    Map<String, String> params = new HashMap<>();
    params.put("size", "5");
    params.put("maxRamMB", "1");
    CacheRegenerator cr = new NoOpRegenerator();
    Object o = accountableLRUCache.init(params, null, cr);
    long baseSize = accountableLRUCache.ramBytesUsed();
    assertEquals(LRUCache.BASE_RAM_BYTES_USED, baseSize);
    accountableLRUCache.put("1", new Accountable() {

        @Override
        public long ramBytesUsed() {
            return 512 * 1024;
        }
    });
    assertEquals(1, accountableLRUCache.size());
    assertEquals(baseSize + 512 * 1024 + LRUCache.DEFAULT_RAM_BYTES_USED + LRUCache.LINKED_HASHTABLE_RAM_BYTES_PER_ENTRY, accountableLRUCache.ramBytesUsed());
    accountableLRUCache.put("2", new Accountable() {

        @Override
        public long ramBytesUsed() {
            return 512 * 1024;
        }
    });
    assertEquals(1, accountableLRUCache.size());
    assertEquals(baseSize + 512 * 1024 + LRUCache.LINKED_HASHTABLE_RAM_BYTES_PER_ENTRY + LRUCache.DEFAULT_RAM_BYTES_USED, accountableLRUCache.ramBytesUsed());
    Map<String, Object> nl = accountableLRUCache.getMetricsMap().getValue();
    assertEquals(1L, nl.get("evictions"));
    assertEquals(1L, nl.get("evictionsRamUsage"));
    accountableLRUCache.put("3", new Accountable() {

        @Override
        public long ramBytesUsed() {
            return 1024;
        }
    });
    nl = accountableLRUCache.getMetricsMap().getValue();
    assertEquals(1L, nl.get("evictions"));
    assertEquals(1L, nl.get("evictionsRamUsage"));
    assertEquals(2L, accountableLRUCache.size());
    assertEquals(baseSize + 513 * 1024 + LRUCache.LINKED_HASHTABLE_RAM_BYTES_PER_ENTRY * 2 + LRUCache.DEFAULT_RAM_BYTES_USED * 2, accountableLRUCache.ramBytesUsed());
    accountableLRUCache.clear();
    assertEquals(RamUsageEstimator.shallowSizeOfInstance(LRUCache.class), accountableLRUCache.ramBytesUsed());
}
Also used : HashMap(java.util.HashMap) Accountable(org.apache.lucene.util.Accountable)

Example 8 with Accountable

use of org.apache.lucene.util.Accountable in project lucene-solr by apache.

the class TestSortedSetDocValuesFacets method testSparseFacets.

// LUCENE-5333
public void testSparseFacets() throws Exception {
    Directory dir = newDirectory();
    RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
    FacetsConfig config = new FacetsConfig();
    Document doc = new Document();
    doc.add(new SortedSetDocValuesFacetField("a", "foo1"));
    writer.addDocument(config.build(doc));
    if (random().nextBoolean()) {
        writer.commit();
    }
    doc = new Document();
    doc.add(new SortedSetDocValuesFacetField("a", "foo2"));
    doc.add(new SortedSetDocValuesFacetField("b", "bar1"));
    writer.addDocument(config.build(doc));
    if (random().nextBoolean()) {
        writer.commit();
    }
    doc = new Document();
    doc.add(new SortedSetDocValuesFacetField("a", "foo3"));
    doc.add(new SortedSetDocValuesFacetField("b", "bar2"));
    doc.add(new SortedSetDocValuesFacetField("c", "baz1"));
    writer.addDocument(config.build(doc));
    // NRT open
    IndexSearcher searcher = newSearcher(writer.getReader());
    writer.close();
    // Per-top-reader state:
    SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(searcher.getIndexReader());
    ExecutorService exec = randomExecutorServiceOrNull();
    Facets facets = getAllFacets(searcher, state, exec);
    // Ask for top 10 labels for any dims that have counts:
    List<FacetResult> results = facets.getAllDims(10);
    assertEquals(3, results.size());
    assertEquals("dim=a path=[] value=3 childCount=3\n  foo1 (1)\n  foo2 (1)\n  foo3 (1)\n", results.get(0).toString());
    assertEquals("dim=b path=[] value=2 childCount=2\n  bar1 (1)\n  bar2 (1)\n", results.get(1).toString());
    assertEquals("dim=c path=[] value=1 childCount=1\n  baz1 (1)\n", results.get(2).toString());
    Collection<Accountable> resources = state.getChildResources();
    assertTrue(state.toString().contains(FacetsConfig.DEFAULT_INDEX_FIELD_NAME));
    if (searcher.getIndexReader().leaves().size() > 1) {
        assertTrue(state.ramBytesUsed() > 0);
        assertFalse(resources.isEmpty());
        assertTrue(resources.toString().contains(FacetsConfig.DEFAULT_INDEX_FIELD_NAME));
    } else {
        assertEquals(0, state.ramBytesUsed());
        assertTrue(resources.isEmpty());
    }
    if (exec != null) {
        exec.shutdownNow();
    }
    searcher.getIndexReader().close();
    dir.close();
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) FacetsConfig(org.apache.lucene.facet.FacetsConfig) Facets(org.apache.lucene.facet.Facets) Accountable(org.apache.lucene.util.Accountable) Document(org.apache.lucene.document.Document) ExecutorService(java.util.concurrent.ExecutorService) FacetResult(org.apache.lucene.facet.FacetResult) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) Directory(org.apache.lucene.store.Directory)

Example 9 with Accountable

use of org.apache.lucene.util.Accountable in project lucene-solr by apache.

the class AnalyzingInfixSuggester method getChildResources.

@Override
public Collection<Accountable> getChildResources() {
    List<Accountable> resources = new ArrayList<>();
    try {
        if (searcherMgr != null) {
            SearcherManager mgr;
            IndexSearcher searcher;
            synchronized (searcherMgrLock) {
                // acquire & release on same SearcherManager, via local reference
                mgr = searcherMgr;
                searcher = mgr.acquire();
            }
            try {
                for (LeafReaderContext context : searcher.getIndexReader().leaves()) {
                    LeafReader reader = FilterLeafReader.unwrap(context.reader());
                    if (reader instanceof SegmentReader) {
                        resources.add(Accountables.namedAccountable("segment", (SegmentReader) reader));
                    }
                }
            } finally {
                mgr.release(searcher);
            }
        }
        return Collections.unmodifiableList(resources);
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) LeafReader(org.apache.lucene.index.LeafReader) FilterLeafReader(org.apache.lucene.index.FilterLeafReader) ArrayList(java.util.ArrayList) Accountable(org.apache.lucene.util.Accountable) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) SearcherManager(org.apache.lucene.search.SearcherManager) IOException(java.io.IOException) SegmentReader(org.apache.lucene.index.SegmentReader)

Example 10 with Accountable

use of org.apache.lucene.util.Accountable in project elasticsearch by elastic.

the class IndicesSegmentResponse method toXContent.

static void toXContent(XContentBuilder builder, Accountable tree) throws IOException {
    builder.startObject();
    builder.field(Fields.DESCRIPTION, tree.toString());
    builder.byteSizeField(Fields.SIZE_IN_BYTES, Fields.SIZE, new ByteSizeValue(tree.ramBytesUsed()));
    Collection<Accountable> children = tree.getChildResources();
    if (children.isEmpty() == false) {
        builder.startArray(Fields.CHILDREN);
        for (Accountable child : children) {
            toXContent(builder, child);
        }
        builder.endArray();
    }
    builder.endObject();
}
Also used : ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) Accountable(org.apache.lucene.util.Accountable)

Aggregations

Accountable (org.apache.lucene.util.Accountable)16 ShardId (org.elasticsearch.index.shard.ShardId)6 Document (org.apache.lucene.document.Document)5 DirectoryReader (org.apache.lucene.index.DirectoryReader)4 IndexWriter (org.apache.lucene.index.IndexWriter)4 RAMDirectory (org.apache.lucene.store.RAMDirectory)4 ElasticsearchDirectoryReader (org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader)4 StringField (org.apache.lucene.document.StringField)3 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)3 IndexSearcher (org.apache.lucene.search.IndexSearcher)3 BitSetProducer (org.apache.lucene.search.join.BitSetProducer)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)2 IndexReader (org.apache.lucene.index.IndexReader)2 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)2 LogByteSizeMergePolicy (org.apache.lucene.index.LogByteSizeMergePolicy)2 Term (org.apache.lucene.index.Term)2 TermQuery (org.apache.lucene.search.TermQuery)2 Directory (org.apache.lucene.store.Directory)2 IndexService (org.elasticsearch.index.IndexService)2