SOLR-5370: Requests to recover when an update fails should be done in background threads.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1533996 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2013-10-20 22:31:36 +00:00
parent 52a77784c2
commit 26e7b5edb6
2 changed files with 44 additions and 20 deletions

View File

@ -68,7 +68,7 @@ public class SyncStrategy {
params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, 10000);
params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, 20);
params.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, 15000);
params.set(HttpClientUtil.PROP_SO_TIMEOUT, 30000);
params.set(HttpClientUtil.PROP_SO_TIMEOUT, 60000);
params.set(HttpClientUtil.PROP_USE_RETRY, false);
client = HttpClientUtil.createClient(params);
}

View File

@ -17,8 +17,10 @@ package org.apache.solr.update.processor;
* limitations under the License.
*/
import org.apache.http.client.HttpClient;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.CharsRef;
import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.request.CoreAdminRequest.RequestRecovery;
import org.apache.solr.cloud.CloudDescriptor;
@ -43,7 +45,9 @@ import org.apache.solr.common.params.UpdateParams;
import org.apache.solr.common.util.Hash;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.handler.component.HttpShardHandlerFactory;
import org.apache.solr.handler.component.RealTimeGetComponent;
import org.apache.solr.handler.component.ShardHandler;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrRequestInfo;
import org.apache.solr.response.SolrQueryResponse;
@ -75,6 +79,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import static org.apache.solr.update.processor.DistributingUpdateProcessorFactory.DISTRIB_UPDATE_PARAM;
@ -107,6 +112,17 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {
}
}
private final HttpClient client;
{
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, 10000);
params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, 20);
params.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, 15000);
params.set(HttpClientUtil.PROP_SO_TIMEOUT, 60000);
params.set(HttpClientUtil.PROP_USE_RETRY, false);
client = HttpClientUtil.createClient(params);
}
public static final String COMMIT_END_POINT = "commit_end_point";
public static final String LOG_REPLAY = "log_replay";
@ -146,7 +162,6 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {
private UpdateCommand updateCommand; // the current command this processor is working on.
public DistributedUpdateProcessor(SolrQueryRequest req,
SolrQueryResponse rsp, UpdateRequestProcessor next) {
super(next);
@ -180,6 +195,7 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {
if (cloudDesc != null) {
collection = cloudDesc.getCollectionName();
}
}
@ -517,33 +533,41 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {
// legit
// TODO: we should do this in the background it would seem
for (SolrCmdDistributor.Error error : errors) {
for (final SolrCmdDistributor.Error error : errors) {
if (error.req.node instanceof RetryNode) {
// we don't try to force a leader to recover
// when we cannot forward to it
continue;
}
// TODO: we should force their state to recovering ??
// TODO: could be sent in parallel
// TODO: do retries??
// TODO: what if its is already recovering? Right now recoveries queue up -
// should they?
String recoveryUrl = error.req.node.getBaseUrl();
HttpSolrServer server;
final String recoveryUrl = error.req.node.getBaseUrl();
Thread thread = new Thread() {
{
setDaemon(true);
}
@Override
public void run() {
log.info("try and ask " + recoveryUrl + " to recover");
try {
server = new HttpSolrServer(recoveryUrl);
HttpSolrServer server = new HttpSolrServer(recoveryUrl);
server.setSoTimeout(60000);
server.setConnectionTimeout(15000);
RequestRecovery recoverRequestCmd = new RequestRecovery();
recoverRequestCmd.setAction(CoreAdminAction.REQUESTRECOVERY);
recoverRequestCmd.setCoreName(error.req.node.getCoreName());
try {
server.request(recoverRequestCmd);
} catch (Exception e) {
log.info("Could not tell a replica to recover", e);
} catch (Throwable t) {
SolrException.log(log, recoveryUrl + ": Could not tell a replica to recover", t);
}
}
};
ExecutorService executor = req.getCore().getCoreDescriptor().getCoreContainer().getUpdateExecutor();
executor.execute(thread);
}
}