mirror of https://github.com/apache/lucene.git
SOLR-4553: Bug in finding remote node when proxying update request in a cluster with more than one collection.
Also, attempt to proxy requests more aggressively. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1545065 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fc7a21deea
commit
c95f5900ac
|
@ -574,13 +574,14 @@ public class SolrDispatchFilter implements Filter
|
||||||
ClusterState clusterState = cores.getZkController().getClusterState();
|
ClusterState clusterState = cores.getZkController().getClusterState();
|
||||||
Collection<Slice> slices = clusterState.getActiveSlices(collectionName);
|
Collection<Slice> slices = clusterState.getActiveSlices(collectionName);
|
||||||
boolean byCoreName = false;
|
boolean byCoreName = false;
|
||||||
|
|
||||||
if (slices == null) {
|
if (slices == null) {
|
||||||
|
slices = new ArrayList<Slice>();
|
||||||
// look by core name
|
// look by core name
|
||||||
byCoreName = true;
|
byCoreName = true;
|
||||||
Set<String> collections = clusterState.getCollections();
|
slices = getSlicesForCollections(clusterState, slices, true);
|
||||||
for (String collection : collections) {
|
if (slices == null || slices.size() == 0) {
|
||||||
slices = new ArrayList<Slice>();
|
slices = getSlicesForCollections(clusterState, slices, false);
|
||||||
slices.addAll(clusterState.getSlices(collection));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -588,6 +589,21 @@ public class SolrDispatchFilter implements Filter
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String coreUrl = getCoreUrl(cores, collectionName, origCorename, clusterState,
|
||||||
|
slices, byCoreName, true);
|
||||||
|
|
||||||
|
if (coreUrl == null) {
|
||||||
|
coreUrl = getCoreUrl(cores, collectionName, origCorename, clusterState,
|
||||||
|
slices, byCoreName, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return coreUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getCoreUrl(CoreContainer cores, String collectionName,
|
||||||
|
String origCorename, ClusterState clusterState, Collection<Slice> slices,
|
||||||
|
boolean byCoreName, boolean activeReplicas) {
|
||||||
|
String coreUrl;
|
||||||
Set<String> liveNodes = clusterState.getLiveNodes();
|
Set<String> liveNodes = clusterState.getLiveNodes();
|
||||||
Iterator<Slice> it = slices.iterator();
|
Iterator<Slice> it = slices.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
|
@ -595,8 +611,9 @@ public class SolrDispatchFilter implements Filter
|
||||||
Map<String,Replica> sliceShards = slice.getReplicasMap();
|
Map<String,Replica> sliceShards = slice.getReplicasMap();
|
||||||
for (ZkNodeProps nodeProps : sliceShards.values()) {
|
for (ZkNodeProps nodeProps : sliceShards.values()) {
|
||||||
ZkCoreNodeProps coreNodeProps = new ZkCoreNodeProps(nodeProps);
|
ZkCoreNodeProps coreNodeProps = new ZkCoreNodeProps(nodeProps);
|
||||||
if (liveNodes.contains(coreNodeProps.getNodeName())
|
if (!activeReplicas || (liveNodes.contains(coreNodeProps.getNodeName())
|
||||||
&& coreNodeProps.getState().equals(ZkStateReader.ACTIVE)) {
|
&& coreNodeProps.getState().equals(ZkStateReader.ACTIVE))) {
|
||||||
|
|
||||||
if (byCoreName && !collectionName.equals(coreNodeProps.getCoreName())) {
|
if (byCoreName && !collectionName.equals(coreNodeProps.getCoreName())) {
|
||||||
// if it's by core name, make sure they match
|
// if it's by core name, make sure they match
|
||||||
continue;
|
continue;
|
||||||
|
@ -605,7 +622,7 @@ public class SolrDispatchFilter implements Filter
|
||||||
// don't count a local core
|
// don't count a local core
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String coreUrl;
|
|
||||||
if (origCorename != null) {
|
if (origCorename != null) {
|
||||||
coreUrl = coreNodeProps.getBaseUrl() + "/" + origCorename;
|
coreUrl = coreNodeProps.getBaseUrl() + "/" + origCorename;
|
||||||
} else {
|
} else {
|
||||||
|
@ -621,6 +638,19 @@ public class SolrDispatchFilter implements Filter
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Collection<Slice> getSlicesForCollections(ClusterState clusterState,
|
||||||
|
Collection<Slice> slices, boolean activeSlices) {
|
||||||
|
Set<String> collections = clusterState.getCollections();
|
||||||
|
for (String collection : collections) {
|
||||||
|
if (activeSlices) {
|
||||||
|
slices.addAll(clusterState.getActiveSlices(collection));
|
||||||
|
} else {
|
||||||
|
slices.addAll(clusterState.getSlices(collection));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return slices;
|
||||||
|
}
|
||||||
|
|
||||||
private SolrCore getCoreByCollection(CoreContainer cores, String corename, String path) {
|
private SolrCore getCoreByCollection(CoreContainer cores, String corename, String path) {
|
||||||
String collection = corename;
|
String collection = corename;
|
||||||
|
|
Loading…
Reference in New Issue