You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2012/09/10 04:14:52 UTC

svn commit: r1382621 [2/2] - in /lucene/dev/trunk/solr: contrib/clustering/src/java/org/apache/solr/handler/clustering/carrot2/ contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/ core/src/java/org/apache/solr/ core/src/java/org/apac...

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/HashPartitioner.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/HashPartitioner.java?rev=1382621&r1=1382620&r2=1382621&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/HashPartitioner.java (original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/HashPartitioner.java Mon Sep 10 02:14:50 2012
@@ -17,23 +17,26 @@ package org.apache.solr.common.cloud;
  * limitations under the License.
  */
 
+import org.apache.noggit.JSONWriter;
+
 import java.util.ArrayList;
 import java.util.List;
 
 /**
  * Class to partition int range into n ranges.
- * 
+ *
  */
 public class HashPartitioner {
 
   // Hash ranges can't currently "wrap" - i.e. max must be greater or equal to min.
   // TODO: ranges may not be all contiguous in the future (either that or we will
   // need an extra class to model a collection of ranges)
-  public static class Range {
+  public static class Range implements JSONWriter.Writable {
     public int min;  // inclusive
     public int max;  // inclusive
-    
+
     public Range(int min, int max) {
+      assert min <= max;
       this.min = min;
       this.max = max;
     }
@@ -46,12 +49,39 @@ public class HashPartitioner {
       return Integer.toHexString(min) + '-' + Integer.toHexString(max);
     }
 
-    public static Range fromString(String range) {
-      return null; // TODO
+
+    @Override
+    public int hashCode() {
+      // difficult numbers to hash... only the highest bits will tend to differ.
+      // ranges will only overlap during a split, so we can just hash the lower range.
+      return (min>>28) + (min>>25) + (min>>21) + min;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+      if (obj.getClass() != getClass()) return false;
+      Range other = (Range)obj;
+      return this.min == other.min && this.max == other.max;
+    }
+
+    @Override
+    public void write(JSONWriter writer) {
+      writer.write(toString());
     }
   }
 
+  public Range fromString(String range) {
+    int middle = range.indexOf('-');
+    String minS = range.substring(0, middle);
+    String maxS = range.substring(middle+1);
+    long min = Long.parseLong(minS, 16);  // use long to prevent the parsing routines from potentially worrying about overflow
+    long max = Long.parseLong(maxS, 16);
+    return new Range((int)min, (int)max);
+  }
 
+  public Range fullRange() {
+    return new Range(Integer.MIN_VALUE, Integer.MAX_VALUE);
+  }
 
   public List<Range> partitionRange(int partitions, Range range) {
     return partitionRange(partitions, range.min, range.max);

Added: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/Replica.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/Replica.java?rev=1382621&view=auto
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/Replica.java (added)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/Replica.java Mon Sep 10 02:14:50 2012
@@ -0,0 +1,38 @@
+package org.apache.solr.common.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.util.Map;
+
+
+public class Replica extends ZkNodeProps {
+  private final String name;
+
+  public Replica(String name, Map<String,Object> propMap) {         // TODO: back compat for handling Map<String,String>
+    super(propMap);
+    this.name = name;
+    String nodeName = (String)propMap.get(ZkStateReader.NODE_NAME_PROP);
+    assert nodeName == null || name.startsWith(nodeName);
+  }
+
+  public String getName() {
+    return name;
+  }
+
+
+}

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.java?rev=1382621&r1=1382620&r2=1382621&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.java (original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.java Mon Sep 10 02:14:50 2012
@@ -19,46 +19,72 @@ package org.apache.solr.common.cloud;
 
 import org.apache.noggit.JSONWriter;
 
-import java.util.Collections;
+import java.util.Collection;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.Map;
 
 /**
- * A Slice contains immutable information about all shards that share the same
- * shard id (shard leader and replicas).
+ * A Slice contains immutable information about a logical shard (all replicas that share the same shard id).
  */
-public class Slice implements JSONWriter.Writable {
-  private final Map<String,ZkNodeProps> shards;
+public class Slice extends ZkNodeProps {
+  public static String REPLICAS = "replicas";
+  public static String RANGE = "range";
+  public static String LEADER = "leader";
+
   private final String name;
+  private final HashPartitioner.Range range;
+  // private final Integer replicationFactor;
+  private final Map<String,Replica> replicas;
+  private final Replica leader;
+
+  public Slice(String name, Map<String,Replica> replicas) {
+    this(name, replicas, null);
+  }
 
-  public Slice(String name, Map<String,ZkNodeProps> shards) {
-    this.shards = shards;
+  public Slice(String name, Map<String,Replica> replicas, Map<String,Object> props) {
+    super( props==null ? new LinkedHashMap<String,Object>(2) : new LinkedHashMap<String,Object>(props));
     this.name = name;
+    this.replicas = replicas != null ? replicas : makeReplicas((Map<String,Object>)propMap.get(REPLICAS));
+    propMap.put(REPLICAS, replicas);
+
+    String rangeStr = (String)propMap.get(RANGE);
+    HashPartitioner.Range tmpRange = null;
+    if (rangeStr != null) {
+      HashPartitioner hp = new HashPartitioner();
+      tmpRange = hp.fromString(rangeStr);
+    }
+
+    range = tmpRange;
+    // replicationFactor = null;  // future
+    leader = findLeader();
   }
-  
-  /**
-   * Get properties for all shards in this slice.
-   * 
-   * @return map containing coreNodeName as the key, see
-   *         {@link ZkStateReader#getCoreNodeName(String, String)}, ZKNodeProps
-   *         as the value.
-   */
-  public Map<String,ZkNodeProps> getShards() {
-    return Collections.unmodifiableMap(shards);
+
+
+  private Map<String,Replica> makeReplicas(Map<String,Object> genericReplicas) {
+    if (genericReplicas == null) return new HashMap<String,Replica>(1);
+    Map<String,Replica> result = new LinkedHashMap<String, Replica>(genericReplicas.size());
+    for (Map.Entry<String,Object> entry : genericReplicas.entrySet()) {
+      String name = entry.getKey();
+      Object val = entry.getValue();
+      Replica r;
+      if (val instanceof Replica) {
+        r = (Replica)val;
+      } else {
+        r = new Replica(name, (Map<String,Object>)val);
+      }
+      result.put(name, r);
+    }
+    return result;
   }
 
-  /**
-   * Get a copy of the shards data this object holds.
-   */
-  public Map<String,ZkNodeProps> getShardsCopy() {
-    Map<String,ZkNodeProps> shards = new HashMap<String,ZkNodeProps>();
-    for (Map.Entry<String,ZkNodeProps> entry : this.shards.entrySet()) {
-      ZkNodeProps zkProps = new ZkNodeProps(entry.getValue());
-      shards.put(entry.getKey(), zkProps);
+  private Replica findLeader() {
+    for (Replica replica : replicas.values()) {
+      if (replica.getStr(LEADER) != null) return replica;
     }
-    return shards;
+    return null;
   }
-  
+
   /**
    * Return slice name (shard id).
    */
@@ -66,13 +92,57 @@ public class Slice implements JSONWriter
     return name;
   }
 
+  /**
+   * Gets the list of replicas for this slice.
+   */
+  public Collection<Replica> getReplicas() {
+    return replicas.values();
+  }
+
+  /**
+   * Get the map of coreNodeName to replicas for this slice.
+   *
+   * @return map containing coreNodeName as the key, see
+   *         {@link ZkStateReader#getCoreNodeName(String, String)}, Replica
+   *         as the value.
+   */
+  public Map<String, Replica> getReplicasMap() {
+    return replicas;
+  }
+
+  public Map<String,Replica> getReplicasCopy() {
+    return new LinkedHashMap<String,Replica>(replicas);
+  }
+
+  public Replica getLeader() {
+    return leader;
+  }
+
+  /***
+  // returns a copy of this slice containing the new replica
+  public Slice addReplica(Replica replica) {
+    Map<String, Object> newProps = new LinkedHashMap<String,Object>(props);
+    Map<String, Replica> replicas = getReplicasMap();
+    Map<String, Replica> newReplicas = replicas == null ? new HashMap<String, Replica>(1) : new LinkedHashMap<String, Replica>(replicas);
+//    newReplicas.put(replica.getName(), replica);
+    newProps.put(REPLICAS, replicas);
+    return new Slice(name, newProps); // TODO: new constructor that takes replicas as-is w/o rebuilding
+  }
+
+  public static Slice newSlice(String name) {
+    Map<String, Object> props = new HashMap<String,Object>(1);
+    props.put("replicas", new HashMap<String,Object>(1));
+    return new Slice(name, props);
+  }
+   ***/
+
   @Override
   public String toString() {
-    return "Slice [shards=" + shards + ", name=" + name + "]";
+    return "Slice [replicas=" + replicas + ", name=" + name + "]";
   }
 
   @Override
   public void write(JSONWriter jsonWriter) {
-    jsonWriter.write(shards);
+    jsonWriter.write(replicas);
   }
 }

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCoreNodeProps.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCoreNodeProps.java?rev=1382621&r1=1382620&r2=1382621&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCoreNodeProps.java (original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkCoreNodeProps.java Mon Sep 10 02:14:50 2012
@@ -25,27 +25,27 @@ public class ZkCoreNodeProps {
   }
   
   public String getCoreUrl() {
-    return getCoreUrl(nodeProps.get(ZkStateReader.BASE_URL_PROP), nodeProps.get(ZkStateReader.CORE_NAME_PROP));
+    return getCoreUrl(nodeProps.getStr(ZkStateReader.BASE_URL_PROP), nodeProps.getStr(ZkStateReader.CORE_NAME_PROP));
   }
   
   public String getNodeName() {
-    return nodeProps.get(ZkStateReader.NODE_NAME_PROP);
+    return nodeProps.getStr(ZkStateReader.NODE_NAME_PROP);
   }
 
   public String getState() {
-    return nodeProps.get(ZkStateReader.STATE_PROP);
+    return nodeProps.getStr(ZkStateReader.STATE_PROP);
   }
 
   public String getBaseUrl() {
-    return nodeProps.get(ZkStateReader.BASE_URL_PROP);
+    return nodeProps.getStr(ZkStateReader.BASE_URL_PROP);
   }
   
   public String getCoreName() {
-    return nodeProps.get(ZkStateReader.CORE_NAME_PROP);
+    return nodeProps.getStr(ZkStateReader.CORE_NAME_PROP);
   }
   
   public static String getCoreUrl(ZkNodeProps nodeProps) {
-    return getCoreUrl(nodeProps.get(ZkStateReader.BASE_URL_PROP), nodeProps.get(ZkStateReader.CORE_NAME_PROP));
+    return getCoreUrl(nodeProps.getStr(ZkStateReader.BASE_URL_PROP), nodeProps.getStr(ZkStateReader.CORE_NAME_PROP));
   }
   
   public static String getCoreUrl(String baseUrl, String coreName) {

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkNodeProps.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkNodeProps.java?rev=1382621&r1=1382620&r2=1382621&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkNodeProps.java (original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkNodeProps.java Mon Sep 10 02:14:50 2012
@@ -17,51 +17,54 @@ package org.apache.solr.common.cloud;
  * limitations under the License.
  */
 
+import org.apache.noggit.JSONWriter;
+
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.Map;
-import java.util.Set;
 import java.util.Map.Entry;
-
-import org.apache.noggit.JSONWriter;
+import java.util.Set;
 
 /**
- * ZkNodeProps contains immutable properties for a shard/solr core.
+ * ZkNodeProps contains generic immutable properties.
  */
 public class ZkNodeProps implements JSONWriter.Writable {
 
-  private final Map<String,String> propMap;
+  protected final Map<String,Object> propMap;
 
   /**
    * Construct ZKNodeProps from map.
    */
-  public ZkNodeProps(Map<String,String> propMap) {
-    this.propMap = new HashMap<String,String>();
-    this.propMap.putAll(propMap);
+  public ZkNodeProps(Map<String,Object> propMap) {         // TODO: back compat for handling Map<String,String>
+    this.propMap = propMap;
   }
-  
-  /**
-   * Construct ZKNodeProps from information of an existingZKNodeProps.
-   */
-  public ZkNodeProps(ZkNodeProps zkNodeProps) {
-    this.propMap = new HashMap<String,String>();
-    this.propMap.putAll(zkNodeProps.propMap);
-  }
-  
+
+
   /**
    * Constructor that populates the from array of Strings in form key1, value1,
    * key2, value2, ..., keyN, valueN
    */
   public ZkNodeProps(String... keyVals) {
-    if (keyVals.length % 2 != 0) {
+    this( makeMap(keyVals) );
+  }
+
+  public static ZkNodeProps fromKeyVals(Object... keyVals)  {
+    return new ZkNodeProps( makeMap(keyVals) );
+  }
+
+  public static Map<String,Object> makeMap(Object... keyVals) {
+    if ((keyVals.length & 0x01) != 0) {
       throw new IllegalArgumentException("arguments should be key,value");
     }
-    propMap = new HashMap<String,String>();
+    Map<String,Object> propMap = new HashMap<String,Object>(keyVals.length>>1);
     for (int i = 0; i < keyVals.length; i+=2) {
-      propMap.put(keyVals[i], keyVals[i+1]);
+      propMap.put(keyVals[i].toString(), keyVals[i+1]);
     }
+    return propMap;
   }
- 
+
+
   /**
    * Get property keys.
    */
@@ -72,15 +75,20 @@ public class ZkNodeProps implements JSON
   /**
    * Get all properties as map.
    */
-  public Map<String,String> getProperties() {
+  public Map<String, Object> getProperties() {
     return Collections.unmodifiableMap(propMap);
   }
 
+  /** Returns a shallow writable copy of the properties */
+  public Map<String,Object> shallowCopy() {
+    return new LinkedHashMap<String, Object>(propMap);
+  }
+
   /**
-   * Create ZkNodeProps from json string that is typically stored in zookeeper.
+   * Create Replica from json string that is typically stored in zookeeper.
    */
   public static ZkNodeProps load(byte[] bytes) {
-    Map<String, String> props = (Map<String, String>) ZkStateReader.fromJSON(bytes);
+    Map<String, Object> props = (Map<String, Object>) ZkStateReader.fromJSON(bytes);
     return new ZkNodeProps(props);
   }
 
@@ -90,17 +98,22 @@ public class ZkNodeProps implements JSON
   }
   
   /**
-   * Get property value.
+   * Get a string property value.
    */
-  public String get(String key) {
+  public String getStr(String key) {
+    Object o = propMap.get(key);
+    return o == null ? null : o.toString();
+  }
+
+  public Object get(String key,int foo) {
     return propMap.get(key);
   }
   
   @Override
   public String toString() {
     StringBuilder sb = new StringBuilder();
-    Set<Entry<String,String>> entries = propMap.entrySet();
-    for(Entry<String,String> entry : entries) {
+    Set<Entry<String,Object>> entries = propMap.entrySet();
+    for(Entry<String,Object> entry : entries) {
       sb.append(entry.getKey() + "=" + entry.getValue() + "\n");
     }
     return sb.toString();

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java?rev=1382621&r1=1382620&r2=1382621&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java (original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java Mon Sep 10 02:14:50 2012
@@ -458,10 +458,10 @@ public class ZkStateReader {
       throw new ZooKeeperException(ErrorCode.BAD_REQUEST, "Could not find shardId in zk: " + shardId);
     }
     
-    Map<String,ZkNodeProps> shardMap = replicas.getShards();
+    Map<String,Replica> shardMap = replicas.getReplicasMap();
     List<ZkCoreNodeProps> nodes = new ArrayList<ZkCoreNodeProps>(shardMap.size());
     String filterNodeName = thisNodeName + "_" + coreName;
-    for (Entry<String,ZkNodeProps> entry : shardMap.entrySet()) {
+    for (Entry<String,Replica> entry : shardMap.entrySet()) {
       ZkCoreNodeProps nodeProps = new ZkCoreNodeProps(entry.getValue());
       String coreNodeName = nodeProps.getNodeName() + "_" + nodeProps.getCoreName();
       if (clusterState.liveNodesContain(nodeProps.getNodeName()) && !coreNodeName.equals(filterNodeName)) {

Modified: lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java?rev=1382621&r1=1382620&r2=1382621&view=diff
==============================================================================
--- lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java (original)
+++ lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java Mon Sep 10 02:14:50 2012
@@ -24,11 +24,10 @@ import java.util.concurrent.atomic.Atomi
 import org.apache.commons.io.FileUtils;
 import org.apache.solr.BaseDistributedSearchTestCase;
 import org.apache.solr.client.solrj.embedded.JettySolrRunner;
-import org.apache.solr.cloud.ZkTestServer;
 import org.apache.solr.common.cloud.ClusterState;
+import org.apache.solr.common.cloud.Replica;
 import org.apache.solr.common.cloud.Slice;
 import org.apache.solr.common.cloud.SolrZkClient;
-import org.apache.solr.common.cloud.ZkNodeProps;
 import org.apache.solr.common.cloud.ZkStateReader;
 import org.apache.solr.servlet.SolrDispatchFilter;
 import org.apache.zookeeper.KeeperException;
@@ -130,18 +129,18 @@ public abstract class AbstractDistribZkT
       ClusterState clusterState = zkStateReader.getClusterState();
       Map<String,Slice> slices = clusterState.getSlices(collection);
       for (Map.Entry<String,Slice> entry : slices.entrySet()) {
-        Map<String,ZkNodeProps> shards = entry.getValue().getShards();
-        for (Map.Entry<String,ZkNodeProps> shard : shards.entrySet()) {
+        Map<String,Replica> shards = entry.getValue().getReplicasMap();
+        for (Map.Entry<String,Replica> shard : shards.entrySet()) {
           if (verbose) System.out.println("rstate:"
-              + shard.getValue().get(ZkStateReader.STATE_PROP)
+              + shard.getValue().getStr(ZkStateReader.STATE_PROP)
               + " live:"
-              + clusterState.liveNodesContain(shard.getValue().get(
-                  ZkStateReader.NODE_NAME_PROP)));
-          String state = shard.getValue().get(ZkStateReader.STATE_PROP);
+              + clusterState.liveNodesContain(shard.getValue().getStr(
+              ZkStateReader.NODE_NAME_PROP)));
+          String state = shard.getValue().getStr(ZkStateReader.STATE_PROP);
           if ((state.equals(ZkStateReader.RECOVERING) || state
               .equals(ZkStateReader.SYNC) || state.equals(ZkStateReader.DOWN))
-              && clusterState.liveNodesContain(shard.getValue().get(
-                  ZkStateReader.NODE_NAME_PROP))) {
+              && clusterState.liveNodesContain(shard.getValue().getStr(
+              ZkStateReader.NODE_NAME_PROP))) {
             sawLiveRecovering = true;
           }
         }
@@ -176,10 +175,10 @@ public abstract class AbstractDistribZkT
         throw new IllegalArgumentException("Cannot find collection:" + collection);
       }
       for (Map.Entry<String,Slice> entry : slices.entrySet()) {
-        Map<String,ZkNodeProps> shards = entry.getValue().getShards();
-        for (Map.Entry<String,ZkNodeProps> shard : shards.entrySet()) {
+        Map<String,Replica> shards = entry.getValue().getReplicasMap();
+        for (Map.Entry<String,Replica> shard : shards.entrySet()) {
 
-          String state = shard.getValue().get(ZkStateReader.STATE_PROP);
+          String state = shard.getValue().getStr(ZkStateReader.STATE_PROP);
           if (!state.equals(ZkStateReader.ACTIVE)) {
             fail("Not all shards are ACTIVE - found a shard that is: " + state);
           }

Modified: lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java?rev=1382621&r1=1382620&r2=1382621&view=diff
==============================================================================
--- lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java (original)
+++ lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/cloud/AbstractFullDistribZkTestBase.java Mon Sep 10 02:14:50 2012
@@ -45,6 +45,7 @@ import org.apache.solr.common.SolrDocume
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.SolrInputDocument;
 import org.apache.solr.common.cloud.ClusterState;
+import org.apache.solr.common.cloud.Replica;
 import org.apache.solr.common.cloud.Slice;
 import org.apache.solr.common.cloud.ZkCoreNodeProps;
 import org.apache.solr.common.cloud.ZkNodeProps;
@@ -340,7 +341,7 @@ public abstract class AbstractFullDistri
     Map<String,Slice> slices = this.zkStateReader.getClusterState().getSlices(defaultCollection);
     int cnt = 0;
     for (Map.Entry<String,Slice> entry : slices.entrySet()) {
-      cnt += entry.getValue().getShards().size();
+      cnt += entry.getValue().getReplicasMap().size();
     }
     
     return cnt;
@@ -378,8 +379,8 @@ public abstract class AbstractFullDistri
       nextClient:
       // we find ou state by simply matching ports...
       for (Map.Entry<String,Slice> slice : slices.entrySet()) {
-        Map<String,ZkNodeProps> theShards = slice.getValue().getShards();
-        for (Map.Entry<String,ZkNodeProps> shard : theShards.entrySet()) {
+        Map<String,Replica> theShards = slice.getValue().getReplicasMap();
+        for (Map.Entry<String,Replica> shard : theShards.entrySet()) {
           int port = new URI(((HttpSolrServer) client).getBaseURL())
               .getPort();
           
@@ -387,7 +388,7 @@ public abstract class AbstractFullDistri
             CloudSolrServerClient csc = new CloudSolrServerClient();
             csc.solrClient = client;
             csc.port = port;
-            csc.shardName = shard.getValue().get(ZkStateReader.NODE_NAME_PROP);
+            csc.shardName = shard.getValue().getStr(ZkStateReader.NODE_NAME_PROP);
             csc.info = shard.getValue();
             
             theClients .add(csc);
@@ -406,8 +407,8 @@ public abstract class AbstractFullDistri
       
       nextJetty:
       for (Map.Entry<String,Slice> slice : slices.entrySet()) {
-        Map<String,ZkNodeProps> theShards = slice.getValue().getShards();
-        for (Map.Entry<String,ZkNodeProps> shard : theShards.entrySet()) {
+        Map<String,Replica> theShards = slice.getValue().getReplicasMap();
+        for (Map.Entry<String,Replica> shard : theShards.entrySet()) {
           if (shard.getKey().contains(":" + port + "_")) {
             List<CloudJettyRunner> list = shardToJetty.get(slice.getKey());
             if (list == null) {
@@ -419,9 +420,9 @@ public abstract class AbstractFullDistri
             CloudJettyRunner cjr = new CloudJettyRunner();
             cjr.jetty = jetty;
             cjr.info = shard.getValue();
-            cjr.nodeName = shard.getValue().get(ZkStateReader.NODE_NAME_PROP);
+            cjr.nodeName = shard.getValue().getStr(ZkStateReader.NODE_NAME_PROP);
             cjr.coreNodeName = shard.getKey();
-            cjr.url = shard.getValue().get(ZkStateReader.BASE_URL_PROP) + "/" + shard.getValue().get(ZkStateReader.CORE_NAME_PROP);
+            cjr.url = shard.getValue().getStr(ZkStateReader.BASE_URL_PROP) + "/" + shard.getValue().getStr(ZkStateReader.CORE_NAME_PROP);
             cjr.client = findClientByPort(port, theClients);
             list.add(cjr);
             if (isLeader) {
@@ -442,7 +443,7 @@ public abstract class AbstractFullDistri
       List<CloudJettyRunner> jetties = shardToJetty.get(slice.getKey());
       assertNotNull("Test setup problem: We found no jetties for shard: " + slice.getKey()
           + " just:" + shardToJetty.keySet(), jetties);
-      assertEquals(slice.getValue().getShards().size(), jetties.size());
+      assertEquals(slice.getValue().getReplicasMap().size(), jetties.size());
     }
   }
   
@@ -752,7 +753,7 @@ public abstract class AbstractFullDistri
         "The client count does not match up with the shard count for slice:"
             + shard,
         zkStateReader.getClusterState().getSlice(DEFAULT_COLLECTION, shard)
-            .getShards().size(), solrJetties.size());
+            .getReplicasMap().size(), solrJetties.size());
 
     CloudJettyRunner lastJetty = null;
     for (CloudJettyRunner cjetty : solrJetties) {
@@ -775,7 +776,7 @@ public abstract class AbstractFullDistri
       }
       
       boolean live = false;
-      String nodeName = props.get(ZkStateReader.NODE_NAME_PROP);
+      String nodeName = props.getStr(ZkStateReader.NODE_NAME_PROP);
       if (zkStateReader.getClusterState().liveNodesContain(nodeName)) {
         live = true;
       }
@@ -783,7 +784,7 @@ public abstract class AbstractFullDistri
       
       if (verbose) System.err.println(" num:" + num + "\n");
       
-      boolean active = props.get(ZkStateReader.STATE_PROP).equals(
+      boolean active = props.getStr(ZkStateReader.STATE_PROP).equals(
           ZkStateReader.ACTIVE);
       if (active && live) {
         if (lastNum > -1 && lastNum != num && failMessage == null) {
@@ -877,7 +878,7 @@ public abstract class AbstractFullDistri
             CloudJettyRunner cjetty = shardToJetty.get(s).get(i);
             ZkNodeProps props = cjetty.info;
             SolrServer client = cjetty.client.solrClient;
-            boolean active = props.get(ZkStateReader.STATE_PROP).equals(
+            boolean active = props.getStr(ZkStateReader.STATE_PROP).equals(
                 ZkStateReader.ACTIVE);
             if (active) {
               SolrQuery query = new SolrQuery("*:*");
@@ -886,7 +887,7 @@ public abstract class AbstractFullDistri
               if (verbose) System.err.println(new ZkCoreNodeProps(props)
                   .getCoreUrl() + " : " + results);
               if (verbose) System.err.println("shard:"
-                  + props.get(ZkStateReader.SHARD_ID_PROP));
+                  + props.getStr(ZkStateReader.SHARD_ID_PROP));
               cnt += results;
               break;
             }
@@ -948,8 +949,8 @@ public abstract class AbstractFullDistri
     for (CloudJettyRunner cjetty : cloudJettys) {
       CloudSolrServerClient client = cjetty.client;
       for (Map.Entry<String,Slice> slice : slices.entrySet()) {
-        Map<String,ZkNodeProps> theShards = slice.getValue().getShards();
-        for (Map.Entry<String,ZkNodeProps> shard : theShards.entrySet()) {
+        Map<String,Replica> theShards = slice.getValue().getReplicasMap();
+        for (Map.Entry<String,Replica> shard : theShards.entrySet()) {
           String shardName = new URI(
               ((HttpSolrServer) client.solrClient).getBaseURL()).getPort()
               + "_solr_";
@@ -961,11 +962,11 @@ public abstract class AbstractFullDistri
       }
       
       long count = 0;
-      String currentState = cjetty.info.get(ZkStateReader.STATE_PROP);
+      String currentState = cjetty.info.getStr(ZkStateReader.STATE_PROP);
       if (currentState != null
           && currentState.equals(ZkStateReader.ACTIVE)
           && zkStateReader.getClusterState().liveNodesContain(
-              cjetty.info.get(ZkStateReader.NODE_NAME_PROP))) {
+              cjetty.info.getStr(ZkStateReader.NODE_NAME_PROP))) {
         SolrQuery query = new SolrQuery("*:*");
         query.set("distrib", false);
         count = client.solrClient.query(query).getResults().getNumFound();
@@ -1209,7 +1210,7 @@ public abstract class AbstractFullDistri
       CloudJettyRunner cjetty) throws InterruptedException {
     int tries = 0;
     while (zkStateReader.getClusterState()
-        .liveNodesContain(cjetty.info.get(ZkStateReader.NODE_NAME_PROP))) {
+        .liveNodesContain(cjetty.info.getStr(ZkStateReader.NODE_NAME_PROP))) {
       if (tries++ == 120) {
         fail("Shard still reported as live in zk");
       }

Modified: lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/cloud/AbstractZkTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/cloud/AbstractZkTestCase.java?rev=1382621&r1=1382620&r2=1382621&view=diff
==============================================================================
--- lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/cloud/AbstractZkTestCase.java (original)
+++ lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/cloud/AbstractZkTestCase.java Mon Sep 10 02:14:50 2012
@@ -93,7 +93,7 @@ public abstract class AbstractZkTestCase
 
     zkClient = new SolrZkClient(zkAddress, AbstractZkTestCase.TIMEOUT);
 
-    Map<String,String> props = new HashMap<String,String>();
+    Map<String,Object> props = new HashMap<String,Object>();
     props.put("configName", "conf1");
     final ZkNodeProps zkProps = new ZkNodeProps(props);
     

Modified: lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java?rev=1382621&r1=1382620&r2=1382621&view=diff
==============================================================================
--- lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java (original)
+++ lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/cloud/ChaosMonkey.java Mon Sep 10 02:14:50 2012
@@ -259,13 +259,13 @@ public class ChaosMonkey {
       Slice theShards = zkStateReader.getClusterState().getSlices(collection)
           .get(slice);
       
-      ZkNodeProps props = theShards.getShards().get(cloudJetty.coreNodeName);
+      ZkNodeProps props = theShards.getReplicasMap().get(cloudJetty.coreNodeName);
       if (props == null) {
-        throw new RuntimeException("shard name " + cloudJetty.coreNodeName + " not found in " + theShards.getShards().keySet());
+        throw new RuntimeException("shard name " + cloudJetty.coreNodeName + " not found in " + theShards.getReplicasMap().keySet());
       }
       
-      String state = props.get(ZkStateReader.STATE_PROP);
-      String nodeName = props.get(ZkStateReader.NODE_NAME_PROP);
+      String state = props.getStr(ZkStateReader.STATE_PROP);
+      String nodeName = props.getStr(ZkStateReader.NODE_NAME_PROP);
       
       
       if (!cloudJetty.jetty.isRunning()
@@ -309,7 +309,7 @@ public class ChaosMonkey {
       cjetty = jetties.get(index);
       
       ZkNodeProps leader = zkStateReader.getLeaderProps(collection, slice);
-      boolean isLeader = leader.get(ZkStateReader.NODE_NAME_PROP).equals(jetties.get(index).nodeName);
+      boolean isLeader = leader.getStr(ZkStateReader.NODE_NAME_PROP).equals(jetties.get(index).nodeName);
       if (!aggressivelyKillLeaders && isLeader) {
         // we don't kill leaders...
         monkeyLog("abort! I don't kill leaders");