You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by va...@apache.org on 2015/05/15 16:04:32 UTC

svn commit: r1679568 - in /lucene/dev/trunk/solr: ./ core/src/java/org/apache/solr/handler/admin/ core/src/test/org/apache/solr/cloud/ solrj/src/java/org/apache/solr/common/cloud/

Author: varun
Date: Fri May 15 14:04:31 2015
New Revision: 1679568

URL: http://svn.apache.org/r1679568
Log:
SOLR-7541: Removed CollectionsHandler#createNodeIfNotExists. All calls made to this method now call ZkCmdExecutor#ensureExists as they were doing the same thing

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/OverseerCollectionProcessorTest.java
    lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1679568&r1=1679567&r2=1679568&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Fri May 15 14:04:31 2015
@@ -368,6 +368,10 @@ Other Changes
 * SOLR-7532: Removed occurrences of the unused 'commitIntervalLowerBound' property for
   updateHandler elements from Solr configuration. (Marius Grama via shalin)
 
+* SOLR-7541: Removed CollectionsHandler#createNodeIfNotExists. All calls made to this method now call
+  ZkCmdExecutor#ensureExists as they were doing the same thing. Also ZkCmdExecutor#ensureExists now respects the
+  CreateMode passed to it.
+
 ==================  5.1.0 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java?rev=1679568&r1=1679567&r2=1679568&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/admin/CollectionsHandler.java Fri May 15 14:04:31 2015
@@ -17,6 +17,7 @@ package org.apache.solr.handler.admin;
  * limitations under the License.
  */
 
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
@@ -42,6 +43,7 @@ import org.apache.solr.common.SolrExcept
 import org.apache.solr.common.cloud.ClusterState;
 import org.apache.solr.common.cloud.ImplicitDocRouter;
 import org.apache.solr.common.cloud.SolrZkClient;
+import org.apache.solr.common.cloud.ZkCmdExecutor;
 import org.apache.solr.common.cloud.ZkCoreNodeProps;
 import org.apache.solr.common.cloud.ZkNodeProps;
 import org.apache.solr.common.cloud.ZkStateReader;
@@ -61,7 +63,6 @@ import org.apache.zookeeper.KeeperExcept
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.apache.solr.cloud.Overseer.QUEUE_OPERATION;
 import static org.apache.solr.cloud.OverseerCollectionProcessor.ASYNC;
 import static org.apache.solr.cloud.OverseerCollectionProcessor.COLL_CONF;
@@ -78,7 +79,6 @@ import static org.apache.solr.common.clo
 import static org.apache.solr.common.cloud.DocCollection.STATE_FORMAT;
 import static org.apache.solr.common.cloud.ZkStateReader.AUTO_ADD_REPLICAS;
 import static org.apache.solr.common.cloud.ZkStateReader.COLLECTION_PROP;
-import static org.apache.solr.common.cloud.ZkStateReader.CONFIGS_ZKNODE;
 import static org.apache.solr.common.cloud.ZkStateReader.MAX_SHARDS_PER_NODE;
 import static org.apache.solr.common.cloud.ZkStateReader.PROPERTY_PROP;
 import static org.apache.solr.common.cloud.ZkStateReader.PROPERTY_VALUE_PROP;
@@ -244,17 +244,6 @@ public class CollectionsHandler extends
     return collectionQueue.containsTaskWithRequestId(asyncId);
   }
 
-  public static void createNodeIfNotExists(SolrZkClient zk, String path, byte[] data) throws KeeperException, InterruptedException {
-    if(!zk.exists(path, true)){
-      //create the config znode
-      try {
-        zk.create(path,data, CreateMode.PERSISTENT,true);
-      } catch (KeeperException.NodeExistsException e) {
-        //no problem . race condition. carry on the good work
-      }
-    }
-  }
-
   private static Map<String, Object> copyPropertiesWithPrefix(SolrParams params, Map<String, Object> props, String prefix) {
     Iterator<String> iter =  params.getParameterNamesIterator();
     while (iter.hasNext()) {
@@ -338,12 +327,17 @@ public class CollectionsHandler extends
 
       private void createSysConfigSet(CoreContainer coreContainer) throws KeeperException, InterruptedException {
         SolrZkClient zk = coreContainer.getZkController().getZkStateReader().getZkClient();
-        createNodeIfNotExists(zk, CONFIGS_ZKNODE, null);
-        createNodeIfNotExists(zk, CONFIGS_ZKNODE + "/" + SYSTEM_COLL, null);
-        createNodeIfNotExists(zk, CONFIGS_ZKNODE + "/" + SYSTEM_COLL + "/schema.xml",
-            BlobHandler.SCHEMA.replaceAll("'", "\"").getBytes(UTF_8));
-        createNodeIfNotExists(zk, CONFIGS_ZKNODE + "/" + SYSTEM_COLL + "/solrconfig.xml",
-            BlobHandler.CONF.replaceAll("'", "\"").getBytes(UTF_8));
+        ZkCmdExecutor cmdExecutor = new ZkCmdExecutor(zk.getZkClientTimeout());
+        cmdExecutor.ensureExists(ZkStateReader.CONFIGS_ZKNODE, zk);
+        cmdExecutor.ensureExists(ZkStateReader.CONFIGS_ZKNODE + "/" + SYSTEM_COLL, zk);
+
+        String path = ZkStateReader.CONFIGS_ZKNODE + "/" + SYSTEM_COLL + "/schema.xml";
+        byte[] data = BlobHandler.SCHEMA.replaceAll("'", "\"").getBytes(StandardCharsets.UTF_8);
+        cmdExecutor.ensureExists(path, data, CreateMode.PERSISTENT, zk);
+
+        path = ZkStateReader.CONFIGS_ZKNODE + "/" + SYSTEM_COLL + "/solrconfig.xml";
+        data = BlobHandler.CONF.replaceAll("'", "\"").getBytes(StandardCharsets.UTF_8);
+        cmdExecutor.ensureExists(path, data, CreateMode.PERSISTENT, zk);
       }
     },
     DELETE_OP(DELETE) {

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/OverseerCollectionProcessorTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/OverseerCollectionProcessorTest.java?rev=1679568&r1=1679567&r2=1679568&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/OverseerCollectionProcessorTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/OverseerCollectionProcessorTest.java Fri May 15 14:04:31 2015
@@ -330,6 +330,15 @@ public class OverseerCollectionProcessor
       }
     }).anyTimes();
 
+    solrZkClientMock.makePath(anyObject(String.class), anyObject(byte[].class), anyObject(CreateMode.class), anyBoolean());
+    expectLastCall().andAnswer(new IAnswer<String>() {
+      @Override
+      public String answer() throws Throwable {
+        String key = (String) getCurrentArguments()[0];
+        return key;
+      }
+    }).anyTimes();
+
     solrZkClientMock.exists(anyObject(String.class),anyBoolean());
     expectLastCall().andAnswer(new IAnswer<Boolean>() {
       @Override

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java?rev=1679568&r1=1679567&r2=1679568&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java (original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCmdExecutor.java Fri May 15 14:04:31 2015
@@ -91,7 +91,7 @@ public class ZkCmdExecutor {
       return;
     }
     try {
-      zkClient.makePath(path, data, true);
+      zkClient.makePath(path, data, createMode, true);
     } catch (NodeExistsException e) {
       // it's okay if another beats us creating the node
     }