SOLR-14897: limit no of forwarding for given request

* Irrespective of active or down replicas, restrict no of forwarding of request.
  Previously, this restriction was applied only if active is not found
This commit is contained in:
Munendra S N 2020-09-28 13:03:59 +05:30
parent b9c7f50b6e
commit 3dcb19f886
2 changed files with 21 additions and 20 deletions

View File

@ -254,6 +254,8 @@ Bug Fixes
* SOLR-14767: Fix NumberFormatException when integer/long field value is specified as floating number * SOLR-14767: Fix NumberFormatException when integer/long field value is specified as floating number
(Apoorv Bhawsar, Munendra S N) (Apoorv Bhawsar, Munendra S N)
* SOLR-14897: Fix unlimited number of forwarding the request from one node to another node. (hossman, Munendra S N)
Other Changes Other Changes
--------------------- ---------------------

View File

@ -666,19 +666,18 @@ public class HttpSolrCall {
} }
} }
private String getQuerySting() {
int internalRequestCount = queryParams.getInt(INTERNAL_REQUEST_COUNT, 0);
ModifiableSolrParams updatedQueryParams = new ModifiableSolrParams(queryParams);
updatedQueryParams.set(INTERNAL_REQUEST_COUNT, internalRequestCount + 1);
return updatedQueryParams.toQueryString();
}
//TODO using Http2Client //TODO using Http2Client
private void remoteQuery(String coreUrl, HttpServletResponse resp) throws IOException { private void remoteQuery(String coreUrl, HttpServletResponse resp) throws IOException {
HttpRequestBase method; HttpRequestBase method;
HttpEntity httpEntity = null; HttpEntity httpEntity = null;
ModifiableSolrParams updatedQueryParams = new ModifiableSolrParams(queryParams);
int forwardCount = queryParams.getInt(INTERNAL_REQUEST_COUNT, 0) + 1;
updatedQueryParams.set(INTERNAL_REQUEST_COUNT, forwardCount);
String queryStr = updatedQueryParams.toQueryString();
try { try {
String urlstr = coreUrl + getQuerySting(); String urlstr = coreUrl + queryStr;
boolean isPostOrPutRequest = "POST".equals(req.getMethod()) || "PUT".equals(req.getMethod()); boolean isPostOrPutRequest = "POST".equals(req.getMethod()) || "PUT".equals(req.getMethod());
if ("GET".equals(req.getMethod())) { if ("GET".equals(req.getMethod())) {
@ -746,7 +745,7 @@ public class HttpSolrCall {
} catch (IOException e) { } catch (IOException e) {
sendError(new SolrException( sendError(new SolrException(
SolrException.ErrorCode.SERVER_ERROR, SolrException.ErrorCode.SERVER_ERROR,
"Error trying to proxy request for url: " + coreUrl, e)); "Error trying to proxy request for url: " + coreUrl + " with _forwardCount: " + forwardCount, e));
} finally { } finally {
Utils.consumeFully(httpEntity); Utils.consumeFully(httpEntity);
} }
@ -984,8 +983,8 @@ public class HttpSolrCall {
if (activeSlices) { if (activeSlices) {
for (Map.Entry<String, DocCollection> entry : clusterState.getCollectionsMap().entrySet()) { for (Map.Entry<String, DocCollection> entry : clusterState.getCollectionsMap().entrySet()) {
final Slice[] activeCollectionSlices = entry.getValue().getActiveSlicesArr(); final Slice[] activeCollectionSlices = entry.getValue().getActiveSlicesArr();
for (Slice s : activeCollectionSlices) { if (activeCollectionSlices != null) {
slices.add(s); Collections.addAll(slices, activeCollectionSlices);
} }
} }
} else { } else {
@ -1015,9 +1014,7 @@ public class HttpSolrCall {
getSlicesForCollections(clusterState, activeSlices, false); getSlicesForCollections(clusterState, activeSlices, false);
} }
} else { } else {
for (Slice s : slices) { Collections.addAll(activeSlices, slices);
activeSlices.add(s);
}
} }
for (Slice s: activeSlices) { for (Slice s: activeSlices) {
@ -1033,16 +1030,18 @@ public class HttpSolrCall {
collectionsList = new ArrayList<>(collectionsList); collectionsList = new ArrayList<>(collectionsList);
collectionsList.add(collectionName); collectionsList.add(collectionName);
} }
String coreUrl = getCoreUrl(collectionName, origCorename, clusterState,
activeSlices, byCoreName, true);
// Avoid getting into a recursive loop of requests being forwarded by // Avoid getting into a recursive loop of requests being forwarded by
// stopping forwarding and erroring out after (totalReplicas) forwards // stopping forwarding and erroring out after (totalReplicas) forwards
if (queryParams.getInt(INTERNAL_REQUEST_COUNT, 0) > totalReplicas){
throw new SolrException(SolrException.ErrorCode.INVALID_STATE,
"No active replicas found for collection: " + collectionName);
}
String coreUrl = getCoreUrl(collectionName, origCorename, clusterState,
activeSlices, byCoreName, true);
if (coreUrl == null) { if (coreUrl == null) {
if (queryParams.getInt(INTERNAL_REQUEST_COUNT, 0) > totalReplicas){
throw new SolrException(SolrException.ErrorCode.INVALID_STATE,
"No active replicas found for collection: " + collectionName);
}
coreUrl = getCoreUrl(collectionName, origCorename, clusterState, coreUrl = getCoreUrl(collectionName, origCorename, clusterState,
activeSlices, byCoreName, false); activeSlices, byCoreName, false);
} }