Apache Solr open-source search software
LUCENE-4849: make ParallelTaxonomyArrays abstract
Shai Ererab9c8815f3d1a
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 206052b58e1..071e3611611 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -45,6 +45,10 @@ Changes in backwards compatibility policyTieredMergePolicy. IndexWriterConfig setters now throw an exception whenpassed null if null is not a valid value.+* LUCENE-4849: Made ParallelTaxonomyArrays abstract with a concrete+ implementation for DirectoryTaxonomyWriter/Reader. Also moved it under+ o.a.l.facet.taxonomy. (Shai Erera)+New Features* LUCENE-4815: DrillSideways now allows more than one FacetRequest perdiff --git a/lucene/facet/src/java/org/apache/lucene/facet/search/DepthOneFacetResultsHandler.java b/lucene/facet/src/java/org/apache/lucene/facet/search/DepthOneFacetResultsHandler.javaindex 0839bc3f72b..1369f681a99 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/search/DepthOneFacetResultsHandler.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/search/DepthOneFacetResultsHandler.java@@ -7,8 +7,8 @@ import java.util.Collections;import java.util.Comparator;import org.apache.lucene.facet.search.FacetRequest.SortOrder;+import org.apache.lucene.facet.taxonomy.ParallelTaxonomyArrays;import org.apache.lucene.facet.taxonomy.TaxonomyReader;-import org.apache.lucene.facet.taxonomy.directory.ParallelTaxonomyArrays;import org.apache.lucene.util.PriorityQueue;/*diff --git a/lucene/facet/src/java/org/apache/lucene/facet/search/DrillSideways.java b/lucene/facet/src/java/org/apache/lucene/facet/search/DrillSideways.javaindex a66d8121433..1fb388b95a4 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/search/DrillSideways.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/search/DrillSideways.java@@ -150,7 +150,7 @@ public class DrillSideways {searcher.search(dsq, hitCollector);int numDims = drillDownDims.size();- List<FacetResult>[] drillSidewaysResults = (List<FacetResult>[]) new List[numDims];+ List<FacetResult>[] drillSidewaysResults = new List[numDims];List<FacetResult> drillDownResults = null;List<FacetResult> mergedResults = new ArrayList<FacetResult>();diff --git a/lucene/facet/src/java/org/apache/lucene/facet/search/FacetsAccumulator.java b/lucene/facet/src/java/org/apache/lucene/facet/search/FacetsAccumulator.javaindex 8d61cf81f18..f0a25ae288e 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/search/FacetsAccumulator.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/search/FacetsAccumulator.java@@ -15,8 +15,8 @@ import org.apache.lucene.facet.search.FacetRequest.FacetArraysSource;import org.apache.lucene.facet.search.FacetRequest.ResultMode;import org.apache.lucene.facet.search.FacetRequest.SortOrder;import org.apache.lucene.facet.search.FacetsCollector.MatchingDocs;+import org.apache.lucene.facet.taxonomy.ParallelTaxonomyArrays;import org.apache.lucene.facet.taxonomy.TaxonomyReader;-import org.apache.lucene.facet.taxonomy.directory.ParallelTaxonomyArrays;import org.apache.lucene.index.IndexReader;/*diff --git a/lucene/facet/src/java/org/apache/lucene/facet/search/TopKFacetResultsHandler.java b/lucene/facet/src/java/org/apache/lucene/facet/search/TopKFacetResultsHandler.javaindex a74fc79f75c..9c173242999 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/search/TopKFacetResultsHandler.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/search/TopKFacetResultsHandler.java@@ -5,8 +5,8 @@ import java.util.ArrayList;import org.apache.lucene.facet.partitions.IntermediateFacetResult;import org.apache.lucene.facet.partitions.PartitionsFacetResultsHandler;+import org.apache.lucene.facet.taxonomy.ParallelTaxonomyArrays;import org.apache.lucene.facet.taxonomy.TaxonomyReader;-import org.apache.lucene.facet.taxonomy.directory.ParallelTaxonomyArrays;import org.apache.lucene.facet.util.ResultSortUtils;/*diff --git a/lucene/facet/src/java/org/apache/lucene/facet/search/TopKInEachNodeHandler.java b/lucene/facet/src/java/org/apache/lucene/facet/search/TopKInEachNodeHandler.javaindex 05bebcb1ac0..9a226320ec2 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/search/TopKInEachNodeHandler.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/search/TopKInEachNodeHandler.java@@ -9,8 +9,8 @@ import org.apache.lucene.facet.collections.IntToObjectMap;import org.apache.lucene.facet.partitions.IntermediateFacetResult;import org.apache.lucene.facet.partitions.PartitionsFacetResultsHandler;import org.apache.lucene.facet.search.FacetRequest.SortOrder;+import org.apache.lucene.facet.taxonomy.ParallelTaxonomyArrays;import org.apache.lucene.facet.taxonomy.TaxonomyReader;-import org.apache.lucene.facet.taxonomy.directory.ParallelTaxonomyArrays;import org.apache.lucene.util.PriorityQueue;/*diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/ParallelTaxonomyArrays.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/ParallelTaxonomyArrays.javanew file mode 100644index 00000000000..e27ffe599b5--- /dev/null+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/ParallelTaxonomyArrays.java@@ -0,0 +1,63 @@+package org.apache.lucene.facet.taxonomy;+++/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++/**+ * Returns 3 arrays for traversing the taxonomy:+ * <ul>+ * <li>{@code parents}: {@code parents[i]} denotes the parent of category+ * ordinal {@code i}.</li>+ * <li>{@code children}: {@code children[i]} denotes a child of category ordinal+ * {@code i}.</li>+ * <li>{@code siblings}: {@code siblings[i]} denotes the sibling of category+ * ordinal {@code i}.</li>+ * </ul>+ *+ * To traverse the taxonomy tree, you typically start with {@code children[0]}+ * (ordinal 0 is reserved for ROOT), and then depends if you want to do DFS or+ * BFS, you call {@code children[children[0]]} or {@code siblings[children[0]]}+ * and so forth, respectively.+ *+ * <p>+ * <b>NOTE:</b> you are not expected to modify the values of the arrays, since+ * the arrays are shared with other threads.+ *+ * @lucene.experimental+ */+public abstract class ParallelTaxonomyArrays {++ /**+ * Returns the parents array, where {@code parents[i]} denotes the parent of+ * category ordinal {@code i}.+ */+ public abstract int[] parents();++ /**+ * Returns the children array, where {@code children[i]} denotes a child of+ * category ordinal {@code i}.+ */+ public abstract int[] children();++ /**+ * Returns the siblings array, where {@code siblings[i]} denotes the sibling+ * of category ordinal {@code i}.+ */+ public abstract int[] siblings();++}diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyReader.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyReader.javaindex 079fa4f606c..ed6a8d61ab9 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyReader.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyReader.java@@ -5,7 +5,6 @@ import java.io.IOException;import java.util.Map;import java.util.concurrent.atomic.AtomicInteger;-import org.apache.lucene.facet.taxonomy.directory.ParallelTaxonomyArrays;import org.apache.lucene.store.AlreadyClosedException;/*diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyReader.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyReader.javaindex 6e3a6cf56a4..0e242348c4c 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyReader.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyReader.java@@ -7,6 +7,7 @@ import java.util.logging.Logger;import org.apache.lucene.facet.collections.LRUHashMap;import org.apache.lucene.facet.taxonomy.CategoryPath;+import org.apache.lucene.facet.taxonomy.ParallelTaxonomyArrays;import org.apache.lucene.facet.taxonomy.TaxonomyReader;import org.apache.lucene.index.CorruptIndexException;import org.apache.lucene.index.DirectoryReader;@@ -62,7 +63,7 @@ public class DirectoryTaxonomyReader extends TaxonomyReader {private LRUHashMap<CategoryPath, Integer> ordinalCache;private LRUHashMap<Integer, CategoryPath> categoryCache;- private volatile ParallelTaxonomyArrays taxoArrays;+ private volatile TaxonomyIndexArrays taxoArrays;private char delimiter = Consts.DEFAULT_DELIMITER;@@ -73,7 +74,7 @@ public class DirectoryTaxonomyReader extends TaxonomyReader {*/DirectoryTaxonomyReader(DirectoryReader indexReader, DirectoryTaxonomyWriter taxoWriter,LRUHashMap<CategoryPath,Integer> ordinalCache, LRUHashMap<Integer,CategoryPath> categoryCache,- ParallelTaxonomyArrays taxoArrays) throws IOException {+ TaxonomyIndexArrays taxoArrays) throws IOException {this.indexReader = indexReader;this.taxoWriter = taxoWriter;this.taxoEpoch = taxoWriter == null ? -1 : taxoWriter.getTaxonomyEpoch();@@ -82,7 +83,7 @@ public class DirectoryTaxonomyReader extends TaxonomyReader {this.ordinalCache = ordinalCache == null ? new LRUHashMap<CategoryPath,Integer>(DEFAULT_CACHE_VALUE) : ordinalCache;this.categoryCache = categoryCache == null ? new LRUHashMap<Integer,CategoryPath>(DEFAULT_CACHE_VALUE) : categoryCache;- this.taxoArrays = taxoArrays != null ? new ParallelTaxonomyArrays(indexReader, taxoArrays) : null;+ this.taxoArrays = taxoArrays != null ? new TaxonomyIndexArrays(indexReader, taxoArrays) : null;}/**@@ -130,7 +131,7 @@ public class DirectoryTaxonomyReader extends TaxonomyReader {// according to Java Concurrency in Practice, this might perform better on// some JVMs, because the array initialization doesn't happen on the// volatile member.- ParallelTaxonomyArrays tmpArrays = new ParallelTaxonomyArrays(indexReader);+ TaxonomyIndexArrays tmpArrays = new TaxonomyIndexArrays(indexReader);taxoArrays = tmpArrays;}}diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.javaindex 62766d1a166..4ed79d8e845 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java@@ -129,7 +129,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {*/private volatile boolean cacheIsComplete;private volatile boolean isClosed = false;- private volatile ParallelTaxonomyArrays taxoArrays;+ private volatile TaxonomyIndexArrays taxoArrays;private volatile int nextID;/** Reads the commit data from a Directory. */@@ -744,7 +744,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {}}- private ParallelTaxonomyArrays getTaxoArrays() throws IOException {+ private TaxonomyIndexArrays getTaxoArrays() throws IOException {if (taxoArrays == null) {synchronized (this) {if (taxoArrays == null) {@@ -754,7 +754,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {// according to Java Concurrency, this might perform better on some// JVMs, since the object initialization doesn't happen on the// volatile member.- ParallelTaxonomyArrays tmpArrays = new ParallelTaxonomyArrays(reader);+ TaxonomyIndexArrays tmpArrays = new TaxonomyIndexArrays(reader);taxoArrays = tmpArrays;} finally {readerManager.release(reader);diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/ParallelTaxonomyArrays.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/TaxonomyIndexArrays.javasimilarity index 83%rename from lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/ParallelTaxonomyArrays.javarename to lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/TaxonomyIndexArrays.javaindex cfbf29788ae..62e7858a4fb 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/ParallelTaxonomyArrays.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/TaxonomyIndexArrays.java@@ -2,6 +2,7 @@ package org.apache.lucene.facet.taxonomy.directory;import java.io.IOException;+import org.apache.lucene.facet.taxonomy.ParallelTaxonomyArrays;import org.apache.lucene.facet.taxonomy.TaxonomyReader;import org.apache.lucene.index.CorruptIndexException;import org.apache.lucene.index.DocsAndPositionsEnum;@@ -28,30 +29,12 @@ import org.apache.lucene.util.ArrayUtil;*//**- * Returns 3 arrays for traversing the taxonomy:- * <ul>- * <li>{@code parents}: {@code parents[i]} denotes the parent of category- * ordinal {@code i}.</li>- * <li>{@code children}: {@code children[i]} denotes the youngest child of- * category ordinal {@code i}. The youngest child is defined as the category- * that was added last to the taxonomy as an immediate child of {@code i}.</li>- * <li>{@code siblings}: {@code siblings[i]} denotes the sibling of category- * ordinal {@code i}. The sibling is defined as the previous youngest child of- * {@code parents[i]}.</li>- * </ul>- *- * To traverse the taxonomy tree, you typically start with {@code children[0]}- * (ordinal 0 is reserved for ROOT), and then depends if you want to do DFS or- * BFS, you call {@code children[children[0]]} or {@code siblings[children[0]]}- * and so forth, respectively.- *- * <p>- * <b>NOTE:</b> you are not expected to modify the values of the arrays, since- * the arrays are shared with other threads.+ * A {@link ParallelTaxonomyArrays} that are initialized from the taxonomy+ * index.** @lucene.experimental*/-public class ParallelTaxonomyArrays {+class TaxonomyIndexArrays extends ParallelTaxonomyArrays {private final int[] parents;@@ -63,11 +46,11 @@ public class ParallelTaxonomyArrays {private int[] children, siblings;/** Used by {@link #add(int, int)} after the array grew. */- private ParallelTaxonomyArrays(int[] parents) {+ private TaxonomyIndexArrays(int[] parents) {this.parents = parents;}- public ParallelTaxonomyArrays(IndexReader reader) throws IOException {+ public TaxonomyIndexArrays(IndexReader reader) throws IOException {parents = new int[reader.maxDoc()];if (parents.length > 0) {initParents(reader, 0);@@ -82,7 +65,7 @@ public class ParallelTaxonomyArrays {}}- public ParallelTaxonomyArrays(IndexReader reader, ParallelTaxonomyArrays copyFrom) throws IOException {+ public TaxonomyIndexArrays(IndexReader reader, TaxonomyIndexArrays copyFrom) throws IOException {assert copyFrom != null;// note that copyParents.length may be equal to reader.maxDoc(). this is not a bug@@ -99,7 +82,7 @@ public class ParallelTaxonomyArrays {}}- private final synchronized void initChildrenSiblings(ParallelTaxonomyArrays copyFrom) {+ private final synchronized void initChildrenSiblings(TaxonomyIndexArrays copyFrom) {if (!initializedChildren) { // must do this check !children = new int[parents.length];siblings = new int[parents.length];@@ -180,11 +163,11 @@ public class ParallelTaxonomyArrays {* <p>* <b>NOTE:</b> you should call this method from a thread-safe code.*/- ParallelTaxonomyArrays add(int ordinal, int parentOrdinal) {+ TaxonomyIndexArrays add(int ordinal, int parentOrdinal) {if (ordinal >= parents.length) {int[] newarray = ArrayUtil.grow(parents, ordinal + 1);newarray[ordinal] = parentOrdinal;- return new ParallelTaxonomyArrays(newarray);+ return new TaxonomyIndexArrays(newarray);}parents[ordinal] = parentOrdinal;return this;@@ -194,6 +177,7 @@ public class ParallelTaxonomyArrays {* Returns the parents array, where {@code parents[i]} denotes the parent of* category ordinal {@code i}.*/+ @Overridepublic int[] parents() {return parents;}@@ -204,6 +188,7 @@ public class ParallelTaxonomyArrays {* category that was added last to the taxonomy as an immediate child of* {@code i}.*/+ @Overridepublic int[] children() {if (!initializedChildren) {initChildrenSiblings(null);@@ -218,6 +203,7 @@ public class ParallelTaxonomyArrays {* of category ordinal {@code i}. The sibling is defined as the previous* youngest child of {@code parents[i]}.*/+ @Overridepublic int[] siblings() {if (!initializedChildren) {initChildrenSiblings(null);diff --git a/lucene/facet/src/java/org/apache/lucene/facet/util/PrintTaxonomyStats.java b/lucene/facet/src/java/org/apache/lucene/facet/util/PrintTaxonomyStats.javaindex fd5daf23c80..fd2252ae79f 100644--- a/lucene/facet/src/java/org/apache/lucene/facet/util/PrintTaxonomyStats.java+++ b/lucene/facet/src/java/org/apache/lucene/facet/util/PrintTaxonomyStats.java@@ -22,9 +22,9 @@ import java.io.IOException;import java.io.PrintStream;import org.apache.lucene.facet.taxonomy.CategoryPath;+import org.apache.lucene.facet.taxonomy.ParallelTaxonomyArrays;import org.apache.lucene.facet.taxonomy.TaxonomyReader;import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;-import org.apache.lucene.facet.taxonomy.directory.ParallelTaxonomyArrays;import org.apache.lucene.store.Directory;import org.apache.lucene.store.FSDirectory;diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.javaindex 563b88b99bc..c5b3f7a1b4c 100644--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyCombined.java@@ -11,7 +11,6 @@ import org.apache.lucene.facet.FacetTestCase;import org.apache.lucene.facet.SlowRAMDirectory;import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;-import org.apache.lucene.facet.taxonomy.directory.ParallelTaxonomyArrays;import org.apache.lucene.store.Directory;import org.apache.lucene.store.LockObtainFailedException;import org.apache.lucene.store.RAMDirectory;