Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOLR-9303: Refactor CloudSolrClient for extensibility #51

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -1144,7 +1144,6 @@ protected NamedList<Object> sendRequest(SolrRequest request, String collection)
ClusterState clusterState = zkStateReader.getClusterState();

boolean sendToLeaders = false;
List<String> replicas = null;

if (request instanceof IsUpdateRequest) {
if (request instanceof UpdateRequest) {
Expand All @@ -1154,13 +1153,25 @@ protected NamedList<Object> sendRequest(SolrRequest request, String collection)
}
}
sendToLeaders = true;
replicas = new ArrayList<>();
}

List<String> urlList = findRequestUrls(request, collection, clusterState, sendToLeaders);

return executeHttpRequest(request, urlList);
}

protected List<String> findRequestUrls(SolrRequest request, String collection, ClusterState clusterState,
boolean sendToLeaders) throws SolrServerException {
SolrParams reqParams = request.getParams();
if (reqParams == null) {
reqParams = new ModifiableSolrParams();
}

List<String> replicas = null;
if (sendToLeaders) {
replicas = new ArrayList<>();
}

List<String> theUrlList = new ArrayList<>();
if (ADMIN_PATHS.contains(request.getPath())) {
Set<String> liveNodes = clusterState.getLiveNodes();
Expand Down Expand Up @@ -1209,8 +1220,11 @@ protected NamedList<Object> sendRequest(SolrRequest request, String collection)
for (ZkNodeProps nodeProps : slice.getReplicasMap().values()) {
ZkCoreNodeProps coreNodeProps = new ZkCoreNodeProps(nodeProps);
String node = coreNodeProps.getNodeName();
if (!liveNodes.contains(coreNodeProps.getNodeName())
|| Replica.State.getState(coreNodeProps.getState()) != Replica.State.ACTIVE) continue;

if (!isNodeAvailable(coreNodeProps, liveNodes, request)) {
continue;
}

if (nodes.put(node, nodeProps) == null) {
if (!sendToLeaders || coreNodeProps.isLeader()) {
String url;
Expand Down Expand Up @@ -1265,13 +1279,17 @@ protected NamedList<Object> sendRequest(SolrRequest request, String collection)
"Could not find a healthy node to handle the request.");
}
}
return theUrlList;
}

protected NamedList<Object> executeHttpRequest(SolrRequest request, List<String> theUrlList)
throws SolrServerException, IOException {
LBHttpSolrClient.Req req = new LBHttpSolrClient.Req(request, theUrlList);
LBHttpSolrClient.Rsp rsp = lbClient.request(req);
return rsp.getResponse();
}

private Set<String> getCollectionNames(ClusterState clusterState,
protected Set<String> getCollectionNames(ClusterState clusterState,
String collection) {
// Extract each comma separated collection name and store in a List.
List<String> rawCollectionsList = StrUtils.splitSmart(collection, ",", true);
Expand All @@ -1295,6 +1313,11 @@ private Set<String> getCollectionNames(ClusterState clusterState,
return collectionNames;
}

protected boolean isNodeAvailable(ZkCoreNodeProps coreNodeProps, Set<String> liveNodes, SolrRequest request) {
return liveNodes.contains(coreNodeProps.getNodeName())
&& Replica.State.getState(coreNodeProps.getState()) == Replica.State.ACTIVE;
}

@Override
public void close() throws IOException {
if (zkStateReader != null) {
Expand Down