Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-6554: Add a ClusterState.copyWith method which accepts a collection directly instead of a map of collections and use it throughout

Shalin Shekhar Mangar83299a07e3af
diff --git a/solr/core/src/java/org/apache/solr/cloud/Overseer.java b/solr/core/src/java/org/apache/solr/cloud/Overseer.java
index bf10dc717ce..17391a77d21 100644
--- a/solr/core/src/java/org/apache/solr/cloud/Overseer.java
+++ b/solr/core/src/java/org/apache/solr/cloud/Overseer.java
@@ -98,10 +98,6 @@ public class Overseer implements Closeable {
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 Closeable {
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 Closeable {
} else {
isClusterStateModified = true;
}
- state = state.copyWith(singletonMap(e.getKey(), c));
+ state = state.copyWith(e.getKey(), c);
}
return state;
diff --git a/solr/core/src/java/org/apache/solr/cloud/overseer/ClusterStateMutator.java b/solr/core/src/java/org/apache/solr/cloud/overseer/ClusterStateMutator.java
index 9885817da2c..0e363025010 100644
--- a/solr/core/src/java/org/apache/solr/cloud/overseer/ClusterStateMutator.java
+++ b/solr/core/src/java/org/apache/solr/cloud/overseer/ClusterStateMutator.java
@@ -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;
}
diff --git a/solr/core/src/java/org/apache/solr/cloud/overseer/ZkStateWriter.java b/solr/core/src/java/org/apache/solr/cloud/overseer/ZkStateWriter.java
index aa61535342b..369c6158407 100644
--- a/solr/core/src/java/org/apache/solr/cloud/overseer/ZkStateWriter.java
+++ b/solr/core/src/java/org/apache/solr/cloud/overseer/ZkStateWriter.java
@@ -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) {
diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
index 3a21738ab28..be18d65043c 100644
--- a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
@@ -84,15 +84,19 @@ public class ClusterState implements JSONWriter.Writable {
}
- 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;
}
diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
index d654239af5e..b9005f644b9 100644
--- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
@@ -873,8 +873,7 @@ public class ZkStateReader implements Closeable {
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 */