You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by er...@apache.org on 2015/07/10 03:47:44 UTC

svn commit: r1690190 - in /lucene/dev/trunk/solr: CHANGES.txt core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java

Author: erick
Date: Fri Jul 10 01:47:44 2015
New Revision: 1690190

URL: http://svn.apache.org/r1690190
Log:
SOLR-7132: The Collections API ADDREPLICA command property.name is not reflected in the clusterstate until after Solr restarts

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1690190&r1=1690189&r2=1690190&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Fri Jul 10 01:47:44 2015
@@ -218,6 +218,9 @@ Bug Fixes
 * SOLR-7143: MoreLikeThis Query parser should handle multiple field names
   (Jens Wille, Anshum Gupta)
 
+* SOLR-7132: The Collections API ADDREPLICA command property.name is not reflected 
+  in the clusterstate until after Solr restarts (Erick Erickson)
+
 Optimizations
 ----------------------
 

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java?rev=1690190&r1=1690189&r2=1690190&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java Fri Jul 10 01:47:44 2015
@@ -2493,6 +2493,9 @@ public class OverseerCollectionProcessor
     String node = message.getStr("node");
     String shard = message.getStr(SHARD_ID_PROP);
     String coreName = message.getStr(CoreAdminParams.NAME);
+    if (StringUtils.isBlank(coreName)) {
+      coreName = message.getStr(CoreAdminParams.PROPERTY_PREFIX + CoreAdminParams.NAME);
+    }
     
     final String asyncId = message.getStr(ASYNC);
     
@@ -2507,7 +2510,6 @@ public class OverseerCollectionProcessor
     ShardHandler shardHandler = shardHandlerFactory.getShardHandler();
     
     if (node == null) {
-      
       node = getNodesForNewShard(clusterState, collection, shard, 1, null,
           overseer.getZkController().getCoreContainer()).get(0).nodeName;
       log.info("Node not provided, Identified {} for creating new replica", node);

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java?rev=1690190&r1=1690189&r2=1690190&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java Fri Jul 10 01:47:44 2015
@@ -475,18 +475,18 @@ public class CollectionsAPIDistributedZk
     if (secondConfigSet) {
       createCmd.setCollectionConfigName("conf1");
     }
-    
+
     makeRequest(getBaseUrl((HttpSolrClient) clients.get(1)), createCmd);
     
     // try and create a SolrCore with no collection name
     createCmd.setCollection(null);
     createCmd.setCoreName("corewithnocollection2");
-    
+
     makeRequest(getBaseUrl((HttpSolrClient) clients.get(1)), createCmd);
     
     // in both cases, the collection should have default to the core name
     cloudClient.getZkStateReader().updateClusterState(true);
-    assertTrue( cloudClient.getZkStateReader().getClusterState().hasCollection("corewithnocollection"));
+    assertTrue(cloudClient.getZkStateReader().getClusterState().hasCollection("corewithnocollection"));
     assertTrue(cloudClient.getZkStateReader().getClusterState().hasCollection("corewithnocollection2"));
   }
 
@@ -1098,45 +1098,22 @@ public class CollectionsAPIDistributedZk
       String newReplicaName = Assign.assignNode(collectionName, client.getZkStateReader().getClusterState());
       ArrayList<String> nodeList = new ArrayList<>(client.getZkStateReader().getClusterState().getLiveNodes());
       Collections.shuffle(nodeList, random());
-      CollectionAdminRequest.AddReplica addReplica = new CollectionAdminRequest.AddReplica();
-      addReplica.setCollectionName(collectionName);
-      addReplica.setShardName("shard1");
-      addReplica.setNode(nodeList.get(0));
-      client.request(addReplica);
-
-      long timeout = System.currentTimeMillis() + 3000;
-      Replica newReplica = null;
-
-      for (; System.currentTimeMillis() < timeout; ) {
-        Slice slice = client.getZkStateReader().getClusterState().getSlice(collectionName, "shard1");
-        newReplica = slice.getReplica(newReplicaName);
-      }
 
-      assertNotNull(newReplica);
+      Replica newReplica = doAddReplica(collectionName, "shard1",
+          Assign.assignNode(collectionName, client.getZkStateReader().getClusterState()),
+          nodeList.get(0), client, null);
 
       log.info("newReplica {},\n{} ", newReplica, client.getZkStateReader().getBaseUrlForNodeName(nodeList.get(0)));
 
       assertEquals("Replica should be created on the right node",
           client.getZkStateReader().getBaseUrlForNodeName(nodeList.get(0)), newReplica.getStr(ZkStateReader.BASE_URL_PROP));
 
-      newReplicaName = Assign.assignNode(collectionName, client.getZkStateReader().getClusterState());
-      addReplica = new CollectionAdminRequest.AddReplica();
-      addReplica.setCollectionName(collectionName);
-      addReplica.setShardName("shard2");
       Properties props = new Properties();
       String instancePathStr = createTempDir().toString();
       props.put(CoreAdminParams.INSTANCE_DIR, instancePathStr); //Use name via the property.instanceDir method
-      addReplica.setProperties(props);
-      client.request(addReplica);
-
-      timeout = System.currentTimeMillis() + 3000;
-      newReplica = null;
-
-      for (; System.currentTimeMillis() < timeout; ) {
-        Slice slice = client.getZkStateReader().getClusterState().getSlice(collectionName, "shard2");
-        newReplica = slice.getReplica(newReplicaName);
-      }
-
+      newReplica = doAddReplica(collectionName, "shard2",
+          Assign.assignNode(collectionName, client.getZkStateReader().getClusterState()),
+          null, client, props);
       assertNotNull(newReplica);
 
       HttpSolrClient coreclient = new HttpSolrClient(newReplica.getStr(ZkStateReader.BASE_URL_PROP));
@@ -1160,9 +1137,44 @@ public class CollectionsAPIDistributedZk
       } catch (SolrException e) {
         assertTrue(e.getMessage().contains("Another replica with the same core name already exists for this collection"));
       }
+
+
+      // Check that specifying property.name works. DO NOT remove this when the "name" property is deprecated
+      // for ADDREPLICA, this is "property.name". See SOLR-7132
+      props = new Properties();
+      props.put(CoreAdminParams.NAME, "propertyDotName");
+
+      newReplica = doAddReplica(collectionName, "shard1",
+          Assign.assignNode(collectionName, client.getZkStateReader().getClusterState()),
+          nodeList.get(0), client, props);
+      assertEquals("'core' should be 'propertyDotName' ", "propertyDotName", newReplica.getStr("core"));
     }
   }
 
+  private Replica doAddReplica(String collectionName, String shard, String newReplicaName, String node,
+                               CloudSolrClient client, Properties props) throws IOException, SolrServerException {
+    CollectionAdminRequest.AddReplica addReplica = new CollectionAdminRequest.AddReplica();
+
+    addReplica.setCollectionName(collectionName);
+    addReplica.setShardName(shard);
+    if (node != null) {
+      addReplica.setNode(node);
+    }
+    if (props != null) {
+      addReplica.setProperties(props);
+    }
+    client.request(addReplica);
+    long timeout = System.currentTimeMillis() + 3000;
+    Replica newReplica = null;
+
+    for (; System.currentTimeMillis() < timeout; ) {
+      Slice slice = client.getZkStateReader().getClusterState().getSlice(collectionName, shard);
+      newReplica = slice.getReplica(newReplicaName);
+    }
+
+    assertNotNull(newReplica);
+    return newReplica;
+  }
   @Override
   protected QueryResponse queryServer(ModifiableSolrParams params) throws SolrServerException, IOException {