You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2017/04/26 00:35:04 UTC
lucene-solr:branch_6x: LUCENE-7801: SortedSetDocValuesReaderState now
implements Accountable
Repository: lucene-solr
Updated Branches:
refs/heads/branch_6x 79d44ae64 -> 92da9535b
LUCENE-7801: SortedSetDocValuesReaderState now implements Accountable
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/92da9535
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/92da9535
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/92da9535
Branch: refs/heads/branch_6x
Commit: 92da9535b5909f07900188cb930564494878a8c7
Parents: 79d44ae
Author: Mike McCandless <mi...@apache.org>
Authored: Tue Apr 25 20:34:00 2017 -0400
Committer: Mike McCandless <mi...@apache.org>
Committed: Tue Apr 25 20:34:29 2017 -0400
----------------------------------------------------------------------
lucene/CHANGES.txt | 4 +++
.../org/apache/lucene/facet/FacetsConfig.java | 2 +-
.../DefaultSortedSetDocValuesReaderState.java | 38 ++++++++++++++++++++
.../SortedSetDocValuesReaderState.java | 3 +-
.../sortedset/TestSortedSetDocValuesFacets.java | 13 +++++++
5 files changed, 58 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/92da9535/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index e143787..d4aee39 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -22,6 +22,10 @@ Improvements
* LUCENE-7785: Move dictionary for Ukrainian analyzer to external dependency.
(Andriy Rysin via Steve Rowe, Dawid Weiss)
+* LUCENE-7801: SortedSetDocValuesReaderState now implements
+ Accountable so you can see how much RAM it's using (Robert Muir,
+ Mike McCandless)
+
Optimizations
* LUCENE-7787: spatial-extras HeatmapFacetCounter will now short-circuit it's
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/92da9535/lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java
----------------------------------------------------------------------
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java b/lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java
index 96db60f..ea67294 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/FacetsConfig.java
@@ -105,7 +105,7 @@ public class FacetsConfig {
*
* @return The default configuration to be used for dimensions that
* are not yet set in the {@link FacetsConfig} */
- protected DimConfig getDefaultDimConfig(){
+ protected DimConfig getDefaultDimConfig() {
return DEFAULT_DIM_CONFIG;
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/92da9535/lucene/facet/src/java/org/apache/lucene/facet/sortedset/DefaultSortedSetDocValuesReaderState.java
----------------------------------------------------------------------
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/sortedset/DefaultSortedSetDocValuesReaderState.java b/lucene/facet/src/java/org/apache/lucene/facet/sortedset/DefaultSortedSetDocValuesReaderState.java
index 936c962..0e683fd 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/sortedset/DefaultSortedSetDocValuesReaderState.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/sortedset/DefaultSortedSetDocValuesReaderState.java
@@ -18,6 +18,7 @@ package org.apache.lucene.facet.sortedset;
import java.io.IOException;
import java.util.Arrays;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@@ -33,6 +34,8 @@ import org.apache.lucene.index.MultiDocValues.MultiSortedSetDocValues;
import org.apache.lucene.index.MultiDocValues.OrdinalMap;
import org.apache.lucene.index.MultiDocValues;
import org.apache.lucene.index.SortedSetDocValues;
+import org.apache.lucene.util.Accountable;
+import org.apache.lucene.util.Accountables;
import org.apache.lucene.util.BytesRef;
/**
@@ -103,11 +106,46 @@ public class DefaultSortedSetDocValuesReaderState extends SortedSetDocValuesRead
}
}
+ /**
+ * Return the memory usage of this object in bytes. Negative values are illegal.
+ */
+ @Override
+ public long ramBytesUsed() {
+ synchronized (cachedOrdMaps) {
+ long bytes = 0;
+ for (OrdinalMap map : cachedOrdMaps.values()) {
+ bytes += map.ramBytesUsed();
+ }
+
+ return bytes;
+ }
+ }
+
+ /**
+ * Returns nested resources of this class.
+ * The result should be a point-in-time snapshot (to avoid race conditions).
+ * @see Accountables
+ */
+ @Override
+ public Collection<Accountable> getChildResources() {
+ synchronized (cachedOrdMaps) {
+ return Accountables.namedAccountables("DefaultSortedSetDocValuesReaderState", cachedOrdMaps);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "DefaultSortedSetDocValuesReaderState(field=" + field + " origReader=" + origReader + ")";
+ }
+
/** Return top-level doc values. */
@Override
public SortedSetDocValues getDocValues() throws IOException {
// TODO: this is dup'd from slow composite reader wrapper ... can we factor it out to share?
OrdinalMap map = null;
+ // TODO: why are we lazy about this? It's better if ctor pays the cost, not first query? Oh, but we
+ // call this method from ctor, ok. Also, we only ever store one entry in the map (for key=field) so
+ // why are we using a map?
synchronized (cachedOrdMaps) {
map = cachedOrdMaps.get(field);
if (map == null) {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/92da9535/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesReaderState.java
----------------------------------------------------------------------
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesReaderState.java b/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesReaderState.java
index 83ed3f0..546b319 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesReaderState.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesReaderState.java
@@ -21,6 +21,7 @@ import java.util.Map;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.SortedSetDocValues;
+import org.apache.lucene.util.Accountable;
/** Wraps a {@link IndexReader} and resolves ords
* using existing {@link SortedSetDocValues} APIs without a
@@ -38,7 +39,7 @@ import org.apache.lucene.index.SortedSetDocValues;
* so you should create it once and re-use that one instance
* for a given {@link IndexReader}. */
-public abstract class SortedSetDocValuesReaderState {
+public abstract class SortedSetDocValuesReaderState implements Accountable {
/** Holds start/end range of ords, which maps to one
* dimension (someday we may generalize it to map to
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/92da9535/lucene/facet/src/test/org/apache/lucene/facet/sortedset/TestSortedSetDocValuesFacets.java
----------------------------------------------------------------------
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/sortedset/TestSortedSetDocValuesFacets.java b/lucene/facet/src/test/org/apache/lucene/facet/sortedset/TestSortedSetDocValuesFacets.java
index 60beddd..c4ede04 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/sortedset/TestSortedSetDocValuesFacets.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/sortedset/TestSortedSetDocValuesFacets.java
@@ -17,6 +17,7 @@
package org.apache.lucene.facet.sortedset;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -38,6 +39,7 @@ import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.Accountable;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.TestUtil;
@@ -183,6 +185,17 @@ public class TestSortedSetDocValuesFacets extends FacetTestCase {
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());
+ }
+
searcher.getIndexReader().close();
dir.close();
}