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 2014/11/29 20:24:59 UTC
svn commit: r1642466 - in /lucene/dev/trunk/solr:
core/src/java/org/apache/solr/cloud/
core/src/java/org/apache/solr/cloud/overseer/
solrj/src/java/org/apache/solr/common/cloud/
Author: shalin
Date: Sat Nov 29 19:24:58 2014
New Revision: 1642466
URL: http://svn.apache.org/r1642466
Log:
SOLR-6554: Add a ClusterState.copyWith method which accepts a collection directly instead of a map of collections and use it throughout
Modified:
lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/Overseer.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/overseer/ClusterStateMutator.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/overseer/ZkStateWriter.java
lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/Overseer.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/Overseer.java?rev=1642466&r1=1642465&r2=1642466&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/Overseer.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/Overseer.java Sat Nov 29 19:24:58 2014
@@ -98,10 +98,6 @@ public class Overseer implements Closeab
static enum LeaderStatus {DONT_KNOW, NO, YES}
- public static final String preferredLeaderProp = COLL_PROP_PREFIX + "preferredleader";
-
- public static final Set<String> sliceUniqueBooleanProperties = ImmutableSet.of(preferredLeaderProp);
-
private long lastUpdatedTime = 0;
private class ClusterStateUpdater implements Runnable, Closeable {
@@ -593,7 +589,7 @@ public class Overseer implements Closeab
DocCollection c = e.getValue();
if (c == null) {
isClusterStateModified = true;
- state = state.copyWith(singletonMap(e.getKey(), (DocCollection) null));
+ state = state.copyWith(e.getKey(), null);
updateNodes.put(ZkStateReader.getCollectionPath(e.getKey()) ,null);
continue;
}
@@ -604,7 +600,7 @@ public class Overseer implements Closeab
} else {
isClusterStateModified = true;
}
- state = state.copyWith(singletonMap(e.getKey(), c));
+ state = state.copyWith(e.getKey(), c);
}
return state;
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/overseer/ClusterStateMutator.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/overseer/ClusterStateMutator.java?rev=1642466&r1=1642465&r2=1642466&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/overseer/ClusterStateMutator.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/overseer/ClusterStateMutator.java Sat Nov 29 19:24:58 2014
@@ -121,9 +121,9 @@ public class ClusterStateMutator {
public static ClusterState newState(ClusterState state, String name, DocCollection collection) {
ClusterState newClusterState = null;
if (collection == null) {
- newClusterState = state.copyWith(singletonMap(name, (DocCollection) null));
+ newClusterState = state.copyWith(name, (DocCollection) null);
} else {
- newClusterState = state.copyWith(singletonMap(name, collection));
+ newClusterState = state.copyWith(name, collection);
}
return newClusterState;
}
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/overseer/ZkStateWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/overseer/ZkStateWriter.java?rev=1642466&r1=1642465&r2=1642466&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/overseer/ZkStateWriter.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/overseer/ZkStateWriter.java Sat Nov 29 19:24:58 2014
@@ -59,7 +59,7 @@ public class ZkStateWriter {
if (cmd.collection == null) {
isClusterStateModified = true;
- clusterState = prevState.copyWith(singletonMap(cmd.name, (DocCollection) null));
+ clusterState = prevState.copyWith(cmd.name, (DocCollection) null);
updates.put(cmd.name, null);
} else {
if (cmd.collection.getStateFormat() > 1) {
@@ -67,7 +67,7 @@ public class ZkStateWriter {
} else {
isClusterStateModified = true;
}
- clusterState = prevState.copyWith(singletonMap(cmd.name, cmd.collection));
+ clusterState = prevState.copyWith(cmd.name, cmd.collection);
}
return clusterState;
}
@@ -97,12 +97,12 @@ public class ZkStateWriter {
log.info("going to update_collection {}", path);
Stat stat = reader.getZkClient().setData(path, data, c.getZNodeVersion(), true);
DocCollection newCollection = new DocCollection(name, c.getSlicesMap(), c.getProperties(), c.getRouter(), stat.getVersion(), path);
- clusterState = clusterState.copyWith(singletonMap(name, newCollection));
+ clusterState = clusterState.copyWith(name, newCollection);
} else {
log.info("going to create_collection {}", path);
reader.getZkClient().create(path, data, CreateMode.PERSISTENT, true);
DocCollection newCollection = new DocCollection(name, c.getSlicesMap(), c.getProperties(), c.getRouter(), 0, path);
- clusterState = clusterState.copyWith(singletonMap(name, newCollection));
+ clusterState = clusterState.copyWith(name, newCollection);
isClusterStateModified = true;
}
} else if (c.getStateFormat() == 1) {
Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java?rev=1642466&r1=1642465&r2=1642466&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java (original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java Sat Nov 29 19:24:58 2014
@@ -84,15 +84,19 @@ public class ClusterState implements JSO
}
- public ClusterState copyWith(Map<String,DocCollection> modified){
+ /**
+ * Returns a new cluster state object modified with the given collection.
+ *
+ * @param collectionName the name of the modified (or deleted) collection
+ * @param collection the collection object. A null value deletes the collection from the state
+ * @return the updated cluster state which preserves the current live nodes and zk node version
+ */
+ public ClusterState copyWith(String collectionName, DocCollection collection) {
ClusterState result = new ClusterState(liveNodes, new LinkedHashMap<>(collectionStates), znodeVersion);
- for (Entry<String, DocCollection> e : modified.entrySet()) {
- DocCollection c = e.getValue();
- if(c == null) {
- result.collectionStates.remove(e.getKey());
- continue;
- }
- result.collectionStates.put(c.getName(), new CollectionRef(c));
+ if (collection == null) {
+ result.collectionStates.remove(collectionName);
+ } else {
+ result.collectionStates.put(collectionName, new CollectionRef(collection));
}
return result;
}
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=1642466&r1=1642465&r2=1642466&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 Sat Nov 29 19:24:58 2014
@@ -873,8 +873,7 @@ public class ZkStateReader implements Cl
log.info("Updating data for {} to ver {} ", newState.getName(),
newState.getZNodeVersion());
- this.clusterState = clusterState.copyWith(Collections.singletonMap(
- newState.getName(), newState));
+ this.clusterState = clusterState.copyWith(newState.getName(), newState);
}
/** This is not a public API. Only used by ZkController */