SOLR-5371: Solr should consistently call SolrServer#shutdown

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1534002 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2013-10-20 22:58:36 +00:00
parent 26e7b5edb6
commit 4975ad612b
18 changed files with 212 additions and 113 deletions

View File

@ -94,13 +94,16 @@ public class SolrEntityProcessor extends EntityProcessorBase {
"SolrEntityProcessor: parameter 'url' is required");
}
// TODO: we should close this client!
HttpClient client = getHttpClient();
URL url = new URL(serverPath);
// (wt="javabin|xml") default is javabin
if ("xml".equals(context.getResolvedEntityAttribute(CommonParams.WT))) {
// TODO: it doesn't matter for this impl when passing a client currently, but we should shutdown this!
solrServer = new HttpSolrServer(url.toExternalForm(), client, new XMLResponseParser());
LOG.info("using XMLResponseParser");
} else {
// TODO: it doesn't matter for this impl when passing a client currently, but we should shutdown this!
solrServer = new HttpSolrServer(url.toExternalForm(), client);
LOG.info("using BinaryResponseParser");
}

View File

@ -282,10 +282,14 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTe
}
HttpSolrServer solrServer = new HttpSolrServer(getSourceUrl());
solrServer.setConnectionTimeout(15000);
solrServer.setSoTimeout(30000);
solrServer.add(sidl);
solrServer.commit(true, true);
try {
solrServer.setConnectionTimeout(15000);
solrServer.setSoTimeout(30000);
solrServer.add(sidl);
solrServer.commit(true, true);
} finally {
solrServer.shutdown();
}
}
private static class SolrInstance {

View File

@ -168,35 +168,41 @@ public class RecoveryStrategy extends Thread implements ClosableThread {
}
private void commitOnLeader(String leaderUrl) throws SolrServerException, IOException {
private void commitOnLeader(String leaderUrl) throws SolrServerException,
IOException {
HttpSolrServer server = new HttpSolrServer(leaderUrl);
server.setConnectionTimeout(30000);
server.setSoTimeout(60000);
UpdateRequest ureq = new UpdateRequest();
ureq.setParams(new ModifiableSolrParams());
ureq.getParams().set(DistributedUpdateProcessor.COMMIT_END_POINT, true);
ureq.getParams().set(UpdateParams.OPEN_SEARCHER, false);
ureq.setAction(AbstractUpdateRequest.ACTION.COMMIT, false, true).process(
server);
server.shutdown();
try {
server.setConnectionTimeout(30000);
server.setSoTimeout(60000);
UpdateRequest ureq = new UpdateRequest();
ureq.setParams(new ModifiableSolrParams());
ureq.getParams().set(DistributedUpdateProcessor.COMMIT_END_POINT, true);
ureq.getParams().set(UpdateParams.OPEN_SEARCHER, false);
ureq.setAction(AbstractUpdateRequest.ACTION.COMMIT, false, true).process(
server);
} finally {
server.shutdown();
}
}
private void sendPrepRecoveryCmd(String leaderBaseUrl,
String leaderCoreName) throws SolrServerException,
IOException {
private void sendPrepRecoveryCmd(String leaderBaseUrl, String leaderCoreName)
throws SolrServerException, IOException {
HttpSolrServer server = new HttpSolrServer(leaderBaseUrl);
server.setConnectionTimeout(45000);
server.setSoTimeout(120000);
WaitForState prepCmd = new WaitForState();
prepCmd.setCoreName(leaderCoreName);
prepCmd.setNodeName(zkController.getNodeName());
prepCmd.setCoreNodeName(coreZkNodeName);
prepCmd.setState(ZkStateReader.RECOVERING);
prepCmd.setCheckLive(true);
prepCmd.setOnlyIfLeader(true);
server.request(prepCmd);
server.shutdown();
try {
server.setConnectionTimeout(45000);
server.setSoTimeout(120000);
WaitForState prepCmd = new WaitForState();
prepCmd.setCoreName(leaderCoreName);
prepCmd.setNodeName(zkController.getNodeName());
prepCmd.setCoreNodeName(coreZkNodeName);
prepCmd.setState(ZkStateReader.RECOVERING);
prepCmd.setCheckLive(true);
prepCmd.setOnlyIfLeader(true);
server.request(prepCmd);
} finally {
server.shutdown();
}
}
@Override

View File

@ -285,12 +285,14 @@ public class SyncStrategy {
recoverRequestCmd.setCoreName(coreName);
HttpSolrServer server = new HttpSolrServer(baseUrl, client);
server.setConnectionTimeout(15000);
server.setSoTimeout(60000);
try {
server.setConnectionTimeout(15000);
server.setSoTimeout(60000);
server.request(recoverRequestCmd);
} catch (Throwable t) {
SolrException.log(log, ZkCoreNodeProps.getCoreUrl(leaderProps) + ": Could not tell a replica to recover", t);
} finally {
server.shutdown();
}
}
};

View File

@ -75,12 +75,15 @@ import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
import static org.apache.lucene.util.IOUtils.CHARSET_UTF_8;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
@ -247,13 +250,18 @@ public class SnapPuller {
params.set(CommonParams.QT, "/replication");
QueryRequest req = new QueryRequest(params);
HttpSolrServer server = new HttpSolrServer(masterUrl, myHttpClient); //XXX modify to use shardhandler
server.setSoTimeout(60000);
server.setConnectionTimeout(15000);
NamedList rsp;
try {
return server.request(req);
server.setSoTimeout(60000);
server.setConnectionTimeout(15000);
rsp = server.request(req);
} catch (SolrServerException e) {
throw new IOException(e);
throw new SolrException(ErrorCode.SERVER_ERROR, e.getMessage());
} finally {
server.shutdown();
}
return rsp;
}
/**
@ -267,10 +275,9 @@ public class SnapPuller {
params.set(CommonParams.QT, "/replication");
QueryRequest req = new QueryRequest(params);
HttpSolrServer server = new HttpSolrServer(masterUrl, myHttpClient); //XXX modify to use shardhandler
server.setSoTimeout(60000);
server.setConnectionTimeout(15000);
try {
server.setSoTimeout(60000);
server.setConnectionTimeout(15000);
NamedList response = server.request(req);
List<Map<String, Object>> files = (List<Map<String,Object>>) response.get(CMD_GET_FILE_LIST);
@ -287,6 +294,8 @@ public class SnapPuller {
} catch (SolrServerException e) {
throw new IOException(e);
} finally {
server.shutdown();
}
}
@ -1273,9 +1282,7 @@ public class SnapPuller {
* Open a new stream using HttpClient
*/
FastInputStream getStream() throws IOException {
HttpSolrServer s = new HttpSolrServer(masterUrl, myHttpClient, null); //XXX use shardhandler
s.setSoTimeout(60000);
s.setConnectionTimeout(15000);
ModifiableSolrParams params = new ModifiableSolrParams();
// //the method is command=filecontent
@ -1307,7 +1314,11 @@ public class SnapPuller {
NamedList response;
InputStream is = null;
HttpSolrServer s = new HttpSolrServer(masterUrl, myHttpClient, null); //XXX use shardhandler
try {
s.setSoTimeout(60000);
s.setConnectionTimeout(15000);
QueryRequest req = new QueryRequest(params);
response = s.request(req);
is = (InputStream) response.get("stream");
@ -1319,6 +1330,8 @@ public class SnapPuller {
//close stream on error
IOUtils.closeQuietly(is);
throw new IOException("Could not download file '" + fileName + "'", t);
} finally {
s.shutdown();
}
}
}
@ -1534,9 +1547,7 @@ public class SnapPuller {
* Open a new stream using HttpClient
*/
FastInputStream getStream() throws IOException {
HttpSolrServer s = new HttpSolrServer(masterUrl, myHttpClient, null); //XXX use shardhandler
s.setSoTimeout(60000);
s.setConnectionTimeout(15000);
ModifiableSolrParams params = new ModifiableSolrParams();
// //the method is command=filecontent
@ -1568,7 +1579,10 @@ public class SnapPuller {
NamedList response;
InputStream is = null;
HttpSolrServer s = new HttpSolrServer(masterUrl, myHttpClient, null); //XXX use shardhandler
try {
s.setSoTimeout(60000);
s.setConnectionTimeout(15000);
QueryRequest req = new QueryRequest(params);
response = s.request(req);
is = (InputStream) response.get("stream");
@ -1580,6 +1594,8 @@ public class SnapPuller {
//close stream on error
IOUtils.closeQuietly(is);
throw new IOException("Could not download file '" + fileName + "'", t);
} finally {
s.shutdown();
}
}
}
@ -1590,10 +1606,16 @@ public class SnapPuller {
params.set("slave", false);
params.set(CommonParams.QT, "/replication");
HttpSolrServer server = new HttpSolrServer(masterUrl, myHttpClient); //XXX use shardhandler
server.setSoTimeout(60000);
server.setConnectionTimeout(15000);
QueryRequest request = new QueryRequest(params);
return server.request(request);
NamedList rsp;
try {
server.setSoTimeout(60000);
server.setConnectionTimeout(15000);
QueryRequest request = new QueryRequest(params);
rsp = server.request(request);
} finally {
server.shutdown();
}
return rsp;
}
static Integer readInterval(String interval) {

View File

@ -232,13 +232,17 @@ public class CollectionsHandler extends RequestHandlerBase {
ZkCoreNodeProps nodeProps = new ZkCoreNodeProps(leaderProps);
HttpSolrServer server = new HttpSolrServer(nodeProps.getBaseUrl());
server.setConnectionTimeout(15000);
server.setSoTimeout(60000);
RequestSyncShard reqSyncShard = new CoreAdminRequest.RequestSyncShard();
reqSyncShard.setCollection(collection);
reqSyncShard.setShard(shard);
reqSyncShard.setCoreName(nodeProps.getCoreName());
server.request(reqSyncShard);
try {
server.setConnectionTimeout(15000);
server.setSoTimeout(60000);
RequestSyncShard reqSyncShard = new CoreAdminRequest.RequestSyncShard();
reqSyncShard.setCollection(collection);
reqSyncShard.setShard(shard);
reqSyncShard.setCoreName(nodeProps.getCoreName());
server.request(reqSyncShard);
} finally {
server.shutdown();
}
}
private void handleCreateAliasAction(SolrQueryRequest req,

View File

@ -152,7 +152,11 @@ public class HttpShardHandler extends ShardHandler {
String url = urls.get(0);
srsp.setShardAddress(url);
SolrServer server = new HttpSolrServer(url, httpClient);
ssr.nl = server.request(req);
try {
ssr.nl = server.request(req);
} finally {
server.shutdown();
}
} else {
LBHttpSolrServer.Rsp rsp = httpShardHandlerFactory.makeLoadBalancedRequest(req, urls);
ssr.nl = rsp.getResponse();

View File

@ -56,10 +56,12 @@ public class SolrCmdDistributor {
}
public void finish() {
servers.blockUntilFinished();
doRetriesIfNeeded();
servers.shutdown();
try {
servers.blockUntilFinished();
doRetriesIfNeeded();
} finally {
servers.shutdown();
}
}
private void doRetriesIfNeeded() {
@ -189,12 +191,14 @@ public class SolrCmdDistributor {
HttpSolrServer server = new HttpSolrServer(req.node.getUrl(),
servers.getHttpClient());
try {
server.request(req.uReq);
} catch (Exception e) {
throw new SolrException(ErrorCode.SERVER_ERROR, "Failed synchronous update on shard " + req.node + " update: " + req.uReq , e);
} finally {
server.shutdown();
}
return;
}

View File

@ -553,16 +553,21 @@ public class DistributedUpdateProcessor extends UpdateRequestProcessor {
public void run() {
log.info("try and ask " + recoveryUrl + " to recover");
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 (Throwable t) {
SolrException.log(log, recoveryUrl + ": Could not tell a replica to recover", t);
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 (Throwable t) {
SolrException.log(log, recoveryUrl
+ ": Could not tell a replica to recover", t);
}
} finally {
server.shutdown();
}
}
};

View File

@ -923,7 +923,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {
Callable call = new Callable() {
@Override
public Object call() {
HttpSolrServer server;
HttpSolrServer server = null;
try {
server = new HttpSolrServer(baseUrl);
server.setConnectionTimeout(15000);
@ -944,6 +944,10 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {
} catch (Exception e) {
e.printStackTrace();
//fail
} finally {
if (server != null) {
server.shutdown();
}
}
return null;
}
@ -1052,7 +1056,7 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {
Callable call = new Callable() {
@Override
public Object call() {
HttpSolrServer server;
HttpSolrServer server = null;
try {
server = new HttpSolrServer(baseUrl);
server.setConnectionTimeout(15000);
@ -1067,6 +1071,10 @@ public class BasicDistributedZkTest extends AbstractFullDistribZkTestBase {
} catch (Exception e) {
e.printStackTrace();
//fails
} finally {
if (server != null) {
server.shutdown();
}
}
return null;
}

View File

@ -865,9 +865,13 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
while (shardIt.hasNext()) {
Entry<String,Replica> shardEntry = shardIt.next();
ZkCoreNodeProps coreProps = new ZkCoreNodeProps(shardEntry.getValue());
CoreAdminResponse mcr = CoreAdminRequest.getStatus(
coreProps.getCoreName(),
new HttpSolrServer(coreProps.getBaseUrl()));
HttpSolrServer server = new HttpSolrServer(coreProps.getBaseUrl());
CoreAdminResponse mcr;
try {
mcr = CoreAdminRequest.getStatus(coreProps.getCoreName(), server);
} finally {
server.shutdown();
}
long before = mcr.getStartTime(coreProps.getCoreName()).getTime();
urlToTime.put(coreProps.getCoreUrl(), before);
}

View File

@ -310,16 +310,20 @@ public class FullSolrCloudDistribCmdsTest extends AbstractFullDistribZkTestBase
private void testIndexingWithSuss() throws Exception {
ConcurrentUpdateSolrServer suss = new ConcurrentUpdateSolrServer(
((HttpSolrServer) clients.get(0)).getBaseURL(), 3, 1);
suss.setConnectionTimeout(15000);
suss.setSoTimeout(30000);
for (int i=100; i<150; i++) {
index_specific(suss, id, i);
try {
suss.setConnectionTimeout(15000);
suss.setSoTimeout(30000);
for (int i = 100; i < 150; i++) {
index_specific(suss, id, i);
}
suss.blockUntilFinished();
commit();
checkShardConsistency();
} finally {
suss.shutdown();
}
suss.blockUntilFinished();
commit();
checkShardConsistency();
}
private void testOptimisticUpdate(QueryResponse results) throws Exception {

View File

@ -408,12 +408,23 @@ public class ShardSplitTest extends BasicDistributedZkTest {
ZkCoreNodeProps shard1_0 = getLeaderUrlFromZk(AbstractDistribZkTestBase.DEFAULT_COLLECTION, SHARD1_0);
HttpSolrServer shard1_0Server = new HttpSolrServer(shard1_0.getCoreUrl());
QueryResponse response = shard1_0Server.query(query);
QueryResponse response;
try {
response = shard1_0Server.query(query);
} finally {
shard1_0Server.shutdown();
}
long shard10Count = response.getResults().getNumFound();
ZkCoreNodeProps shard1_1 = getLeaderUrlFromZk(AbstractDistribZkTestBase.DEFAULT_COLLECTION, SHARD1_1);
ZkCoreNodeProps shard1_1 = getLeaderUrlFromZk(
AbstractDistribZkTestBase.DEFAULT_COLLECTION, SHARD1_1);
HttpSolrServer shard1_1Server = new HttpSolrServer(shard1_1.getCoreUrl());
QueryResponse response2 = shard1_1Server.query(query);
QueryResponse response2;
try {
response2 = shard1_1Server.query(query);
} finally {
shard1_1Server.shutdown();
}
long shard11Count = response2.getResults().getNumFound();
logDebugHelp(docCounts, response, shard10Count, response2, shard11Count);
@ -433,7 +444,12 @@ public class ShardSplitTest extends BasicDistributedZkTest {
for (Replica replica : slice.getReplicas()) {
String coreUrl = new ZkCoreNodeProps(replica).getCoreUrl();
HttpSolrServer server = new HttpSolrServer(coreUrl);
QueryResponse response = server.query(query);
QueryResponse response;
try {
response = server.query(query);
} finally {
server.shutdown();
}
numFound[c++] = response.getResults().getNumFound();
log.info("Shard: " + shard + " Replica: {} has {} docs", coreUrl, String.valueOf(response.getResults().getNumFound()));
assertTrue("Shard: " + shard + " Replica: " + coreUrl + " has 0 docs", response.getResults().getNumFound() > 0);

View File

@ -115,26 +115,30 @@ public class StressHdfsTest extends BasicDistributedZkTest {
int i = 0;
for (SolrServer client : clients) {
HttpSolrServer c = new HttpSolrServer(getBaseUrl(client) + "/delete_data_dir");
c.add(getDoc("id", i++));
if (random().nextBoolean()) c.add(getDoc("id", i++));
if (random().nextBoolean()) c.add(getDoc("id", i++));
if (random().nextBoolean()) {
c.commit();
} else {
c.commit(true, true, true);
HttpSolrServer c = new HttpSolrServer(getBaseUrl(client)
+ "/delete_data_dir");
try {
c.add(getDoc("id", i++));
if (random().nextBoolean()) c.add(getDoc("id", i++));
if (random().nextBoolean()) c.add(getDoc("id", i++));
if (random().nextBoolean()) {
c.commit();
} else {
c.commit(true, true, true);
}
c.query(new SolrQuery("id:" + i));
c.setSoTimeout(60000);
c.setConnectionTimeout(30000);
NamedList<Object> response = c.query(
new SolrQuery().setRequestHandler("/admin/system")).getResponse();
NamedList<Object> coreInfo = (NamedList<Object>) response.get("core");
String dataDir = (String) ((NamedList<Object>) coreInfo
.get("directory")).get("data");
dataDirs.add(dataDir);
} finally {
c.shutdown();
}
c.query(new SolrQuery("id:" + i));
c.setSoTimeout(60000);
c.setConnectionTimeout(30000);
NamedList<Object> response = c.query(
new SolrQuery().setRequestHandler("/admin/system")).getResponse();
NamedList<Object> coreInfo = (NamedList<Object>) response.get("core");
String dataDir = (String) ((NamedList<Object>) coreInfo.get("directory"))
.get("data");
dataDirs.add(dataDir);
c.shutdown();
}
if (random().nextBoolean()) {

View File

@ -42,6 +42,7 @@ public class SolrExceptionTest extends LuceneTestCase {
SolrServer client = new HttpSolrServer("http://[ff01::114]:11235/solr/", httpClient);
SolrQuery query = new SolrQuery("test123");
client.query(query);
client.shutdown();
} catch (SolrServerException sse) {
gotExpectedError = true;
/***

View File

@ -38,6 +38,7 @@ import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.impl.LBHttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.response.SolrResponseBase;
import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.ModifiableSolrParams;
@ -107,9 +108,14 @@ public class TestLBHttpSolrServer extends LuceneTestCase {
docs.add(doc);
}
HttpSolrServer solrServer = new HttpSolrServer(solrInstance.getUrl(), httpClient);
UpdateResponse resp = solrServer.add(docs);
assertEquals(0, resp.getStatus());
resp = solrServer.commit();
SolrResponseBase resp;
try {
resp = solrServer.add(docs);
assertEquals(0, resp.getStatus());
resp = solrServer.commit();
} finally {
solrServer.shutdown();
}
assertEquals(0, resp.getStatus());
}

View File

@ -479,6 +479,7 @@ public class BasicHttpSolrServerTest extends SolrJettyTestBase {
server.setDefaultMaxConnectionsPerHost(1);
fail("Operation should not succeed.");
} catch (UnsupportedOperationException e) {}
server.shutdown();
client.getConnectionManager().shutdown();
}

View File

@ -204,14 +204,15 @@ public class CloudSolrServerTest extends AbstractFullDistribZkTestBase {
public void testShutdown() throws MalformedURLException {
CloudSolrServer server = new CloudSolrServer("[ff01::114]:33332");
server.setZkConnectTimeout(100);
try {
server.setZkConnectTimeout(100);
server.connect();
fail("Expected exception");
} catch(RuntimeException e) {
} catch (RuntimeException e) {
assertTrue(e.getCause() instanceof TimeoutException);
} finally {
server.shutdown();
}
server.shutdown();
}
}