You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2018/08/15 14:27:24 UTC
lucene-solr:master: SOLR-12649: CloudSolrClient retries requests
unnecessarily exception from server
Repository: lucene-solr
Updated Branches:
refs/heads/master 9cc0078af -> 60257ea27
SOLR-12649: CloudSolrClient retries requests unnecessarily exception from server
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/60257ea2
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/60257ea2
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/60257ea2
Branch: refs/heads/master
Commit: 60257ea276dab2838b884b6fe6a8e0a362ca1c79
Parents: 9cc0078
Author: Noble Paul <no...@apache.org>
Authored: Thu Aug 16 00:26:23 2018 +1000
Committer: Noble Paul <no...@apache.org>
Committed: Thu Aug 16 00:26:23 2018 +1000
----------------------------------------------------------------------
solr/CHANGES.txt | 2 +
.../solr/client/solrj/impl/CloudSolrClient.java | 5 +-
.../solrj/impl/CloudSolrClientRetryTest.java | 79 ++++++++++++++++++++
3 files changed, 85 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/60257ea2/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 5af49f8..599b124 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -237,6 +237,8 @@ Bug Fixes
* SOLR-12665: Autoscaling policy not being refreshed due to caching (noble)
+* SOLR-12649: CloudSolrClient retries requests unnecessarily exception from server (noble, shalin)
+
Optimizations
----------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/60257ea2/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
index 1eee687..6fc216e 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
@@ -927,7 +927,10 @@ public class CloudSolrClient extends SolrClient {
rootCause instanceof NoHttpResponseException ||
rootCause instanceof SocketException);
- if (wasCommError || (exc instanceof RouteException)) {
+ if (wasCommError
+ || (exc instanceof RouteException && (errorCode == 404 || errorCode == 503)) // 404 because the core does not exist 503 service unavailable
+ //TODO there are other reasons for 404. We need to change the solr response format from HTML to structured data to know that
+ ) {
// it was a communication error. it is likely that
// the node to which the request to be sent is down . So , expire the state
// so that the next attempt would fetch the fresh state
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/60257ea2/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientRetryTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientRetryTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientRetryTest.java
new file mode 100644
index 0000000..900ae71
--- /dev/null
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientRetryTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.solr.client.solrj.impl;
+
+import org.apache.solr.client.solrj.SolrRequest;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.cloud.SolrCloudTestCase;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.params.CommonParams;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.util.TestInjection;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class CloudSolrClientRetryTest extends SolrCloudTestCase {
+ private static final int NODE_COUNT = 1;
+
+ @BeforeClass
+ public static void setupCluster() throws Exception {
+ configureCluster(NODE_COUNT)
+ .addConfig("conf", getFile("solrj").toPath().resolve("solr").resolve("configsets").resolve("streaming").resolve("conf"))
+ .configure();
+ }
+
+ @Test
+ public void testRetry() throws Exception {
+ String collectionName = "testRetry";
+ CloudSolrClient solrClient = cluster.getSolrClient();
+ CollectionAdminRequest.createCollection(collectionName, 1, 1)
+ .process(solrClient);
+
+ solrClient.add(collectionName, new SolrInputDocument("id", "1"));
+
+ ModifiableSolrParams params = new ModifiableSolrParams();
+ params.set(CommonParams.QT, "/admin/metrics");
+ String updateRequestCountKey = "solr.core.testRetry.shard1.replica_n1:UPDATE./update.requestTimes:count";
+ params.set("key", updateRequestCountKey);
+ params.set("indent", "true");
+
+ QueryResponse response = solrClient.query(collectionName, params, SolrRequest.METHOD.GET);
+ NamedList<Object> namedList = response.getResponse();
+ System.out.println(namedList);
+ NamedList metrics = (NamedList) namedList.get("metrics");
+ assertEquals(1L, metrics.get(updateRequestCountKey));
+
+ TestInjection.failUpdateRequests = "true:100";
+ try {
+ expectThrows(CloudSolrClient.RouteException.class,
+ "Expected an exception on the client when failure is injected during updates", () -> {
+ solrClient.add(collectionName, new SolrInputDocument("id", "2"));
+ });
+ } finally {
+ TestInjection.reset();
+ }
+
+ response = solrClient.query(collectionName, params, SolrRequest.METHOD.GET);
+ namedList = response.getResponse();
+ System.out.println(namedList);
+ metrics = (NamedList) namedList.get("metrics");
+ assertEquals(2L, metrics.get(updateRequestCountKey));
+ }
+}