lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markrmil...@apache.org
Subject svn commit: r902218 - in /lucene/solr/branches/cloud/src/java/org/apache/solr: cloud/ZkController.java core/CoreContainer.java core/SolrCore.java
Date Fri, 22 Jan 2010 18:43:30 GMT
Author: markrmiller
Date: Fri Jan 22 18:43:29 2010
New Revision: 902218

URL: http://svn.apache.org/viewvc?rev=902218&view=rev
Log:
updates to core/shard registration - normal and after a zk reconnect

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
    lucene/solr/branches/cloud/src/java/org/apache/solr/core/SolrCore.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=902218&r1=902217&r2=902218&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 Fri Jan 22
18:43:29 2010
@@ -18,14 +18,11 @@
  */
 
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.InetAddress;
-import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -40,6 +37,7 @@
 
 import org.apache.solr.cloud.SolrZkClient.OnReconnect;
 import org.apache.solr.common.SolrException;
+import org.apache.solr.core.CoreContainer;
 import org.apache.solr.core.SolrConfig;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.core.SolrResourceLoader;
@@ -96,23 +94,24 @@
 
   private String hostName;
 
+  private CoreContainer coreContainer;
+
 
   /**
-   * 
    * @param zkServerAddress ZooKeeper server host address
    * @param zkClientTimeout
-   * @param collection
    * @param localHost
    * @param locaHostPort
    * @param localHostContext
-   * @throws IOException
-   * @throws TimeoutException
+   * @param coreConatiner
    * @throws InterruptedException
+   * @throws TimeoutException
+   * @throws IOException
    */
   public ZkController(String zkServerAddress, int zkClientTimeout, String localHost, String
locaHostPort,
-      String localHostContext) throws InterruptedException,
+      String localHostContext, final CoreContainer coreConatiner) throws InterruptedException,
       TimeoutException, IOException {
-
+    this.coreContainer = coreConatiner;
     this.zkServerAddress = zkServerAddress;
     this.localHostPort = locaHostPort;
     this.localHostContext = localHostContext;
@@ -126,6 +125,11 @@
               // nocommit : re-register ephemeral nodes, (possibly) wait a while
               // for others to do the same, then load
               createEphemeralNode();
+              // register cores in case any new cores came online will zk was down
+              Collection<SolrCore> cores = coreConatiner.getCores();
+              for(SolrCore core : cores) {
+                register(core, false);
+              }
               updateCloudState();
             } catch (KeeperException e) {
               log.error("", e);
@@ -545,40 +549,40 @@
     return Collections.unmodifiableMap(shardNameToProps);
   }
 
+
   /**
    * Register shard. A SolrCore calls this on startup to register with
    * ZooKeeper.
    * 
-   * @param core
-   * @return
+   * @param core SolrCore to register as a shard
+   * @param forcePropsUpdate update solr.xml core props even if the shard is already registered
+   * 
    * @throws IOException
-   * @throws InterruptedException
    * @throws KeeperException
+   * @throws InterruptedException
    */
-  public String register(SolrCore core) throws IOException,
+  public void register(SolrCore core, boolean forcePropsUpdate) throws IOException,
       KeeperException, InterruptedException {
     String coreName = core.getCoreDescriptor().getName();
     String shardUrl = localHostName + ":" + localHostPort + "/" + localHostContext
         + "/" + coreName;
+    
+    CloudDescriptor cloudDesc = core.getCoreDescriptor().getCloudDescriptor();
+    String collection = cloudDesc.getCollectionName();
+    
+    String shardsZkPath = COLLECTIONS_ZKNODE + "/" + collection + SHARDS_ZKNODE + "/" + cloudDesc.getShardId();
 
-    // nocommit:
+    boolean shardZkNodeAlreadyExists = zkClient.exists(shardsZkPath);
+    
+    if(shardZkNodeAlreadyExists && !forcePropsUpdate) {
+      return;
+    }
+    
     if (log.isInfoEnabled()) {
       log.info("Register shard - core:" + core.getName() + " address:"
           + shardUrl);
     }
 
-    CloudDescriptor cloudDesc = core.getCoreDescriptor().getCloudDescriptor();
-
-    String collection = cloudDesc.getCollectionName();
-    String nodePath = null;
-    String shardsZkPath = COLLECTIONS_ZKNODE + "/" + collection + SHARDS_ZKNODE + "/" + cloudDesc.getShardId();
-
-    // build layout if not exists
-    // nocommit : consider how we watch shards on all collections
-    addZkShardsNode(cloudDesc.getShardId(), collection);
-
-    // create node
-
     ZkNodeProps props = new ZkNodeProps();
     props.put(URL_PROP, shardUrl);
 
@@ -587,30 +591,40 @@
     props.put(NODE_NAME, getNodeName());
 
     byte[] bytes = props.store();
-
+    
     String shardZkNodeName = hostName + ":" + localHostPort + "_"+ localHostContext + (coreName.length()
== 0 ? "" : "_" + coreName);
-    try {
-      nodePath = zkClient.create(shardsZkPath + "/" + shardZkNodeName,
-        bytes, CreateMode.PERSISTENT);
-    } catch (KeeperException e) {
-      // its okay if the node already exists
-      if (e.code() != KeeperException.Code.NODEEXISTS) {
-        throw e;
+
+    
+    if(shardZkNodeAlreadyExists && forcePropsUpdate) {
+      // nocommit : consider how we watch shards on all collections
+      zkClient.setData(shardsZkPath + "/" + shardZkNodeName, bytes);
+    } else {
+      addZkShardsNode(cloudDesc.getShardId(), collection);
+      try {
+        zkClient.create(shardsZkPath + "/" + shardZkNodeName, bytes,
+            CreateMode.PERSISTENT);
+      } catch (KeeperException e) {
+        // its okay if the node already exists
+        if (e.code() != KeeperException.Code.NODEEXISTS) {
+          throw e;
+        }
+        // for some reason the shard already exists, though it didn't when we
+        // started registration - just return
+        return;
       }
     }
-    
+
     // signal that the shards node has changed
     // nocommit
     zkClient.setData(shardsZkPath, (byte[])null);
 
-    return nodePath;
+
   }
 
   /**
    * @param core
-   * @param zkNodePath
    */
-  public void unregister(SolrCore core, String zkNodePath) {
+  public void unregister(SolrCore core) {
     // nocommit : perhaps mark the core down in zk?
   }
 

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=902218&r1=902217&r2=902218&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 Fri Jan 22
18:43:29 2010
@@ -106,7 +106,7 @@
     if (zookeeperHost != null) {
       // we are ZooKeeper enabled
       try {
-        zooKeeperController = new ZkController(zookeeperHost, zkClientTimeout, host, hostPort,
hostContext);
+        zooKeeperController = new ZkController(zookeeperHost, zkClientTimeout, host, hostPort,
hostContext, this);
         
         String confDir = System.getProperty("bootstrap_confdir");
         if(confDir != null) {

Modified: lucene/solr/branches/cloud/src/java/org/apache/solr/core/SolrCore.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/java/org/apache/solr/core/SolrCore.java?rev=902218&r1=902217&r2=902218&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/java/org/apache/solr/core/SolrCore.java (original)
+++ lucene/solr/branches/cloud/src/java/org/apache/solr/core/SolrCore.java Fri Jan 22 18:43:29
2010
@@ -297,9 +297,7 @@
   List<SolrEventListener> newSearcherListeners;
 
   private ZkController zooKeeperComponent;
-  
-  // path of node that represents this core in ZooKeeper
-  private String zkNodePath;
+
 
   /**
    * NOTE: this function is not thread safe.  However, it is safe to call within the
@@ -545,7 +543,7 @@
       if (zooKeeperComponent != null) {
         // load ZooKeeper - nocommit: somehow fall back to local configs?
         try {
-          this.zkNodePath = zooKeeperComponent.register(this);
+          zooKeeperComponent.register(this, true);
         } catch (InterruptedException e) {
           // Restore the interrupted status
           Thread.currentThread().interrupt();
@@ -740,7 +738,7 @@
     log.info(logid+" CLOSING SolrCore " + this);
     // nocommit : if ZooKeeper, unregister core
     if(zooKeeperComponent != null) {
-      zooKeeperComponent.unregister(this, zkNodePath);
+      zooKeeperComponent.unregister(this);
     }
     try {
       infoRegistry.clear();



Mime
View raw message