mirror of https://github.com/apache/lucene.git
SOLR-6554: Add a ClusterState.copyWith method which accepts a collection directly instead of a map of collections and use it throughout
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1642466 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
150cd9abb6
commit
83299a07e3
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in New Issue