mirror of https://github.com/apache/lucene.git
SOLR-5903: SolrCore implements Closeable
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1581360 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
436fc3149a
commit
1dba8a6f6b
|
@ -237,6 +237,9 @@ Other Changes
|
|||
* SOLR-5228: Don't require <field> or <dynamicField> be inside of <fields> -- or
|
||||
that <fieldType> be inside of <types>. (Erick Erickson)
|
||||
|
||||
* SOLR-5903: SolrCore implements Closeable, cut over to using try-with-resources
|
||||
where possible. (Alan Woodward)
|
||||
|
||||
================== 4.7.1 ==================
|
||||
|
||||
Versions of Major Components
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
package org.apache.solr.cloud;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.lucene.search.MatchAllDocsQuery;
|
||||
import org.apache.solr.common.SolrException;
|
||||
import org.apache.solr.common.SolrException.ErrorCode;
|
||||
|
@ -29,6 +25,10 @@ import org.apache.zookeeper.KeeperException.NodeExistsException;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
@ -194,12 +194,9 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase {
|
|||
if (!weAreReplacement) {
|
||||
waitForReplicasToComeUp(weAreReplacement, leaderVoteWait);
|
||||
}
|
||||
|
||||
SolrCore core = null;
|
||||
try {
|
||||
|
||||
core = cc.getCore(coreName);
|
||||
|
||||
|
||||
try (SolrCore core = cc.getCore(coreName)) {
|
||||
|
||||
if (core == null) {
|
||||
cancelElection();
|
||||
throw new SolrException(ErrorCode.SERVER_ERROR,
|
||||
|
@ -287,10 +284,6 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase {
|
|||
log.info("I am the new leader: "
|
||||
+ ZkCoreNodeProps.getCoreUrl(leaderProps) + " " + shardId);
|
||||
core.getCoreDescriptor().getCloudDescriptor().setLeader(true);
|
||||
} finally {
|
||||
if (core != null) {
|
||||
core.close();
|
||||
}
|
||||
}
|
||||
boolean success = false;
|
||||
try {
|
||||
|
@ -299,8 +292,8 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase {
|
|||
} catch (Exception e) {
|
||||
SolrException.log(log, "There was a problem trying to register as the leader", e);
|
||||
|
||||
try {
|
||||
core = cc.getCore(coreName);
|
||||
try (SolrCore core = cc.getCore(coreName)) {
|
||||
|
||||
if (core == null) {
|
||||
throw new SolrException(ErrorCode.SERVER_ERROR,
|
||||
"Fatal Error, SolrCore not found:" + coreName + " in "
|
||||
|
@ -312,16 +305,8 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase {
|
|||
// we could not publish ourselves as leader - rejoin election
|
||||
rejoinLeaderElection(leaderSeqPath, core);
|
||||
} finally {
|
||||
try {
|
||||
if (!success) {
|
||||
cancelElection();
|
||||
}
|
||||
} finally {
|
||||
if (core != null) {
|
||||
core.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (!success)
|
||||
cancelElection();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,14 +17,6 @@ package org.apache.solr.cloud;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.lucene.search.MatchAllDocsQuery;
|
||||
import org.apache.lucene.store.Directory;
|
||||
|
@ -66,6 +58,14 @@ import org.apache.zookeeper.KeeperException;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class RecoveryStrategy extends Thread implements ClosableThread {
|
||||
private static final int MAX_RETRIES = 500;
|
||||
private static final int INTERRUPTED = MAX_RETRIES + 1;
|
||||
|
@ -216,14 +216,15 @@ public class RecoveryStrategy extends Thread implements ClosableThread {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
SolrCore core = cc.getCore(coreName);
|
||||
if (core == null) {
|
||||
SolrException.log(log, "SolrCore not found - cannot recover:" + coreName);
|
||||
return;
|
||||
}
|
||||
|
||||
// set request info for logging
|
||||
try {
|
||||
try (SolrCore core = cc.getCore(coreName)) {
|
||||
|
||||
if (core == null) {
|
||||
SolrException.log(log, "SolrCore not found - cannot recover:" + coreName);
|
||||
return;
|
||||
}
|
||||
|
||||
SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());
|
||||
SolrQueryResponse rsp = new SolrQueryResponse();
|
||||
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
|
||||
|
@ -243,7 +244,6 @@ public class RecoveryStrategy extends Thread implements ClosableThread {
|
|||
"", e);
|
||||
}
|
||||
} finally {
|
||||
if (core != null) core.close();
|
||||
SolrRequestInfo.clearRequestInfo();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,28 +17,6 @@ package org.apache.solr.cloud;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.URLEncoder;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.solr.client.solrj.impl.HttpSolrServer;
|
||||
|
@ -74,6 +52,28 @@ import org.apache.zookeeper.data.Stat;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.URLEncoder;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
/**
|
||||
* Handle ZooKeeper interactions.
|
||||
*
|
||||
|
@ -802,13 +802,9 @@ public final class ZkController {
|
|||
String ourUrl = ZkCoreNodeProps.getCoreUrl(baseUrl, coreName);
|
||||
log.info("We are " + ourUrl + " and leader is " + leaderUrl);
|
||||
boolean isLeader = leaderUrl.equals(ourUrl);
|
||||
|
||||
|
||||
SolrCore core = null;
|
||||
try {
|
||||
core = cc.getCore(desc.getName());
|
||||
try (SolrCore core = cc.getCore(desc.getName())) {
|
||||
|
||||
|
||||
// recover from local transaction log and wait for it to complete before
|
||||
// going active
|
||||
// TODO: should this be moved to another thread? To recoveryStrat?
|
||||
|
@ -837,12 +833,7 @@ public final class ZkController {
|
|||
publish(desc, ZkStateReader.ACTIVE);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (core != null) {
|
||||
core.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// make sure we have an update cluster state right away
|
||||
zkStateReader.updateClusterState(true);
|
||||
|
@ -1028,16 +1019,10 @@ public final class ZkController {
|
|||
*/
|
||||
public void publish(final CoreDescriptor cd, final String state, boolean updateLastState, boolean forcePublish) throws KeeperException, InterruptedException {
|
||||
if (!forcePublish) {
|
||||
SolrCore core = cc.getCore(cd.getName());
|
||||
if (core == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (core.isClosed()) {
|
||||
try (SolrCore core = cc.getCore(cd.getName())) {
|
||||
if (core == null || core.isClosed()) {
|
||||
return;
|
||||
}
|
||||
} finally {
|
||||
core.close();
|
||||
}
|
||||
}
|
||||
String collection = cd.getCloudDescriptor().getCollectionName();
|
||||
|
|
|
@ -692,18 +692,13 @@ public class CoreContainer {
|
|||
}
|
||||
|
||||
public void rename(String name, String toName) {
|
||||
SolrCore core = getCore(name);
|
||||
try {
|
||||
try (SolrCore core = getCore(name)) {
|
||||
if (core != null) {
|
||||
registerCore(false, toName, core, false);
|
||||
name = checkDefault(name);
|
||||
SolrCore old = solrCores.remove(name, false);
|
||||
coresLocator.rename(this, old.getCoreDescriptor(), core.getCoreDescriptor());
|
||||
}
|
||||
} finally {
|
||||
if (core != null) {
|
||||
core.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -99,6 +99,7 @@ import org.slf4j.LoggerFactory;
|
|||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
@ -137,7 +138,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public final class SolrCore implements SolrInfoMBean {
|
||||
public final class SolrCore implements SolrInfoMBean, Closeable {
|
||||
public static final String version="1.0";
|
||||
|
||||
// These should *only* be used for debugging or monitoring purposes
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.apache.solr.common.SolrException.ErrorCode;
|
|||
import org.apache.solr.common.cloud.ClusterState;
|
||||
import org.apache.solr.common.cloud.DocCollection;
|
||||
import org.apache.solr.common.cloud.DocRouter;
|
||||
import org.apache.solr.common.cloud.Replica;
|
||||
import org.apache.solr.common.cloud.Slice;
|
||||
import org.apache.solr.common.cloud.ZkNodeProps;
|
||||
import org.apache.solr.common.cloud.ZkStateReader;
|
||||
|
@ -856,9 +855,8 @@ public class CoreAdminHandler extends RequestHandlerBase {
|
|||
if (cname == null) {
|
||||
cname = "";
|
||||
}
|
||||
SolrCore core = null;
|
||||
try {
|
||||
core = coreContainer.getCore(cname);
|
||||
try (SolrCore core = coreContainer.getCore(cname)) {
|
||||
|
||||
if (core != null) {
|
||||
// try to publish as recovering right away
|
||||
try {
|
||||
|
@ -877,11 +875,6 @@ public class CoreAdminHandler extends RequestHandlerBase {
|
|||
} else {
|
||||
SolrException.log(log, "Could not find core to call recovery:" + cname);
|
||||
}
|
||||
} finally {
|
||||
// no recoveryStrat close for now
|
||||
if (core != null) {
|
||||
core.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -903,10 +896,10 @@ public class CoreAdminHandler extends RequestHandlerBase {
|
|||
if (cname == null) {
|
||||
throw new IllegalArgumentException(CoreAdminParams.CORE + " is required");
|
||||
}
|
||||
SolrCore core = null;
|
||||
|
||||
SyncStrategy syncStrategy = null;
|
||||
try {
|
||||
core = coreContainer.getCore(cname);
|
||||
try (SolrCore core = coreContainer.getCore(cname)) {
|
||||
|
||||
if (core != null) {
|
||||
syncStrategy = new SyncStrategy(core.getCoreDescriptor().getCoreContainer());
|
||||
|
||||
|
@ -942,9 +935,6 @@ public class CoreAdminHandler extends RequestHandlerBase {
|
|||
}
|
||||
} finally {
|
||||
// no recoveryStrat close for now
|
||||
if (core != null) {
|
||||
core.close();
|
||||
}
|
||||
if (syncStrategy != null) {
|
||||
syncStrategy.close();
|
||||
}
|
||||
|
@ -977,9 +967,7 @@ public class CoreAdminHandler extends RequestHandlerBase {
|
|||
boolean live = false;
|
||||
int retry = 0;
|
||||
while (true) {
|
||||
SolrCore core = null;
|
||||
try {
|
||||
core = coreContainer.getCore(cname);
|
||||
try (SolrCore core = coreContainer.getCore(cname)) {
|
||||
if (core == null && retry == 30) {
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST, "core not found:"
|
||||
+ cname);
|
||||
|
@ -1098,10 +1086,6 @@ public class CoreAdminHandler extends RequestHandlerBase {
|
|||
throw new SolrException(ErrorCode.SERVER_ERROR, null, e);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (core != null) {
|
||||
core.close();
|
||||
}
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
@ -1113,9 +1097,10 @@ public class CoreAdminHandler extends RequestHandlerBase {
|
|||
private void handleRequestApplyUpdatesAction(SolrQueryRequest req, SolrQueryResponse rsp) {
|
||||
SolrParams params = req.getParams();
|
||||
String cname = params.get(CoreAdminParams.NAME, "");
|
||||
SolrCore core = coreContainer.getCore(cname);
|
||||
log.info("Applying buffered updates on core: " + cname);
|
||||
try {
|
||||
try (SolrCore core = coreContainer.getCore(cname)) {
|
||||
if (core == null)
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST, "Core [" + cname + "] not found");
|
||||
UpdateLog updateLog = core.getUpdateHandler().getUpdateLog();
|
||||
if (updateLog.getState() != UpdateLog.State.BUFFERING) {
|
||||
throw new SolrException(ErrorCode.SERVER_ERROR, "Core " + cname + " not in buffering state");
|
||||
|
@ -1145,8 +1130,6 @@ public class CoreAdminHandler extends RequestHandlerBase {
|
|||
throw new SolrException(ErrorCode.SERVER_ERROR, "Could not apply buffered updates", e);
|
||||
} finally {
|
||||
if (req != null) req.close();
|
||||
if (core != null)
|
||||
core.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1154,9 +1137,11 @@ public class CoreAdminHandler extends RequestHandlerBase {
|
|||
private void handleRequestBufferUpdatesAction(SolrQueryRequest req, SolrQueryResponse rsp) {
|
||||
SolrParams params = req.getParams();
|
||||
String cname = params.get(CoreAdminParams.NAME, "");
|
||||
SolrCore core = coreContainer.getCore(cname);
|
||||
log.info("Starting to buffer updates on core:" + cname);
|
||||
try {
|
||||
|
||||
try (SolrCore core = coreContainer.getCore(cname)) {
|
||||
if (core == null)
|
||||
throw new SolrException(ErrorCode.BAD_REQUEST, "Core [" + cname + "] does not exist");
|
||||
UpdateLog updateLog = core.getUpdateHandler().getUpdateLog();
|
||||
if (updateLog.getState() != UpdateLog.State.ACTIVE) {
|
||||
throw new SolrException(ErrorCode.SERVER_ERROR, "Core " + cname + " not in active state");
|
||||
|
@ -1171,8 +1156,6 @@ public class CoreAdminHandler extends RequestHandlerBase {
|
|||
throw new SolrException(ErrorCode.SERVER_ERROR, "Could not start buffering updates", e);
|
||||
} finally {
|
||||
if (req != null) req.close();
|
||||
if (core != null)
|
||||
core.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1204,9 +1187,8 @@ public class CoreAdminHandler extends RequestHandlerBase {
|
|||
info.add("isLoaded", "false");
|
||||
}
|
||||
} else {
|
||||
SolrCore core = cores.getCore(cname);
|
||||
if (core != null) {
|
||||
try {
|
||||
try (SolrCore core = cores.getCore(cname)) {
|
||||
if (core != null) {
|
||||
info.add("name", core.getName());
|
||||
info.add("isDefaultCore", core.getName().equals(cores.getDefaultCoreName()));
|
||||
info.add("instanceDir", normalizePath(core.getResourceLoader().getInstanceDir()));
|
||||
|
@ -1227,8 +1209,6 @@ public class CoreAdminHandler extends RequestHandlerBase {
|
|||
searcher.decref();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
core.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,9 +17,6 @@ package org.apache.solr;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.solr.client.solrj.SolrQuery;
|
||||
import org.apache.solr.client.solrj.SolrServer;
|
||||
|
@ -29,8 +26,11 @@ import org.apache.solr.client.solrj.request.QueryRequest;
|
|||
import org.apache.solr.client.solrj.request.UpdateRequest;
|
||||
import org.apache.solr.common.SolrInputDocument;
|
||||
import org.apache.solr.core.SolrCore;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class AnalysisAfterCoreReloadTest extends SolrTestCaseJ4 {
|
||||
|
||||
|
@ -116,26 +116,20 @@ public class AnalysisAfterCoreReloadTest extends SolrTestCaseJ4 {
|
|||
}
|
||||
|
||||
private void overwriteStopwords(String stopwords) throws IOException {
|
||||
SolrCore core = h.getCoreContainer().getCore(collection);
|
||||
try {
|
||||
try (SolrCore core = h.getCoreContainer().getCore(collection)) {
|
||||
String configDir = core.getResourceLoader().getConfigDir();
|
||||
FileUtils.moveFile(new File(configDir, "stopwords.txt"), new File(configDir, "stopwords.txt.bak"));
|
||||
File file = new File(configDir, "stopwords.txt");
|
||||
FileUtils.writeStringToFile(file, stopwords, "UTF-8");
|
||||
|
||||
} finally {
|
||||
core.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
SolrCore core = h.getCoreContainer().getCore(collection);
|
||||
String configDir;
|
||||
try {
|
||||
try (SolrCore core = h.getCoreContainer().getCore(collection)) {
|
||||
configDir = core.getResourceLoader().getConfigDir();
|
||||
} finally {
|
||||
core.close();
|
||||
}
|
||||
super.tearDown();
|
||||
if (new File(configDir, "stopwords.txt.bak").exists()) {
|
||||
|
|
|
@ -343,13 +343,9 @@ public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
|
|||
|
||||
}
|
||||
|
||||
private final long getCoreStartTime(final CoreContainer cc,
|
||||
final String name) {
|
||||
SolrCore tmp = cc.getCore(name);
|
||||
try {
|
||||
private long getCoreStartTime(final CoreContainer cc, final String name) {
|
||||
try (SolrCore tmp = cc.getCore(name)) {
|
||||
return tmp.getStartTime();
|
||||
} finally {
|
||||
tmp.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -142,28 +142,27 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {
|
|||
TestLazyCores.checkInCores(cc, "core1");
|
||||
TestLazyCores.checkNotInCores(cc, "lazy1", "core2", "collection1");
|
||||
|
||||
SolrCore core1 = cc.getCore("core1");
|
||||
// force loading of core2 and lazy1 by getting them from the CoreContainer
|
||||
try (SolrCore core1 = cc.getCore("core1");
|
||||
SolrCore core2 = cc.getCore("core2");
|
||||
SolrCore lazy1 = cc.getCore("lazy1")) {
|
||||
|
||||
// Let's assert we did the right thing for implicit properties too.
|
||||
CoreDescriptor desc = core1.getCoreDescriptor();
|
||||
assertEquals("core1", desc.getName());
|
||||
// Let's assert we did the right thing for implicit properties too.
|
||||
CoreDescriptor desc = core1.getCoreDescriptor();
|
||||
assertEquals("core1", desc.getName());
|
||||
|
||||
// This is too long and ugly to put in. Besides, it varies.
|
||||
assertNotNull(desc.getInstanceDir());
|
||||
// This is too long and ugly to put in. Besides, it varies.
|
||||
assertNotNull(desc.getInstanceDir());
|
||||
|
||||
// Prove we're ignoring this even though it's set in the properties file
|
||||
assertFalse("InstanceDir should be ignored", desc.getInstanceDir().contains("totallybogus"));
|
||||
// Prove we're ignoring this even though it's set in the properties file
|
||||
assertFalse("InstanceDir should be ignored", desc.getInstanceDir().contains("totallybogus"));
|
||||
|
||||
assertEquals("core1", desc.getDataDir());
|
||||
assertEquals("solrconfig-minimal.xml", desc.getConfigName());
|
||||
assertEquals("schema-tiny.xml", desc.getSchemaName());
|
||||
assertEquals("core1", desc.getDataDir());
|
||||
assertEquals("solrconfig-minimal.xml", desc.getConfigName());
|
||||
assertEquals("schema-tiny.xml", desc.getSchemaName());
|
||||
|
||||
SolrCore core2 = cc.getCore("core2");
|
||||
SolrCore lazy1 = cc.getCore("lazy1");
|
||||
TestLazyCores.checkInCores(cc, "core1", "core2", "lazy1");
|
||||
core1.close();
|
||||
core2.close();
|
||||
lazy1.close();
|
||||
TestLazyCores.checkInCores(cc, "core1", "core2", "lazy1");
|
||||
}
|
||||
|
||||
} finally {
|
||||
cc.shutdown();
|
||||
|
@ -208,13 +207,10 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {
|
|||
addCoreWithProps(makeCorePropFile("core2", false, false, "dataDir=core2"),
|
||||
new File(alt, "core2" + File.separator + CorePropertiesLocator.PROPERTIES_FILENAME));
|
||||
CoreContainer cc = init();
|
||||
try {
|
||||
SolrCore core1 = cc.getCore("core1");
|
||||
SolrCore core2 = cc.getCore("core2");
|
||||
try (SolrCore core1 = cc.getCore("core1");
|
||||
SolrCore core2 = cc.getCore("core2")) {
|
||||
assertNotNull(core1);
|
||||
assertNotNull(core2);
|
||||
core1.close();
|
||||
core2.close();
|
||||
} finally {
|
||||
cc.shutdown();
|
||||
if (alt.exists()) FileUtils.deleteDirectory(alt);
|
||||
|
@ -231,13 +227,10 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {
|
|||
addCoreWithProps(makeCorePropFile("core2", false, false),
|
||||
new File(noCoreDir, "core2" + File.separator + CorePropertiesLocator.PROPERTIES_FILENAME));
|
||||
CoreContainer cc = init();
|
||||
try {
|
||||
SolrCore core1 = cc.getCore("core1");
|
||||
SolrCore core2 = cc.getCore("core2");
|
||||
try (SolrCore core1 = cc.getCore("core1");
|
||||
SolrCore core2 = cc.getCore("core2")) {
|
||||
assertNotNull(core1);
|
||||
assertNotNull(core2);
|
||||
core1.close();
|
||||
core2.close();
|
||||
} finally {
|
||||
cc.shutdown();
|
||||
if (noCoreDir.exists()) FileUtils.deleteDirectory(noCoreDir);
|
||||
|
|
|
@ -16,19 +16,25 @@
|
|||
*/
|
||||
package org.apache.solr.core;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.util.*;
|
||||
import javax.management.*;
|
||||
|
||||
import org.apache.lucene.util.Constants;
|
||||
import org.apache.solr.core.JmxMonitoredMap.SolrDynamicMBean;
|
||||
import org.apache.solr.util.AbstractSolrTestCase;
|
||||
import org.junit.Assume;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.management.AttributeNotFoundException;
|
||||
import javax.management.MBeanAttributeInfo;
|
||||
import javax.management.MBeanInfo;
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.MalformedObjectNameException;
|
||||
import javax.management.ObjectInstance;
|
||||
import javax.management.ObjectName;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Test for JMX Integration
|
||||
*
|
||||
|
@ -156,8 +162,7 @@ public class TestJmxIntegration extends AbstractSolrTestCase {
|
|||
Set<ObjectInstance> newBeans = mbeanServer.queryMBeans(null, null);
|
||||
int newNumberOfObjects = 0;
|
||||
int registrySize = 0;
|
||||
SolrCore core = h.getCoreContainer().getCore(coreName);
|
||||
try {
|
||||
try (SolrCore core = h.getCoreContainer().getCore(coreName)) {
|
||||
registrySize = core.getInfoRegistry().size();
|
||||
for (ObjectInstance bean : newBeans) {
|
||||
try {
|
||||
|
@ -168,8 +173,6 @@ public class TestJmxIntegration extends AbstractSolrTestCase {
|
|||
// expected
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
core.close();
|
||||
}
|
||||
|
||||
log.info("After Reload: Size of infoRegistry: " + registrySize + " MBeans: " + newNumberOfObjects);
|
||||
|
|
|
@ -410,15 +410,10 @@ public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
|
|||
SolrXMLCoresLocator.NonPersistingLocator locator
|
||||
= (SolrXMLCoresLocator.NonPersistingLocator) cores.getCoresLocator();
|
||||
|
||||
String instDir = null;
|
||||
{
|
||||
SolrCore template = null;
|
||||
try {
|
||||
template = cores.getCore("collection1");
|
||||
instDir = template.getCoreDescriptor().getRawInstanceDir();
|
||||
} finally {
|
||||
if (null != template) template.close();
|
||||
}
|
||||
String instDir;
|
||||
try (SolrCore template = cores.getCore("collection1")) {
|
||||
assertNotNull(template);
|
||||
instDir = template.getCoreDescriptor().getRawInstanceDir();
|
||||
}
|
||||
|
||||
final File instDirFile = new File(cores.getSolrHome(), instDir);
|
||||
|
|
|
@ -144,15 +144,10 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 {
|
|||
|
||||
final CoreAdminHandler admin = new CoreAdminHandler(cores);
|
||||
|
||||
String instDir = null;
|
||||
{
|
||||
SolrCore template = null;
|
||||
try {
|
||||
template = cores.getCore("collection1");
|
||||
instDir = template.getCoreDescriptor().getInstanceDir();
|
||||
} finally {
|
||||
if (null != template) template.close();
|
||||
}
|
||||
String instDir;
|
||||
try (SolrCore template = cores.getCore("collection1")) {
|
||||
assertNotNull(template);
|
||||
instDir = template.getCoreDescriptor().getInstanceDir();
|
||||
}
|
||||
|
||||
final File instDirFile = new File(instDir);
|
||||
|
|
|
@ -48,15 +48,10 @@ public class CoreAdminRequestStatusTest extends SolrTestCaseJ4{
|
|||
|
||||
final CoreAdminHandler admin = new CoreAdminHandler(cores);
|
||||
|
||||
String instDir = null;
|
||||
{
|
||||
SolrCore template = null;
|
||||
try {
|
||||
template = cores.getCore("collection1");
|
||||
instDir = template.getCoreDescriptor().getInstanceDir();
|
||||
} finally {
|
||||
if (null != template) template.close();
|
||||
}
|
||||
String instDir;
|
||||
try (SolrCore template = cores.getCore("collection1")) {
|
||||
assertNotNull(template);
|
||||
instDir = template.getCoreDescriptor().getInstanceDir();
|
||||
}
|
||||
|
||||
final File instDirFile = new File(instDir);
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.junit.rules.TestRule;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public class CoreMergeIndexesAdminHandlerTest extends SolrTestCaseJ4 {
|
||||
|
||||
|
@ -80,8 +79,7 @@ public class CoreMergeIndexesAdminHandlerTest extends SolrTestCaseJ4 {
|
|||
|
||||
final CoreAdminHandler admin = new CoreAdminHandler(cores);
|
||||
|
||||
SolrCore core = cores.getCore("collection1");
|
||||
try {
|
||||
try (SolrCore core = cores.getCore("collection1")) {
|
||||
FailingDirectoryFactory dirFactory = (FailingDirectoryFactory)core.getDirectoryFactory();
|
||||
|
||||
try {
|
||||
|
@ -102,8 +100,6 @@ public class CoreMergeIndexesAdminHandlerTest extends SolrTestCaseJ4 {
|
|||
unIgnoreException(FAILING_MSG);
|
||||
}
|
||||
dirFactory.fail = false;
|
||||
} finally {
|
||||
core.close();
|
||||
}
|
||||
|
||||
// cleanup
|
||||
|
|
|
@ -75,8 +75,7 @@ public class ChangedSchemaMergeTest extends SolrTestCaseJ4 {
|
|||
public void testOptimizeDiffSchemas() throws Exception {
|
||||
// load up a core (why not put it on disk?)
|
||||
CoreContainer cc = init();
|
||||
SolrCore changed = cc.getCore("changed");
|
||||
try {
|
||||
try (SolrCore changed = cc.getCore("changed")) {
|
||||
|
||||
// add some documents
|
||||
addDoc(changed, "id", "1", "which", "15", "text", "some stuff with which");
|
||||
|
@ -98,7 +97,6 @@ public class ChangedSchemaMergeTest extends SolrTestCaseJ4 {
|
|||
changed.getUpdateHandler().commit(new CommitUpdateCommand(req, false));
|
||||
changed.getUpdateHandler().commit(new CommitUpdateCommand(req, true));
|
||||
} finally {
|
||||
if (changed != null) changed.close();
|
||||
if (cc != null) cc.shutdown();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@ package org.apache.solr.schema;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.lucene.index.AtomicReader;
|
||||
import org.apache.lucene.index.FieldInfo.DocValuesType;
|
||||
import org.apache.lucene.index.FieldInfos;
|
||||
|
@ -30,6 +28,8 @@ import org.apache.solr.search.SolrIndexSearcher;
|
|||
import org.apache.solr.util.RefCounted;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@SuppressCodecs({"Lucene40", "Lucene41"})
|
||||
public class DocValuesMultiTest extends SolrTestCaseJ4 {
|
||||
|
||||
|
@ -46,8 +46,7 @@ public class DocValuesMultiTest extends SolrTestCaseJ4 {
|
|||
public void testDocValues() throws IOException {
|
||||
assertU(adoc("id", "1", "floatdv", "4.5", "intdv", "-1", "intdv", "3", "stringdv", "value1", "stringdv", "value2"));
|
||||
assertU(commit());
|
||||
SolrCore core = h.getCoreInc();
|
||||
try {
|
||||
try (SolrCore core = h.getCoreInc()) {
|
||||
final RefCounted<SolrIndexSearcher> searcherRef = core.openNewSearcher(true, true);
|
||||
final SolrIndexSearcher searcher = searcherRef.get();
|
||||
try {
|
||||
|
@ -66,8 +65,6 @@ public class DocValuesMultiTest extends SolrTestCaseJ4 {
|
|||
} finally {
|
||||
searcherRef.decref();
|
||||
}
|
||||
} finally {
|
||||
core.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,8 +17,6 @@ package org.apache.solr.schema;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.lucene.index.AtomicReader;
|
||||
import org.apache.lucene.index.FieldInfo.DocValuesType;
|
||||
import org.apache.lucene.index.FieldInfos;
|
||||
|
@ -29,6 +27,8 @@ import org.apache.solr.search.SolrIndexSearcher;
|
|||
import org.apache.solr.util.RefCounted;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class DocValuesTest extends SolrTestCaseJ4 {
|
||||
|
||||
@BeforeClass
|
||||
|
@ -44,8 +44,7 @@ public class DocValuesTest extends SolrTestCaseJ4 {
|
|||
public void testDocValues() throws IOException {
|
||||
assertU(adoc("id", "1"));
|
||||
assertU(commit());
|
||||
SolrCore core = h.getCoreInc();
|
||||
try {
|
||||
try (SolrCore core = h.getCoreInc()) {
|
||||
final RefCounted<SolrIndexSearcher> searcherRef = core.openNewSearcher(true, true);
|
||||
final SolrIndexSearcher searcher = searcherRef.get();
|
||||
try {
|
||||
|
@ -84,8 +83,6 @@ public class DocValuesTest extends SolrTestCaseJ4 {
|
|||
} finally {
|
||||
searcherRef.decref();
|
||||
}
|
||||
} finally {
|
||||
core.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -67,10 +67,9 @@ public class ModifyConfFileTest extends SolrTestCaseJ4 {
|
|||
public void testConfigWrite() throws Exception {
|
||||
|
||||
final CoreContainer cc = init();
|
||||
try {
|
||||
try (SolrCore core = cc.getCore("core1")) {
|
||||
//final CoreAdminHandler admin = new CoreAdminHandler(cc);
|
||||
|
||||
SolrCore core = cc.getCore("core1");
|
||||
SolrQueryResponse rsp = new SolrQueryResponse();
|
||||
SolrRequestHandler handler = core.getRequestHandler("/admin/fileedit");
|
||||
|
||||
|
@ -147,7 +146,6 @@ public class ModifyConfFileTest extends SolrTestCaseJ4 {
|
|||
|
||||
assertTrue("Velocity should be a directory", (boolean)velocity.get("directory"));
|
||||
|
||||
core.close();
|
||||
} finally {
|
||||
cc.shutdown();
|
||||
if (solrHomeDirectory.exists()) {
|
||||
|
|
|
@ -17,15 +17,6 @@ package org.apache.solr.update;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.apache.lucene.index.LogDocMergePolicy;
|
||||
import org.apache.solr.BaseDistributedSearchTestCase;
|
||||
import org.apache.solr.client.solrj.SolrQuery;
|
||||
|
@ -56,6 +47,14 @@ import org.apache.solr.update.processor.DistributedUpdateProcessor;
|
|||
import org.junit.BeforeClass;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class SolrCmdDistributorTest extends BaseDistributedSearchTestCase {
|
||||
|
||||
private AtomicInteger id = new AtomicInteger();
|
||||
|
@ -279,23 +278,26 @@ public class SolrCmdDistributorTest extends BaseDistributedSearchTestCase {
|
|||
final AtomicInteger commits = new AtomicInteger();
|
||||
for(JettySolrRunner jetty : jettys) {
|
||||
CoreContainer cores = ((SolrDispatchFilter) jetty.getDispatchFilter().getFilter()).getCores();
|
||||
SolrCore core = cores.getCore("collection1");
|
||||
try {
|
||||
try (SolrCore core = cores.getCore("collection1")) {
|
||||
core.getUpdateHandler().registerCommitCallback(new SolrEventListener() {
|
||||
@Override
|
||||
public void init(NamedList args) {}
|
||||
public void init(NamedList args) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postSoftCommit() {}
|
||||
public void postSoftCommit() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postCommit() {
|
||||
commits.incrementAndGet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void newSearcher(SolrIndexSearcher newSearcher,
|
||||
SolrIndexSearcher currentSearcher) {}
|
||||
SolrIndexSearcher currentSearcher) {
|
||||
}
|
||||
});
|
||||
} finally {
|
||||
core.close();
|
||||
}
|
||||
}
|
||||
params = new ModifiableSolrParams();
|
||||
|
|
|
@ -58,9 +58,8 @@ public class MergeIndexesEmbeddedTest extends MergeIndexesExampleTestBase {
|
|||
|
||||
@Override
|
||||
protected String getIndexDirCore1() {
|
||||
SolrCore core1 = cores.getCore("core1");
|
||||
String indexDir = core1.getIndexDir();
|
||||
core1.close();
|
||||
return indexDir;
|
||||
try (SolrCore core1 = cores.getCore("core1")) {
|
||||
return core1.getIndexDir();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,15 +85,9 @@ public class TestCoreAdmin extends AbstractEmbeddedSolrServerTestCase {
|
|||
CoreAdminResponse response = req.process(server);
|
||||
assertThat((String) response.getResponse().get("core"), is("corewithconfigset"));
|
||||
|
||||
SolrCore core = null;
|
||||
try {
|
||||
core = cores.getCore("corewithconfigset");
|
||||
try (SolrCore core = cores.getCore("corewithconfigset")) {
|
||||
assertThat(core, is(notNullValue()));
|
||||
}
|
||||
finally {
|
||||
if (core != null)
|
||||
core.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -135,23 +129,19 @@ public class TestCoreAdmin extends AbstractEmbeddedSolrServerTestCase {
|
|||
|
||||
// Show that the newly-created core has values for load on startup and transient different than defaults due to the
|
||||
// above.
|
||||
|
||||
SolrCore coreProveIt = cores.getCore("collection1");
|
||||
SolrCore core = cores.getCore("newcore");
|
||||
|
||||
assertTrue(core.getCoreDescriptor().isTransient());
|
||||
assertFalse(coreProveIt.getCoreDescriptor().isTransient());
|
||||
|
||||
assertFalse(core.getCoreDescriptor().isLoadOnStartup());
|
||||
assertTrue(coreProveIt.getCoreDescriptor().isLoadOnStartup());
|
||||
|
||||
File logDir;
|
||||
try {
|
||||
try (SolrCore coreProveIt = cores.getCore("collection1");
|
||||
SolrCore core = cores.getCore("newcore")) {
|
||||
|
||||
assertTrue(core.getCoreDescriptor().isTransient());
|
||||
assertFalse(coreProveIt.getCoreDescriptor().isTransient());
|
||||
|
||||
assertFalse(core.getCoreDescriptor().isLoadOnStartup());
|
||||
assertTrue(coreProveIt.getCoreDescriptor().isLoadOnStartup());
|
||||
|
||||
logDir = new File(core.getUpdateHandler().getUpdateLog().getLogDir());
|
||||
} finally {
|
||||
coreProveIt.close();
|
||||
core.close();
|
||||
}
|
||||
|
||||
assertEquals(new File(dataDir, "ulog" + File.separator + "tlog").getAbsolutePath(), logDir.getAbsolutePath());
|
||||
server.shutdown();
|
||||
|
||||
|
|
|
@ -17,15 +17,6 @@ package org.apache.solr.cloud;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.solr.client.solrj.SolrServer;
|
||||
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
|
||||
|
@ -43,6 +34,14 @@ import org.eclipse.jetty.servlet.FilterHolder;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* The monkey can stop random or specific jetties used with SolrCloud.
|
||||
*
|
||||
|
@ -381,19 +380,17 @@ public class ChaosMonkey {
|
|||
monkeyLog("selected jetty not running correctly - skip");
|
||||
return null;
|
||||
}
|
||||
SolrCore core = cores.getCore(leader.getStr(ZkStateReader.CORE_NAME_PROP));
|
||||
if (core == null) {
|
||||
monkeyLog("selected jetty not running correctly - skip");
|
||||
return null;
|
||||
}
|
||||
|
||||
// cluster state can be stale - also go by our 'near real-time' is leader prop
|
||||
boolean rtIsLeader;
|
||||
try {
|
||||
try (SolrCore core = cores.getCore(leader.getStr(ZkStateReader.CORE_NAME_PROP))) {
|
||||
if (core == null) {
|
||||
monkeyLog("selected jetty not running correctly - skip");
|
||||
return null;
|
||||
}
|
||||
rtIsLeader = core.getCoreDescriptor().getCloudDescriptor().isLeader();
|
||||
} finally {
|
||||
core.close();
|
||||
}
|
||||
|
||||
|
||||
boolean isLeader = leader.getStr(ZkStateReader.NODE_NAME_PROP).equals(jetties.get(index).nodeName)
|
||||
|| rtIsLeader;
|
||||
if (!aggressivelyKillLeaders && isLeader) {
|
||||
|
|
|
@ -232,22 +232,19 @@ public class TestHarness extends BaseTestHarness {
|
|||
* @return The XML response to the update
|
||||
*/
|
||||
public String update(String xml) {
|
||||
SolrCore core = getCoreInc();
|
||||
DirectSolrConnection connection = new DirectSolrConnection(core);
|
||||
SolrRequestHandler handler = core.getRequestHandler("/update");
|
||||
// prefer the handler mapped to /update, but use our generic backup handler
|
||||
// if that lookup fails
|
||||
if (handler == null) {
|
||||
handler = updater;
|
||||
}
|
||||
try {
|
||||
try (SolrCore core = getCoreInc()) {
|
||||
DirectSolrConnection connection = new DirectSolrConnection(core);
|
||||
SolrRequestHandler handler = core.getRequestHandler("/update");
|
||||
// prefer the handler mapped to /update, but use our generic backup handler
|
||||
// if that lookup fails
|
||||
if (handler == null) {
|
||||
handler = updater;
|
||||
}
|
||||
return connection.request(handler, null, xml);
|
||||
} catch (SolrException e) {
|
||||
throw (SolrException)e;
|
||||
} catch (Exception e) {
|
||||
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
|
||||
} finally {
|
||||
core.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -292,8 +289,7 @@ public class TestHarness extends BaseTestHarness {
|
|||
* @see LocalSolrQueryRequest
|
||||
*/
|
||||
public String query(String handler, SolrQueryRequest req) throws Exception {
|
||||
SolrCore core = getCoreInc();
|
||||
try {
|
||||
try (SolrCore core = getCoreInc()) {
|
||||
SolrQueryResponse rsp = new SolrQueryResponse();
|
||||
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
|
||||
core.execute(core.getRequestHandler(handler),req,rsp);
|
||||
|
@ -310,23 +306,19 @@ public class TestHarness extends BaseTestHarness {
|
|||
} finally {
|
||||
req.close();
|
||||
SolrRequestInfo.clearRequestInfo();
|
||||
core.close();
|
||||
}
|
||||
}
|
||||
|
||||
/** It is the users responsibility to close the request object when done with it.
|
||||
* This method does not set/clear SolrRequestInfo */
|
||||
public SolrQueryResponse queryAndResponse(String handler, SolrQueryRequest req) throws Exception {
|
||||
SolrCore core = getCoreInc();
|
||||
try {
|
||||
try (SolrCore core = getCoreInc()) {
|
||||
SolrQueryResponse rsp = new SolrQueryResponse();
|
||||
core.execute(core.getRequestHandler(handler),req,rsp);
|
||||
core.execute(core.getRequestHandler(handler), req, rsp);
|
||||
if (rsp.getException() != null) {
|
||||
throw rsp.getException();
|
||||
}
|
||||
return rsp;
|
||||
} finally {
|
||||
core.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue