From d34f549df6cee0db7cbff1ec2639262c2f7e21e2 Mon Sep 17 00:00:00 2001 From: Cao Manh Dat Date: Mon, 23 Jan 2017 17:41:35 +0700 Subject: [PATCH] SOLR-9114: NPE using TermVectorComponent, MoreLikeThisComponent in combination with ExactStatsCache --- solr/CHANGES.txt | 2 ++ .../component/MoreLikeThisComponent.java | 12 +++++++++- .../component/TermVectorComponent.java | 9 ++++++++ .../DistributedMLTComponentTest.java | 23 +++++++++++++++++++ .../TermVectorComponentDistributedTest.java | 18 +++++++++++++++ 5 files changed, 63 insertions(+), 1 deletion(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index abd29834afc..a68f4454191 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -121,6 +121,8 @@ Bug Fixes * SOLR-9979: Macro expansion should not be done in shard requests (Tomás Fernández Löbbe) +* SOLR-9114: NPE using TermVectorComponent, MoreLikeThisComponent in combination with ExactStatsCache (Cao Manh Dat, Varun Thacker) + Optimizations ---------------------- diff --git a/solr/core/src/java/org/apache/solr/handler/component/MoreLikeThisComponent.java b/solr/core/src/java/org/apache/solr/handler/component/MoreLikeThisComponent.java index 893cdf38cfc..55edc631114 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/MoreLikeThisComponent.java +++ b/solr/core/src/java/org/apache/solr/handler/component/MoreLikeThisComponent.java @@ -221,7 +221,17 @@ public class MoreLikeThisComponent extends SearchComponent { } super.finishStage(rb); } - + + @Override + public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest sreq) { + SolrParams params = rb.req.getParams(); + if (!params.getBool(COMPONENT_NAME, false)) return; + if ((sreq.purpose & ShardRequest.PURPOSE_GET_MLT_RESULTS) == 0 + && (sreq.purpose & ShardRequest.PURPOSE_GET_TOP_IDS) == 0) { + sreq.params.set(COMPONENT_NAME, "false"); + } + } + /** * Returns NamedList based on the order of * resultIds.shardDoc.positionInResponse diff --git a/solr/core/src/java/org/apache/solr/handler/component/TermVectorComponent.java b/solr/core/src/java/org/apache/solr/handler/component/TermVectorComponent.java index c8872778f21..e81ed85f878 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/TermVectorComponent.java +++ b/solr/core/src/java/org/apache/solr/handler/component/TermVectorComponent.java @@ -464,6 +464,15 @@ public class TermVectorComponent extends SearchComponent implements SolrCoreAwar } } + @Override + public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest sreq) { + SolrParams params = rb.req.getParams(); + if (!params.getBool(COMPONENT_NAME, false)) return; + if ((sreq.purpose & ShardRequest.PURPOSE_GET_FIELDS) == 0) { + sreq.params.set(COMPONENT_NAME, "false"); + } + } + //////////////////////// NamedListInitializedPlugin methods ////////////////////// @Override diff --git a/solr/core/src/test/org/apache/solr/handler/component/DistributedMLTComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/DistributedMLTComponentTest.java index dd1d5c800ba..10116b971c6 100644 --- a/solr/core/src/test/org/apache/solr/handler/component/DistributedMLTComponentTest.java +++ b/solr/core/src/test/org/apache/solr/handler/component/DistributedMLTComponentTest.java @@ -20,11 +20,17 @@ import java.util.HashMap; import java.util.Map; import org.apache.lucene.util.LuceneTestCase.Slow; +import org.apache.lucene.util.TestUtil; import org.apache.solr.BaseDistributedSearchTestCase; import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.common.SolrDocumentList; import org.apache.solr.common.params.MoreLikeThisParams; import org.apache.solr.common.util.NamedList; +import org.apache.solr.search.stats.ExactStatsCache; +import org.apache.solr.search.stats.LRUStatsCache; +import org.apache.solr.search.stats.LocalStatsCache; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; /** @@ -49,6 +55,23 @@ public class DistributedMLTComponentTest extends BaseDistributedSearchTestCase { requestHandlerName = "mltrh"; super.distribSetUp(); } + + @BeforeClass + public static void beforeClass() { + int statsType = TestUtil.nextInt(random(), 1, 3); + if (statsType == 1) { + System.setProperty("solr.statsCache", ExactStatsCache.class.getName()); + } else if (statsType == 2) { + System.setProperty("solr.statsCache", LRUStatsCache.class.getName()); + } else { + System.setProperty("solr.statsCache", LocalStatsCache.class.getName()); + } + } + + @AfterClass + public static void afterClass() { + System.clearProperty("solr.statsCache"); + } @Test @ShardsFixed(num = 3) diff --git a/solr/core/src/test/org/apache/solr/handler/component/TermVectorComponentDistributedTest.java b/solr/core/src/test/org/apache/solr/handler/component/TermVectorComponentDistributedTest.java index 5d7ff9ad534..0527d9e5074 100644 --- a/solr/core/src/test/org/apache/solr/handler/component/TermVectorComponentDistributedTest.java +++ b/solr/core/src/test/org/apache/solr/handler/component/TermVectorComponentDistributedTest.java @@ -18,9 +18,14 @@ package org.apache.solr.handler.component; import org.apache.lucene.util.Constants; +import org.apache.lucene.util.TestUtil; import org.apache.solr.BaseDistributedSearchTestCase; import org.apache.solr.common.params.ShardParams; import org.apache.solr.common.params.TermVectorParams; +import org.apache.solr.search.stats.ExactStatsCache; +import org.apache.solr.search.stats.LRUStatsCache; +import org.apache.solr.search.stats.LocalStatsCache; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -29,6 +34,19 @@ public class TermVectorComponentDistributedTest extends BaseDistributedSearchTes public static void betterNotBeJ9() { assumeFalse("FIXME: SOLR-5792: This test fails under IBM J9", Constants.JAVA_VENDOR.startsWith("IBM")); + int statsType = TestUtil.nextInt(random(), 1, 3); + if (statsType == 1) { + System.setProperty("solr.statsCache", ExactStatsCache.class.getName()); + } else if (statsType == 2) { + System.setProperty("solr.statsCache", LRUStatsCache.class.getName()); + } else { + System.setProperty("solr.statsCache", LocalStatsCache.class.getName()); + } + } + + @AfterClass + public static void afterClass() { + System.clearProperty("solr.statsCache"); } @Test