You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2013/02/18 16:45:18 UTC

svn commit: r1447339 - in /lucene/dev/branches/branch_4x: ./ solr/ solr/core/ solr/core/src/test/org/apache/solr/cloud/ solr/solrj/ solr/solrj/src/java/org/apache/solr/common/cloud/

Author: shalin
Date: Mon Feb 18 15:45:17 2013
New Revision: 1447339

URL: http://svn.apache.org/r1447339
Log:
SOLR-4414: Add 'state' to shards (default to 'active') and read/write them to ZooKeeper

Added:
    lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/cloud/SliceStateTest.java
      - copied unchanged from r1447336, lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/SliceStateTest.java
    lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/cloud/SliceStateUpdateTest.java
      - copied unchanged from r1447336, lucene/dev/trunk/solr/core/src/test/org/apache/solr/cloud/SliceStateUpdateTest.java
Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/solr/   (props changed)
    lucene/dev/branches/branch_4x/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_4x/solr/core/   (props changed)
    lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/cloud/ClusterStateUpdateTest.java
    lucene/dev/branches/branch_4x/solr/solrj/   (props changed)
    lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
    lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/cloud/DocCollection.java
    lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.java

Modified: lucene/dev/branches/branch_4x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/CHANGES.txt?rev=1447339&r1=1447338&r2=1447339&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/solr/CHANGES.txt Mon Feb 18 15:45:17 2013
@@ -154,6 +154,9 @@ Other Changes
 
 * SOLR-4384: Make post.jar report timing information (Upayavira via janhoy)
 
+* SOLR-4414: Add 'state' to shards (default to 'active') and read/write them to
+  ZooKeeper (Anshum Gupta via shalin)
+
 ==================  4.1.0 ==================
 
 Versions of Major Components

Modified: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/cloud/ClusterStateUpdateTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/cloud/ClusterStateUpdateTest.java?rev=1447339&r1=1447338&r2=1447339&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/cloud/ClusterStateUpdateTest.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/cloud/ClusterStateUpdateTest.java Mon Feb 18 15:45:17 2013
@@ -254,7 +254,7 @@ public class ClusterStateUpdateTest exte
     System.clearProperty("solrcloud.update.delay");
   }
   
-  private void printLayout(String zkHost) throws Exception {
+  static void printLayout(String zkHost) throws Exception {
     SolrZkClient zkClient = new SolrZkClient(
         zkHost, AbstractZkTestCase.TIMEOUT);
     zkClient.printLayoutToStdOut();

Modified: lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java?rev=1447339&r1=1447338&r2=1447339&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java Mon Feb 18 15:45:17 2013
@@ -117,6 +117,12 @@ public class ClusterState implements JSO
     if (coll == null) return null;
     return coll.getSlicesMap();
   }
+  
+  public Map<String, Slice> getAllSlicesMap(String collection) {
+    DocCollection coll = collectionStates.get(collection);
+    if (coll == null) return null;
+    return coll.getAllSlicesMap();
+  }
 
   public Collection<Slice> getSlices(String collection) {
     DocCollection coll = collectionStates.get(collection);

Modified: lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/cloud/DocCollection.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/cloud/DocCollection.java?rev=1447339&r1=1447338&r2=1447339&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/cloud/DocCollection.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/cloud/DocCollection.java Mon Feb 18 15:45:17 2013
@@ -23,6 +23,7 @@ import org.apache.noggit.JSONWriter;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.Map;
 
@@ -35,6 +36,7 @@ public class DocCollection extends ZkNod
 
   private final String name;
   private final Map<String, Slice> slices;
+  private final Map<String, Slice> allSlices;
   private final DocRouter router;
 
   /**
@@ -45,7 +47,17 @@ public class DocCollection extends ZkNod
   public DocCollection(String name, Map<String, Slice> slices, Map<String, Object> props, DocRouter router) {
     super( props==null ? Collections.<String,Object>emptyMap() : props);
     this.name = name;
-    this.slices = slices;
+
+    this.allSlices = slices;
+    this.slices = new HashMap<String, Slice>();
+
+    Iterator<Map.Entry<String, Slice>> iter = slices.entrySet().iterator();
+
+    while (iter.hasNext()) {
+      Map.Entry<String, Slice> slice = iter.next();
+      if (slice.getValue().getState().equals(Slice.ACTIVE))
+        this.slices.put(slice.getKey(), slice.getValue());
+    }
     this.router = router;
 
     assert name != null && slices != null;
@@ -60,23 +72,38 @@ public class DocCollection extends ZkNod
   }
 
   public Slice getSlice(String sliceName) {
-    return slices.get(sliceName);
+    return allSlices.get(sliceName);
   }
 
   /**
-   * Gets the list of slices for this collection.
+   * Gets the list of active slices for this collection.
    */
   public Collection<Slice> getSlices() {
     return slices.values();
   }
 
+
+  /**
+   * Return the list of all slices for this collection.
+   */
+  public Collection<Slice> getAllSlices() {
+    return allSlices.values();
+  }
+
   /**
-   * Get the map of slices (sliceName->Slice) for this collection.
+   * Get the map of active slices (sliceName->Slice) for this collection.
    */
   public Map<String, Slice> getSlicesMap() {
     return slices;
   }
 
+  /**
+   * Get the map of all slices (sliceName->Slice) for this collection.
+   */
+  public Map<String, Slice> getAllSlicesMap() {
+    return allSlices;
+  }
+
   public DocRouter getRouter() {
     return router;
   }
@@ -88,9 +115,9 @@ public class DocCollection extends ZkNod
 
   @Override
   public void write(JSONWriter jsonWriter) {
-    LinkedHashMap<String,Object> all = new LinkedHashMap<String,Object>(slices.size()+1);
+    LinkedHashMap<String, Object> all = new LinkedHashMap<String, Object>(allSlices.size() + 1);
     all.putAll(propMap);
-    all.put(SHARDS, slices);
+    all.put(SHARDS, allSlices);
     jsonWriter.write(all);
   }
 }

Modified: lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.java?rev=1447339&r1=1447338&r2=1447339&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/cloud/Slice.java Mon Feb 18 15:45:17 2013
@@ -31,13 +31,16 @@ import java.util.Map;
 public class Slice extends ZkNodeProps {
   public static String REPLICAS = "replicas";
   public static String RANGE = "range";
+  public static String STATE = "state";
   public static String LEADER = "leader";       // FUTURE: do we want to record the leader as a slice property in the JSON (as opposed to isLeader as a replica property?)
+  public static String ACTIVE = "active";
 
   private final String name;
   private final DocRouter.Range range;
   private final Integer replicationFactor;      // FUTURE: optional per-slice override of the collection replicationFactor
   private final Map<String,Replica> replicas;
   private final Replica leader;
+  private final String state;
 
   /**
    * @param name  The name of the slice
@@ -49,6 +52,12 @@ public class Slice extends ZkNodeProps {
     this.name = name;
 
     Object rangeObj = propMap.get(RANGE);
+    if (propMap.containsKey(STATE))
+      state = (String) propMap.get(STATE);
+    else {
+      state = ACTIVE;                         //Default to ACTIVE
+      propMap.put(STATE, this.state);
+    }
     DocRouter.Range tmpRange = null;
     if (rangeObj instanceof DocRouter.Range) {
       tmpRange = (DocRouter.Range)rangeObj;
@@ -135,6 +144,10 @@ public class Slice extends ZkNodeProps {
     return range;
   }
 
+  public String getState() {
+    return state;
+  }
+
   @Override
   public String toString() {
     return name + ':' + JSONUtil.toJSON(propMap);