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/01/27 23:46:31 UTC

svn commit: r903895 - in /lucene/solr/branches/cloud/src/java/org/apache/solr: cloud/ZkController.java core/CoreContainer.java

Author: markrmiller
Date: Wed Jan 27 22:46:30 2010
New Revision: 903895

URL: http://svn.apache.org/viewvc?rev=903895&view=rev
Log:
bootstrap code for setting collection config

Modified:
    lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkController.java
    lucene/solr/branches/cloud/src/java/org/apache/solr/core/CoreContainer.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=903895&r1=903894&r2=903895&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 Wed Jan 27 22:46:30 2010
@@ -168,29 +168,11 @@
    */
   private void addZkShardsNode(String shardId, String collection) throws IOException, InterruptedException, KeeperException {
 
-    String collectionPath = COLLECTIONS_ZKNODE + "/" + collection;
     String shardsZkPath = COLLECTIONS_ZKNODE + "/" + collection + SHARDS_ZKNODE + "/" + shardId;
     
-    boolean newCollection = false;
     boolean newShardId = false;
     
     try {
-      if(!zkClient.exists(collectionPath)) {
-        try {
-          zkClient.makePath(collectionPath, CreateMode.PERSISTENT, null);
-          String confName = readConfigName(collection);
-          if(confName == null && System.getProperty("bootstrap_confdir") != null) {
-            confName = System.getProperty("bootstrap_confname", "configuration1");
-            zkClient.makePath(COLLECTIONS_ZKNODE + "/" + collection + "/conifg=" + confName);
-          }
-          newCollection = true;
-        } catch (KeeperException e) {
-          // its okay if another beats us creating the node
-          if (e.code() != KeeperException.Code.NODEEXISTS) {
-            throw e;
-          }
-        }
-      }
       
       // shards node
       if (!zkClient.exists(shardsZkPath)) {
@@ -210,9 +192,9 @@
       }
     }
     
-    if(newCollection || newShardId) {
+    if(newShardId) {
       // nocommit - scrutinize
-      // ping that there is a new collection or a new shardId
+      // ping that there is a new shardId
       zkClient.setData(COLLECTIONS_ZKNODE, (byte[])null);
     }
   }
@@ -524,7 +506,7 @@
       }
     }
     
-    if(!zkClient.exists(CONFIGS_ZKNODE + "/" + configName)) {
+    if (configName != null && !zkClient.exists(CONFIGS_ZKNODE + "/" + configName)) {
       log.error("Specified config does not exist in ZooKeeper:" + configName);
       throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
           "Specified config does not exist in ZooKeeper:" + configName);
@@ -836,4 +818,44 @@
     }
   }
 
+  public void createCollectionZkNode(String collection) throws KeeperException, InterruptedException {
+    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) {
+            log.info("Setting config for collection:" + collection + " to " + confName);
+            confName = System.getProperty("bootstrap_confname", "configuration1");
+            zkClient.makePath(COLLECTIONS_ZKNODE + "/" + collection + "/config=" + confName);
+          }
+          newCollection = true;
+        } catch (KeeperException e) {
+          // its okay if another beats us creating the node
+          if (e.code() != KeeperException.Code.NODEEXISTS) {
+            throw e;
+          }
+        }
+      }
+      
+    } catch (KeeperException e) {
+      // its okay if another beats us creating the node
+      if (e.code() != KeeperException.Code.NODEEXISTS) {
+        throw e;
+      }
+    }
+    
+    if(newCollection) {
+      // nocommit - scrutinize
+      // ping that there is a new collection
+      zkClient.setData(COLLECTIONS_ZKNODE, (byte[])null);
+    }
+    
+  }
+
 }

Modified: lucene/solr/branches/cloud/src/java/org/apache/solr/core/CoreContainer.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/java/org/apache/solr/core/CoreContainer.java?rev=903895&r1=903894&r2=903895&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/java/org/apache/solr/core/CoreContainer.java (original)
+++ lucene/solr/branches/cloud/src/java/org/apache/solr/core/CoreContainer.java Wed Jan 27 22:46:30 2010
@@ -586,7 +586,14 @@
       config = new SolrConfig(solrLoader, dcore.getConfigName(), null);
     } else {
       try {
-        zkConfigName = zooKeeperController.readConfigName(dcore.getCloudDescriptor().getCollectionName());
+        String collection = dcore.getCloudDescriptor().getCollectionName();
+        zooKeeperController.createCollectionZkNode(collection);
+        zkConfigName = zooKeeperController.readConfigName(collection);
+        if (zkConfigName == null) {
+          log.error("Could not find config name for collection:" + collection);
+          throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
+              "Could not find config name for collection:" + collection);
+        }
         solrLoader = new ZkSolrResourceLoader(instanceDir, zkConfigName, libLoader, getCoreProps(instanceDir, dcore.getPropertiesName(),dcore.getCoreProperties()), zooKeeperController);
         config = zooKeeperController.getConfig(zkConfigName, dcore.getConfigName(), solrLoader);
       } catch (KeeperException e) {