Skip to content

Apache Lucene open-source search software

SOLR-2564: add pollLast to deal with performance regression due to Java5/Java6 difference between modules and Solr

Yonik Seeleya7a7108ec8ad
diff --git a/modules/grouping/src/java/org/apache/lucene/search/grouping/AbstractFirstPassGroupingCollector.java b/modules/grouping/src/java/org/apache/lucene/search/grouping/AbstractFirstPassGroupingCollector.java
index 9e2ef6eb1ef..686b616b64e 100644
--- a/modules/grouping/src/java/org/apache/lucene/search/grouping/AbstractFirstPassGroupingCollector.java
+++ b/modules/grouping/src/java/org/apache/lucene/search/grouping/AbstractFirstPassGroupingCollector.java
@@ -43,7 +43,8 @@ abstract public class AbstractFirstPassGroupingCollector<GROUP_VALUE_TYPE> exten
private final int compIDXEnd;
// Set once we reach topNGroups unique groups:
- private TreeSet<CollectedSearchGroup<GROUP_VALUE_TYPE>> orderedGroups;
+ /** @lucene.internal */
+ protected TreeSet<CollectedSearchGroup<GROUP_VALUE_TYPE>> orderedGroups;
private int docBase;
private int spareSlot;
@@ -214,8 +215,7 @@ abstract public class AbstractFirstPassGroupingCollector<GROUP_VALUE_TYPE> exten
// the bottom group with this new group.
// java 6-only: final CollectedSearchGroup bottomGroup = orderedGroups.pollLast();
- final CollectedSearchGroup<GROUP_VALUE_TYPE> bottomGroup = orderedGroups.last();
- orderedGroups.remove(bottomGroup);
+ final CollectedSearchGroup<GROUP_VALUE_TYPE> bottomGroup = pollLast();
assert orderedGroups.size() == topNGroups -1;
groupMap.remove(bottomGroup.groupValue);
@@ -350,9 +350,14 @@ abstract public class AbstractFirstPassGroupingCollector<GROUP_VALUE_TYPE> exten
* @return a copy of the specified group value
*/
protected abstract GROUP_VALUE_TYPE copyDocGroupValue(GROUP_VALUE_TYPE groupValue, GROUP_VALUE_TYPE reuse);
-}
-class CollectedSearchGroup<T> extends SearchGroup<T> {
- int topDoc;
- int comparatorSlot;
+
+
+ protected CollectedSearchGroup<GROUP_VALUE_TYPE> pollLast() {
+ // java 6-only: final CollectedSearchGroup bottomGroup = orderedGroups.pollLast();
+ final CollectedSearchGroup<GROUP_VALUE_TYPE> bottomGroup = orderedGroups.last();
+ orderedGroups.remove(bottomGroup);
+ return bottomGroup;
+ }
}
+
diff --git a/modules/grouping/src/java/org/apache/lucene/search/grouping/CollectedSearchGroup.java b/modules/grouping/src/java/org/apache/lucene/search/grouping/CollectedSearchGroup.java
new file mode 100644
index 00000000000..f4cca99e9b6
--- /dev/null
+++ b/modules/grouping/src/java/org/apache/lucene/search/grouping/CollectedSearchGroup.java
@@ -0,0 +1,24 @@
+/**
+ * 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.
+ */
+
+package org.apache.lucene.search.grouping;
+
+/** @lucene.internal */
+public class CollectedSearchGroup<T> extends SearchGroup<T> {
+ int topDoc;
+ int comparatorSlot;
+}
diff --git a/solr/src/java/org/apache/solr/search/Grouping.java b/solr/src/java/org/apache/solr/search/Grouping.java
index 8649b57176b..ce33795b6fe 100755
--- a/solr/src/java/org/apache/solr/search/Grouping.java
+++ b/solr/src/java/org/apache/solr/search/Grouping.java
@@ -628,7 +628,7 @@ public class Grouping {
}
sort = sort == null ? Sort.RELEVANCE : sort;
- firstPass = new TermFirstPassGroupingCollector(groupBy, sort, actualGroupsToFind);
+ firstPass = new TermFirstPassGroupingCollectorJava6(groupBy, sort, actualGroupsToFind);
return firstPass;
}
@@ -996,6 +996,22 @@ public class Grouping {
filler = docValues.getValueFiller();
mval = filler.getValue();
}
+
+ @Override
+ protected CollectedSearchGroup<MutableValue> pollLast() {
+ return orderedGroups.pollLast();
+ }
+ }
+
+ static class TermFirstPassGroupingCollectorJava6 extends TermFirstPassGroupingCollector {
+ public TermFirstPassGroupingCollectorJava6(String groupField, Sort groupSort, int topNGroups) throws IOException {
+ super(groupField, groupSort, topNGroups);
+ }
+
+ @Override
+ protected CollectedSearchGroup<BytesRef> pollLast() {
+ return orderedGroups.pollLast();
+ }
}
static class FunctionSecondPassGroupingCollector extends AbstractSecondPassGroupingCollector<MutableValue> {