lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markrmil...@apache.org
Subject svn commit: r905295 - in /lucene/solr/branches/cloud/src: java/org/apache/solr/cloud/ZkController.java java/org/apache/solr/core/CoreContainer.java test/org/apache/solr/cloud/AbstractZkTestCase.java test/org/apache/solr/cloud/CloudStateUpdateTest.java
Date Mon, 01 Feb 2010 14:56:17 GMT
Author: markrmiller
Date: Mon Feb  1 14:56:17 2010
New Revision: 905295

URL: http://svn.apache.org/viewvc?rev=905295&view=rev
Log:
add more rigorous testing for cloud state updates and sharing

Added:
    lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/CloudStateUpdateTest.java
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/test/org/apache/solr/cloud/AbstractZkTestCase.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=905295&r1=905294&r2=905295&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  1
14:56:17 2010
@@ -69,6 +69,8 @@
 
   static final String NEWL = System.getProperty("line.separator");
 
+  private static final long CLOUD_UPDATE_DELAY = Long.parseLong(System.getProperty("CLOUD_UPDATE_DELAY",
"5000"));
+
   private final static Pattern URL_POST = Pattern.compile("https?://(.*)");
   private final static Pattern URL_PREFIX = Pattern.compile("(https?://).*");
 
@@ -416,6 +418,7 @@
       this.cloudState = cloudState;
     } else {
       if(cloudStateUpdateScheduled) {
+        log.info("Cloud state update for ZooKeeper already scheduled");
         return;
       }
       log.info("Scheduling cloud state update from ZooKeeper...");
@@ -425,6 +428,7 @@
         public void run() {
           log.info("Updating cloud state from ZooKeeper...");
           synchronized (ZkController.this) {
+            cloudStateUpdateScheduled = false;
             CloudState cloudState;
             try {
               cloudState = CloudState.buildCloudState(zkClient);
@@ -445,10 +449,9 @@
             }
             // update volatile
             ZkController.this.cloudState = cloudState;
-            cloudStateUpdateScheduled = false;
           }
         }
-      }, 5000, TimeUnit.MILLISECONDS);
+      }, CLOUD_UPDATE_DELAY, TimeUnit.MILLISECONDS);
     }
 
   }

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=905295&r1=905294&r2=905295&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  1
14:56:17 2010
@@ -165,7 +165,7 @@
     protected String solrConfigFilename = null;
     protected boolean abortOnConfigurationError = true;
     protected String dataDir = null; // override datadir for single core mode
-    private String zkPortOverride;
+    protected String zkPortOverride;
     protected String testShardListOverride;
 
     public boolean isAbortOnConfigurationError() {

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=905295&r1=905294&r2=905295&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 Mon
Feb  1 14:56:17 2010
@@ -114,9 +114,6 @@
     putConfig(zkClient, "mapping-ISOLatin1Accent.txt");
     putConfig(zkClient, "old_synonyms.txt");
     
-    //nocommit
-    zkClient.printLayoutToStdOut();
-    
     zkClient.close();
   }
 

Added: lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/CloudStateUpdateTest.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/CloudStateUpdateTest.java?rev=905295&view=auto
==============================================================================
--- lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/CloudStateUpdateTest.java (added)
+++ lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/CloudStateUpdateTest.java Mon
Feb  1 14:56:17 2010
@@ -0,0 +1,170 @@
+package org.apache.solr.cloud;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.CoreDescriptor;
+import org.apache.solr.core.SolrCore;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CloudStateUpdateTest extends TestCase {
+  protected static Logger log = LoggerFactory
+      .getLogger(AbstractZkTestCase.class);
+
+  protected File tmpDir = new File(System.getProperty("java.io.tmpdir")
+      + System.getProperty("file.separator") + getClass().getName() + "-"
+      + System.currentTimeMillis());
+  
+  private static final boolean VERBOSE = true;
+
+  protected ZkTestServer zkServer;
+
+  protected String zkDir;
+
+  private CoreContainer container1;
+
+  private CoreContainer container2;
+  
+  private CoreContainer container3;
+
+  private File dataDir1;
+
+  private File dataDir2;
+
+  public void setUp() throws Exception {
+    try {
+      System.setProperty("zkHost", AbstractZkTestCase.ZOO_KEEPER_ADDRESS);
+      zkDir = tmpDir.getAbsolutePath() + File.separator
+          + "zookeeper/server1/data";
+      zkServer = new ZkTestServer(zkDir);
+      zkServer.run();
+
+      AbstractZkTestCase.buildZooKeeper("solrconfig.xml", "schema.xml");
+
+      log.info("####SETUP_START " + getName());
+      dataDir1 = new File(tmpDir + File.separator + "data1");
+      dataDir1.mkdirs();
+
+      dataDir2 = new File(tmpDir + File.separator + "data2");
+      dataDir2.mkdirs();
+
+      // set some system properties for use by tests
+      System.setProperty("solr.test.sys.prop1", "propone");
+      System.setProperty("solr.test.sys.prop2", "proptwo");
+
+      CoreContainer.Initializer init1 = new CoreContainer.Initializer() {
+        {
+          this.dataDir = CloudStateUpdateTest.this.dataDir1.getAbsolutePath();
+          this.zkPortOverride = "8983";
+        }
+      };
+
+      container1 = init1.initialize();
+
+      CoreContainer.Initializer init2 = new CoreContainer.Initializer() {
+        {
+          this.dataDir = CloudStateUpdateTest.this.dataDir2.getAbsolutePath();
+          this.zkPortOverride = "8984";
+        }
+      };
+
+      container2 = init2.initialize();
+      
+      CoreContainer.Initializer init3 = new CoreContainer.Initializer() {
+        {
+          this.dataDir = CloudStateUpdateTest.this.dataDir2.getAbsolutePath();
+          this.zkPortOverride = "8985";
+        }
+      };
+
+      container3 = init3.initialize();
+    } catch (Exception e) {
+      e.printStackTrace();
+      throw e;
+    }
+    log.info("####SETUP_END " + getName());
+
+  }
+  
+  public void testCoreRegistration() throws Exception {
+    System.setProperty("CLOUD_UPDATE_DELAY", "1");
+    CoreDescriptor dcore= new CoreDescriptor(container1, "testcore", "testcore");
+
+    SolrCore core = container1.create(dcore);
+    container1.register(core, false);
+    
+    // slight pause - TODO: takes an oddly long amount of time to schedule tasks with almost
no delay ...
+    Thread.sleep(5000);
+    
+    ZkController zkController2 = container2.getZooKeeperController();
+    
+    CloudState cloudState2 = zkController2.getCloudState();
+    Map<String,Slice> slices = cloudState2.getSlices("testcore");
+    
+    assertNotNull(slices);
+    assertTrue(slices.containsKey("thequadway:8983_solr_testcore"));
+    
+    Slice slice = slices.get("thequadway:8983_solr_testcore");
+    assertEquals("thequadway:8983_solr_testcore", slice.getName());
+    
+    Map<String,ZkNodeProps> shards = slice.getShards();
+    
+    assertEquals(1, shards.size());
+    
+    ZkNodeProps zkProps = shards.get("thequadway:8983_solr_testcore");
+    
+    assertNotNull(zkProps);
+    
+    assertEquals("thequadway:8983_solr", zkProps.get("node_name"));
+    
+    assertEquals("http://thequadway:8983/solr/testcore", zkProps.get("url"));
+    
+    Set<String> liveNodes = cloudState2.getLiveNodes();
+    assertNotNull(liveNodes);
+    assertEquals(3, liveNodes.size());
+    
+    container3.shutdown();
+    
+    liveNodes = zkController2.getCloudState().getLiveNodes();
+    
+    // nocommit - fix update cloud state when nodes removed
+    //assertEquals(2, liveNodes.size());
+  }
+
+  public void tearDown() throws Exception {
+    if(VERBOSE) {
+      printLayout();
+    }
+    super.tearDown();
+    zkServer.shutdown();
+  }
+
+  private void printLayout() throws Exception {
+    SolrZkClient zkClient = new SolrZkClient(
+        AbstractZkTestCase.ZOO_KEEPER_SERVER, AbstractZkTestCase.TIMEOUT);
+    zkClient.printLayoutToStdOut();
+    zkClient.close();
+  }
+}



Mime
View raw message