Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-6591: Overseer can use stale cluster state and lose updates for collections with stateFormat > 1

Shalin Shekhar Mangar08c6f54346b6
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 836ff177c19..e54b0217c17 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -267,6 +267,9 @@ Bug Fixes
* SOLR-6647: Bad error message when missing resource from ZK when parsing Schema (janhoy)
+* SOLR-6591: Overseer can use stale cluster state and lose updates for collections
+ with stateFormat > 1. (shalin)
+
Optimizations
----------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
index 3b0bcf7e953..d120098e4dd 100644
--- a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
@@ -1039,18 +1039,9 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
"conf1");
// remove collection
- ModifiableSolrParams params = new ModifiableSolrParams();
- params.set("action", CollectionAction.DELETE.toString());
- params.set("name", collectionName);
- QueryRequest request = new QueryRequest(params);
- request.setPath("/admin/collections");
-
- if (client == null) {
- client = createCloudClient(null);
- }
-
- client.request(request);
-
+ CollectionAdminRequest.Delete delete = new CollectionAdminRequest.Delete();
+ delete.setCollectionName(collectionName);
+ client.request(delete);
} catch (SolrServerException e) {
e.printStackTrace();
throw new RuntimeException(e);
diff --git a/solr/core/src/test/org/apache/solr/cloud/SimpleCollectionCreateDeleteTest.java b/solr/core/src/test/org/apache/solr/cloud/SimpleCollectionCreateDeleteTest.java
new file mode 100644
index 00000000000..ad00be9cb85
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/cloud/SimpleCollectionCreateDeleteTest.java
@@ -0,0 +1,82 @@
+package org.apache.solr.cloud;
+
+/*
+ * 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.
+ */
+
+import org.apache.solr.client.solrj.impl.CloudSolrServer;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.client.solrj.request.QueryRequest;
+import org.apache.solr.common.cloud.SolrZkClient;
+import org.apache.solr.common.cloud.ZkStateReader;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.NamedList;
+
+public class SimpleCollectionCreateDeleteTest extends AbstractFullDistribZkTestBase {
+
+ public SimpleCollectionCreateDeleteTest() {
+ fixShardCount = true;
+ sliceCount = 1;
+ shardCount = 1;
+ }
+
+ @Override
+ public void doTest() throws Exception {
+ String overseerNode = OverseerCollectionProcessor.getLeaderNode(cloudClient.getZkStateReader().getZkClient());
+ String notOverseerNode = null;
+ for (CloudJettyRunner cloudJetty : cloudJettys) {
+ if (!overseerNode.equals(cloudJetty.nodeName)) {
+ notOverseerNode = cloudJetty.nodeName;
+ break;
+ }
+ }
+ CollectionAdminRequest.Create create = new CollectionAdminRequest.Create();
+ String collectionName = "SimpleCollectionCreateDeleteTest";
+ create.setCollectionName(collectionName);
+ create.setNumShards(1);
+ create.setReplicationFactor(1);
+ create.setCreateNodeSet(overseerNode);
+ ModifiableSolrParams params = new ModifiableSolrParams(create.getParams());
+ params.set("stateFormat", "2");
+ QueryRequest req = new QueryRequest(params);
+ req.setPath("/admin/collections");
+ NamedList<Object> request = cloudClient.request(req);
+
+ if (request.get("success") != null) {
+ assertTrue(cloudClient.getZkStateReader().getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, false));
+
+ CollectionAdminRequest.Delete delete = new CollectionAdminRequest.Delete();
+ delete.setCollectionName(collectionName);
+ cloudClient.request(delete);
+
+ assertFalse(cloudClient.getZkStateReader().getZkClient().exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + collectionName, false));
+
+ // create collection again on a node other than the overseer leader
+ create = new CollectionAdminRequest.Create();
+ create.setCollectionName(collectionName);
+ create.setNumShards(1);
+ create.setReplicationFactor(1);
+ create.setCreateNodeSet(notOverseerNode);
+ params = new ModifiableSolrParams(create.getParams());
+ params.set("stateFormat", "2");
+ req = new QueryRequest(params);
+ req.setPath("/admin/collections");
+ request = cloudClient.request(req);
+ assertTrue("Collection creation should not have failed", request.get("success") != null);
+ }
+ }
+}
diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
index 4a8dbd9c4ba..dc6ac87c6af 100644
--- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
@@ -876,6 +876,7 @@ public class ZkStateReader implements Closeable {
public void removeZKWatch(final String coll) {
synchronized (this) {
watchedCollections.remove(coll);
+ watchedCollectionStates.remove(coll);
try {
updateClusterState(true);
} catch (KeeperException e) {