You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by ma...@apache.org on 2010/02/02 20:23:41 UTC

svn commit: r905753 - in /lucene/solr/branches/cloud/src: java/org/apache/solr/cloud/ZkController.java test/org/apache/solr/cloud/AbstractZkTestCase.java test/org/apache/solr/cloud/ZkControllerTest.java test/org/apache/solr/cloud/ZkSolrClientTest.java

Author: markrmiller
Date: Tue Feb  2 19:23:41 2010
New Revision: 905753

URL: http://svn.apache.org/viewvc?rev=905753&view=rev
Log:
switch collection config settings from path to props and other small changes

Modified:
    lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkController.java
    lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/AbstractZkTestCase.java
    lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkControllerTest.java
    lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkSolrClientTest.java

Modified: lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkController.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkController.java?rev=905753&r1=905752&r2=905753&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkController.java (original)
+++ lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkController.java Tue Feb  2 19:23:41 2010
@@ -124,9 +124,7 @@
 
           public void command() {
             try {
-
               createEphemeralLiveNode();
-
               updateCloudState(false);
             } catch (KeeperException e) {
               log.error("", e);
@@ -336,11 +334,8 @@
             "Unrecognized host:" + localHostName);
       }
       
-      // makes nodes node
+      // makes nodes zkNode
       try {
-        // TODO: for now, no watch - if a node goes down or comes up, its going to change
-        // shards info anyway and cause a state update - this could change if we do incremental
-        // state update
         zkClient.makePath(NODES_ZKNODE);
       } catch (KeeperException e) {
         // its okay if another beats us creating the node
@@ -350,8 +345,8 @@
               "", e);
         }
       }
-      createEphemeralLiveNode();
       
+      createEphemeralLiveNode();
       setUpCollectionsNode();
       
     } catch (IOException e) {
@@ -429,7 +424,7 @@
   }
   
   // load and publish a new CollectionInfo
-  public void updateLiveNodes() throws KeeperException, InterruptedException,
+  private void updateLiveNodes() throws KeeperException, InterruptedException,
       IOException {
     updateCloudState(true, true);
   }
@@ -509,36 +504,23 @@
    * @return
    * @throws KeeperException
    * @throws InterruptedException
+   * @throws IOException 
    */
   public String readConfigName(String collection) throws KeeperException,
-      InterruptedException {
-    // nocommit: load all config at once or organize differently (Properties?)
+      InterruptedException, IOException {
+
     String configName = null;
 
     String path = COLLECTIONS_ZKNODE + "/" + collection;
     if (log.isInfoEnabled()) {
       log.info("Load collection config from:" + path);
     }
-    List<String> children;
-    try {
-      children = zkClient.getChildren(path, null);
-    } catch (KeeperException.NoNodeException e) {
-      log.error(
-          "Config name to use for collection:"
-              + collection + " could not be located", e);
-      throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
-          "Config name to use for collection:"
-              + collection + " could not be located", e);
-    }
-    for (String node : children) {
-      // nocommit: do we actually want to handle settings in the node name?
-      if (node.startsWith("config=")) {
-        configName = node.substring(node.indexOf("=") + 1);
-        if (log.isInfoEnabled()) {
-          log.info("Using collection config:" + configName);
-        }
-        // nocommmit : bail or read more?
-      }
+    byte[] data = zkClient.getData(path, null, null);
+    ZkNodeProps props = new ZkNodeProps();
+    
+    if(data != null) {
+      props.load(data);
+      configName = props.get("configName");
     }
     
     if (configName != null && !zkClient.exists(CONFIGS_ZKNODE + "/" + configName)) {
@@ -853,25 +835,26 @@
     }
   }
 
-  public void createCollectionZkNode(String collection) throws KeeperException, InterruptedException {
+  public void createCollectionZkNode(String collection) throws KeeperException, InterruptedException, IOException {
     String collectionPath = COLLECTIONS_ZKNODE + "/" + collection;
     
-    boolean newCollection = false;
-    
     try {
       if(!zkClient.exists(collectionPath)) {
         log.info("Creating collection in ZooKeeper:" + collection);
         try {
-          zkClient.makePath(collectionPath, CreateMode.PERSISTENT, null);
-          String confName = readConfigName(collection);
-          if(confName == null && System.getProperty("bootstrap_confdir") != null) {
+          ZkNodeProps props = new ZkNodeProps();
+          // if we are bootstrapping a collection, default the config for
+          // a new collection to the collection we are bootstrapping
+          if(System.getProperty("bootstrap_confdir") != null) {
+            String confName = System.getProperty("bootstrap_confname", "configuration1");
             log.info("Setting config for collection:" + collection + " to " + confName);
-            confName = System.getProperty("bootstrap_confname", "configuration1");
-            zkClient.makePath(COLLECTIONS_ZKNODE + "/" + collection + "/config=" + confName);
+            props.put("configName",  confName);
           }
-          newCollection = true;
+          
+          zkClient.makePath(COLLECTIONS_ZKNODE + "/" + collection, props.store(), CreateMode.PERSISTENT);
+         
         } catch (KeeperException e) {
-          // its okay if another beats us creating the node
+          // its okay if the node already exists
           if (e.code() != KeeperException.Code.NODEEXISTS) {
             throw e;
           }
@@ -885,12 +868,6 @@
       }
     }
     
-    if(newCollection) {
-      // nocommit - scrutinize
-      // ping that there is a new collection
-      zkClient.setData(COLLECTIONS_ZKNODE, (byte[])null);
-    }
-    
   }
 
 }

Modified: lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/AbstractZkTestCase.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/AbstractZkTestCase.java?rev=905753&r1=905752&r2=905753&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/AbstractZkTestCase.java (original)
+++ lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/AbstractZkTestCase.java Tue Feb  2 19:23:41 2010
@@ -22,6 +22,7 @@
 import org.apache.solr.core.CoreContainer;
 import org.apache.solr.util.AbstractSolrTestCase;
 import org.apache.solr.util.TestHarness;
+import org.apache.zookeeper.CreateMode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -104,8 +105,13 @@
 
     zkClient = new SolrZkClient(ZOO_KEEPER_ADDRESS, AbstractZkTestCase.TIMEOUT);
     
-    zkClient.makePath("/collections/collection1/config=conf1");
-    zkClient.makePath("/collections/testcore/config=conf1");
+    ZkNodeProps props1 = new ZkNodeProps();
+    props1.put("configName", "conf1");
+    zkClient.makePath("/collections/collection1", props1.store(), CreateMode.PERSISTENT);
+    
+    ZkNodeProps props2 = new ZkNodeProps();
+    props2.put("configName", "conf1");
+    zkClient.makePath("/collections/testcore", props2.store(), CreateMode.PERSISTENT);
     
     putConfig(zkClient, config);
     putConfig(zkClient, schema);

Modified: lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkControllerTest.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkControllerTest.java?rev=905753&r1=905752&r2=905753&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkControllerTest.java (original)
+++ lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkControllerTest.java Tue Feb  2 19:23:41 2010
@@ -80,6 +80,7 @@
 
       zkController = new ZkController(AbstractZkTestCase.ZOO_KEEPER_ADDRESS,
           TIMEOUT, 1000, "localhost", "8983", "/solr");
+ 
       zkController.updateCloudState(true);
       CloudState cloudInfo = zkController.getCloudState();
       Map<String,Slice> slices = cloudInfo.getSlices("collection1");
@@ -145,9 +146,9 @@
 
       zkClient.makePath(ZkController.CONFIGS_ZKNODE + "/" + actualConfigName);
       
-      String shardsPath = ZkController.COLLECTIONS_ZKNODE + "/" + COLLECTION_NAME + "/config="
-          + actualConfigName;
-      zkClient.makePath(shardsPath);
+      ZkNodeProps props = new ZkNodeProps();
+      props.put("configName", actualConfigName);
+      zkClient.makePath(ZkController.COLLECTIONS_ZKNODE + "/" + COLLECTION_NAME , props.store(), CreateMode.PERSISTENT);
 
       if (DEBUG) {
         zkClient.printLayoutToStdOut();

Modified: lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkSolrClientTest.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkSolrClientTest.java?rev=905753&r1=905752&r2=905753&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkSolrClientTest.java (original)
+++ lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkSolrClientTest.java Tue Feb  2 19:23:41 2010
@@ -80,7 +80,7 @@
       String shardsPath = "/collections/collection1/shards";
       zkClient.makePath(shardsPath);
 
-      zkClient.makePath("collections/collection1/config=collection1");
+      zkClient.makePath("collections/collection1");
       
       // this tests disconnect state
       server.shutdown();
@@ -89,7 +89,7 @@
       
       boolean exceptionHappened = false;
       try {
-        zkClient.makePath("collections/collection1/config=collection2");
+        zkClient.makePath("collections/collection2");
       } catch (KeeperException.ConnectionLossException e) {
         // nocommit : the connection should be down
         exceptionHappened = true;
@@ -103,12 +103,12 @@
       // wait for reconnect
       Thread.sleep(1000);
       
-      zkClient.makePath("collections/collection1/config=collection3");
+      zkClient.makePath("collections/collection3");
       
       zkClient.printLayoutToStdOut();
       
-      assertNotNull(zkClient.exists("/collections/collection1/config=collection3", null));
-      assertNotNull(zkClient.exists("/collections/collection1/config=collection1", null));
+      assertNotNull(zkClient.exists("/collections/collection3", null));
+      assertNotNull(zkClient.exists("/collections/collection1", null));
       
       //this tests expired state
       
@@ -119,11 +119,11 @@
       
       Thread.sleep(3000); // pause for reconnect
       
-      zkClient.makePath("collections/collection1/config=collection4");
+      zkClient.makePath("collections/collection4");
       
       zkClient.printLayoutToStdOut();
       
-      assertNotNull(zkClient.exists("/collections/collection1/config=collection4", null));
+      assertNotNull(zkClient.exists("/collections/collection4", null));
 
     } catch(Exception e) {
       // nocommit