-
Notifications
You must be signed in to change notification settings - Fork 861
SOLR-18401: HttpJettySolrClient: detect if request wasn't sent; retry #4805
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
114b5d5
SOLR-18401: HttpJettySolrClient: detect if request wasn't sent; means…
dsmiley 8a8cf1a
clarify test methods
dsmiley 0ffbcfd
@Serial
dsmiley cefa59c
Align logic better
dsmiley 2cd224a
tidy
dsmiley d9fcec4
Fix TestMiniSolrCloudClusterSSL: can't assume call-stack order
dsmiley 337699e
ECJ fix
dsmiley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| title: > | ||
| HttpJettySolrClient: detect if request wasn't sent; means retry-able. | ||
| CloudSolrClient & LBSolrClient will detect it. | ||
| type: changed | ||
| authors: | ||
| - name: David Smiley | ||
| links: | ||
| - name: SOLR-18401 | ||
| url: https://issues.apache.org/jira/browse/SOLR-18401 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
solr/solrj/src/java/org/apache/solr/client/solrj/RequestNotSentException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.solr.client.solrj; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.Serial; | ||
|
|
||
| /** | ||
| * Indicates that a request failed before any of it was written to the network, so the server cannot | ||
| * have processed it. Retrying such a request on another node is safe even when it is not | ||
| * idempotent. | ||
| * | ||
| * <p>Typically a pooled connection that the server had already closed. | ||
| */ | ||
| public class RequestNotSentException extends IOException { | ||
|
|
||
| @Serial private static final long serialVersionUID = 1L; | ||
|
|
||
| public RequestNotSentException(String message, Throwable cause) { | ||
| super(message, cause); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBSolrClientRetryUnsentTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.solr.client.solrj.impl; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import org.apache.solr.SolrTestCase; | ||
| import org.apache.solr.client.solrj.RequestNotSentException; | ||
| import org.apache.solr.client.solrj.SolrClient; | ||
| import org.apache.solr.client.solrj.SolrRequest; | ||
| import org.apache.solr.client.solrj.SolrRequest.SolrRequestType; | ||
| import org.apache.solr.client.solrj.SolrServerException; | ||
| import org.apache.solr.client.solrj.request.QueryRequest; | ||
| import org.apache.solr.client.solrj.request.UpdateRequest; | ||
| import org.apache.solr.common.util.NamedList; | ||
| import org.junit.Test; | ||
|
|
||
| /** | ||
| * A failure that proves the request never reached the server is safe to replay even when | ||
| * LBSolrClient would otherwise refuse to retry the request. {@link RequestNotSentException} is that | ||
| * proof. | ||
| */ | ||
| public class LBSolrClientRetryUnsentTest extends SolrTestCase { | ||
|
|
||
| private static final LBSolrClient.Endpoint DEAD_HOST_1 = | ||
| new LBSolrClient.Endpoint("http://127.0.0.1:1/solr"); | ||
| private static final LBSolrClient.Endpoint DEAD_HOST_2 = | ||
| new LBSolrClient.Endpoint("http://127.0.0.1:2/solr"); | ||
|
|
||
| /** Fails whatever endpoint is tried first with {@code failure}; any later endpoint succeeds. */ | ||
| private static class FailFirstEndpoint extends LBSolrClient { | ||
| final List<String> attempted = new ArrayList<>(); | ||
| private final Exception failure; | ||
|
|
||
| FailFirstEndpoint(Exception failure) { | ||
| super(List.of(DEAD_HOST_1, DEAD_HOST_2)); | ||
| this.failure = failure; | ||
| } | ||
|
|
||
| @Override | ||
| protected SolrClient getClient(Endpoint endpoint) { | ||
| return new SolrClient() { | ||
| @Override | ||
| public NamedList<Object> request(SolrRequest<?> request, String collection) | ||
| throws SolrServerException, IOException { | ||
| attempted.add(endpoint.getBaseUrl()); | ||
| if (attempted.size() > 1) { | ||
| return new NamedList<>(); | ||
| } | ||
| if (failure instanceof SolrServerException sse) { | ||
| throw sse; | ||
| } | ||
| throw (IOException) failure; | ||
| } | ||
|
|
||
| @Override | ||
| public void close() {} | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| private static SolrServerException unsentException() { | ||
| IOException onTheWire = new IOException("Broken pipe"); | ||
| return new SolrServerException( | ||
| "Connection failed before the request was sent to: " + DEAD_HOST_1.getUrl(), | ||
| new RequestNotSentException(onTheWire.getMessage(), onTheWire)); | ||
| } | ||
|
|
||
| private static SolrServerException maybeSentException() { | ||
| return new SolrServerException( | ||
| "IOException occurred when talking to server at: " + DEAD_HOST_1.getUrl(), | ||
| new IOException("Broken pipe")); | ||
| } | ||
|
|
||
| private static List<String> requestReturningAttemptedUrls( | ||
| Exception failure, SolrRequest<?> request) throws Exception { | ||
| try (FailFirstEndpoint client = new FailFirstEndpoint(failure)) { | ||
| client.request(new LBSolrClient.Req(request, List.of(DEAD_HOST_1, DEAD_HOST_2))); | ||
| return client.attempted; | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testUpdateIsRetriedWhenRequestWasNeverSent() throws Exception { | ||
| assertEquals( | ||
| List.of(DEAD_HOST_1.getBaseUrl(), DEAD_HOST_2.getBaseUrl()), | ||
| requestReturningAttemptedUrls(unsentException(), new UpdateRequest().add("id", "1"))); | ||
| } | ||
|
|
||
| /** LBSolrClient classifies {@link SolrRequestType#UPDATE} as non-retryable. */ | ||
| @Test | ||
| public void testRequestThatMayHaveBeenReceivedIsNotRetried() { | ||
| LBSolrClient.Req req = | ||
| new LBSolrClient.Req(new UpdateRequest().add("id", "1"), List.of(DEAD_HOST_1, DEAD_HOST_2)); | ||
| try (FailFirstEndpoint client = new FailFirstEndpoint(maybeSentException())) { | ||
| expectThrows(SolrServerException.class, () -> client.request(req)); | ||
| assertEquals(List.of(DEAD_HOST_1.getBaseUrl()), client.attempted); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testQueryIsStillRetriedOnAnyIOException() throws Exception { | ||
| assertEquals( | ||
| List.of(DEAD_HOST_1.getBaseUrl(), DEAD_HOST_2.getBaseUrl()), | ||
| requestReturningAttemptedUrls(maybeSentException(), new QueryRequest())); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The try-catch logic here is a challenge; not sure if we can make it elegant/clearer.