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/22 16:14:09 UTC

svn commit: r912602 - in /lucene/solr/branches/cloud/src: common/org/apache/solr/common/cloud/ java/org/apache/solr/cloud/ java/org/apache/solr/core/ solrj/org/apache/solr/client/solrj/impl/

Author: markrmiller
Date: Mon Feb 22 15:14:09 2010
New Revision: 912602

URL: http://svn.apache.org/viewvc?rev=912602&view=rev
Log:
add watches on reconnect

Modified:
    lucene/solr/branches/cloud/src/common/org/apache/solr/common/cloud/ConnectionManager.java
    lucene/solr/branches/cloud/src/common/org/apache/solr/common/cloud/ZkStateReader.java
    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/solrj/org/apache/solr/client/solrj/impl/CloudSolrServer.java

Modified: lucene/solr/branches/cloud/src/common/org/apache/solr/common/cloud/ConnectionManager.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/common/org/apache/solr/common/cloud/ConnectionManager.java?rev=912602&r1=912601&r2=912602&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/common/org/apache/solr/common/cloud/ConnectionManager.java (original)
+++ lucene/solr/branches/cloud/src/common/org/apache/solr/common/cloud/ConnectionManager.java Mon Feb 22 15:14:09 2010
@@ -96,6 +96,7 @@
       log.info("Connected:" + connected);
     } else if (state == KeeperState.Disconnected) {
       // ZooKeeper client will recover when it can
+      // TODO: this needs to be investigated more
       connected = false;
     } else {
       connected = false;

Modified: lucene/solr/branches/cloud/src/common/org/apache/solr/common/cloud/ZkStateReader.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/common/org/apache/solr/common/cloud/ZkStateReader.java?rev=912602&r1=912601&r2=912602&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/common/org/apache/solr/common/cloud/ZkStateReader.java (original)
+++ lucene/solr/branches/cloud/src/common/org/apache/solr/common/cloud/ZkStateReader.java Mon Feb 22 15:14:09 2010
@@ -67,7 +67,8 @@
 
           public void command() {
             try {
-              // nocommit: recreate watches ????
+              makeCollectionsNodeWatches();
+              makeShardsWatches(true);
               updateCloudState(false);
             } catch (KeeperException e) {
               log.error("", e);
@@ -160,20 +161,20 @@
 
   }
   
-  public void makeShardZkNodeWatches() throws KeeperException, InterruptedException {
+  public void makeShardZkNodeWatches(boolean makeWatchesForReconnect) throws KeeperException, InterruptedException {
     CloudState cloudState = getCloudState();
-    Set<String> knownCollections = cloudState.getCollections();
     
+    Set<String> knownCollections = cloudState.getCollections();
     List<String> collections = zkClient.getChildren(COLLECTIONS_ZKNODE, null);
 
     for(final String collection : collections) {
-      if(!knownCollections.contains(collection)) {
+      if(makeWatchesForReconnect || !knownCollections.contains(collection)) {
         log.info("Found new collection:" + collection);
         Watcher watcher = new Watcher() {
           public void process(WatchedEvent event) {
             log.info("Detected changed ShardId in collection:" + collection);
             try {
-              makeShardsWatches(collection);
+              makeShardsWatches(collection, false);
               updateCloudState(false);
             } catch (KeeperException e) {
               log.error("", e);
@@ -217,7 +218,7 @@
     }
   }
   
-  public void makeShardsWatches(final String collection) throws KeeperException,
+  public void makeShardsWatches(final String collection, boolean makeWatchesForReconnect) throws KeeperException,
       InterruptedException {
     if (zkClient.exists(COLLECTIONS_ZKNODE + "/" + collection + SHARDS_ZKNODE)) {
       List<String> shardIds = zkClient.getChildren(COLLECTIONS_ZKNODE + "/"
@@ -231,7 +232,7 @@
         knownShardIds = new HashSet<String>(0);
       }
       for (final String shardId : shardIds) {
-        if (!knownShardIds.contains(shardId)) {
+        if (makeWatchesForReconnect || !knownShardIds.contains(shardId)) {
           zkClient.getChildren(COLLECTIONS_ZKNODE + "/" + collection
               + SHARDS_ZKNODE + "/" + shardId, new Watcher() {
 
@@ -265,10 +266,10 @@
    * @throws KeeperException
    * @throws InterruptedException
    */
-  public void makeShardsWatches() throws KeeperException, InterruptedException {
+  public void makeShardsWatches(boolean makeWatchesForReconnect) throws KeeperException, InterruptedException {
     List<String> collections = zkClient.getChildren(COLLECTIONS_ZKNODE, null);
     for (final String collection : collections) {
-      makeShardsWatches(collection);
+      makeShardsWatches(collection, makeWatchesForReconnect);
     }
   }
   
@@ -305,7 +306,7 @@
           try {
             log.info("Detected a new or removed collection");
             synchronized (getUpdateLock()) {
-              makeShardZkNodeWatches();
+              makeShardZkNodeWatches(false);
               updateCloudState(false);
             }
             // re-watch
@@ -337,7 +338,7 @@
         log.info("Notified of CloudState change");
         try {
           synchronized (getUpdateLock()) {
-            makeShardZkNodeWatches();
+            makeShardZkNodeWatches(false);
             updateCloudState(false);
           }
           zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE, this);

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=912602&r1=912601&r2=912602&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 Mon Feb 22 15:14:09 2010
@@ -38,7 +38,6 @@
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.Watcher.Event.EventType;
 import org.apache.zookeeper.data.Stat;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -110,7 +109,8 @@
 
           public void command() {
             try {
-              // nocommit: recreate watches ????
+              zkStateReader.makeCollectionsNodeWatches();
+              zkStateReader.makeShardsWatches(true);
               createEphemeralLiveNode();
               zkStateReader.updateCloudState(false);
             } catch (KeeperException e) {

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=912602&r1=912601&r2=912602&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 Mon Feb 22 15:14:09 2010
@@ -431,7 +431,7 @@
     if(zkController != null) {
       try {
         synchronized (zkController.getZkStateReader().getUpdateLock()) {
-          zkController.getZkStateReader().makeShardZkNodeWatches();
+          zkController.getZkStateReader().makeShardZkNodeWatches(false);
           zkController.getZkStateReader().updateCloudState(true);
         }
       } catch (InterruptedException e) {

Modified: lucene/solr/branches/cloud/src/solrj/org/apache/solr/client/solrj/impl/CloudSolrServer.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/solrj/org/apache/solr/client/solrj/impl/CloudSolrServer.java?rev=912602&r1=912601&r2=912602&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/solrj/org/apache/solr/client/solrj/impl/CloudSolrServer.java (original)
+++ lucene/solr/branches/cloud/src/solrj/org/apache/solr/client/solrj/impl/CloudSolrServer.java Mon Feb 22 15:14:09 2010
@@ -78,7 +78,7 @@
       try {
         ZkStateReader zk = new ZkStateReader(zkHost, zkConnectTimeout, zkClientTimeout);
         zk.makeCollectionsNodeWatches();
-        zk.makeShardZkNodeWatches();
+        zk.makeShardZkNodeWatches(false);
         zk.updateCloudState(true);
         zkStateReader = zk;
       } catch (InterruptedException e) {