fix for solr write.lock after mode change http://mantis.tokeek.de/view.php?id=686

The embedded core holds a lock on the index and must be closed. Earlier commit
comment states that core should be closed with solr instance instead on close 
of connector.
Adjusted the InstanceMirror.close() to take care of closing the embedded 
instance to release the lock.
In 2 routines of fulltext this was already explicite implemented (disconnectLocalSolr).
Now this disconnect is part of the InstanceMirror.close().
This commit is contained in:
reger 2016-09-22 00:16:22 +02:00
parent 11786457b7
commit 330768c8a2
3 changed files with 16 additions and 7 deletions

View File

@ -96,11 +96,18 @@ public class InstanceMirror {
this.remoteSolrInstance = null;
}
/**
* Close this instance and it's connectors and cores
*/
public synchronized void close() {
Set<SolrConnector> connectors = new HashSet<SolrConnector>();
connectors.addAll(this.mirrorConnectorCache.values());
for (SolrConnector connector: connectors) connector.close();
this.mirrorConnectorCache.clear();
// solr core of embedded instance only closed by explicite closing the instance.
// on mode switches a reopen of a core fails if instance did not close the core see http://mantis.tokeek.de/view.php?id=686 which this change solves.
// (and a other alternative to deal with the issue)
disconnectEmbedded();
}
public String getDefaultCoreName() {

View File

@ -577,7 +577,7 @@ public final class Fulltext {
EmbeddedInstance esc = this.solrInstances.getEmbedded();
File storagePath = esc.getContainerPath();
synchronized (this.solrInstances) {
this.disconnectLocalSolr();
// this.disconnectLocalSolr(); // moved to (InstanceMirror) sorlInstances.close()
this.solrInstances.close();
try {
ZIPReader.unzip(solrDumpZipFile, storagePath);
@ -610,7 +610,7 @@ public final class Fulltext {
public void rebootSolr() {
synchronized (this.solrInstances) {
this.disconnectLocalSolr();
this.solrInstances.close();
// this.solrInstances.close(); // moved to (InstanceMirror) sorlInstances.close()
this.solrInstances = new InstanceMirror();
try {
this.connectLocalSolr();

View File

@ -20,7 +20,7 @@ import org.junit.BeforeClass;
public class EmbeddedSolrConnectorTest {
static EmbeddedSolrConnector solr;
static EmbeddedInstance localCollectionInstance;
public EmbeddedSolrConnectorTest() {
}
@ -35,7 +35,7 @@ public class EmbeddedSolrConnectorTest {
storage.mkdirs();
System.out.println("setup EmeddedSolrConnector using config dir: " + solr_config.getAbsolutePath());
try {
EmbeddedInstance localCollectionInstance = new EmbeddedInstance(solr_config, storage, CollectionSchema.CORE_NAME, new String[]{CollectionSchema.CORE_NAME, WebgraphSchema.CORE_NAME});
localCollectionInstance = new EmbeddedInstance(solr_config, storage, CollectionSchema.CORE_NAME, new String[]{CollectionSchema.CORE_NAME, WebgraphSchema.CORE_NAME});
solr = new EmbeddedSolrConnector(localCollectionInstance);
solr.clear(); // delete all documents in index (for clean testing)
} catch (final IOException ex) {
@ -45,7 +45,7 @@ public class EmbeddedSolrConnectorTest {
@AfterClass
public static void finalizeTesting() {
solr.close();
localCollectionInstance.close();
}
/**
@ -179,9 +179,11 @@ public class EmbeddedSolrConnectorTest {
* and debug option for EmbeddedSolrConnector.close() (cause this.core.close())
*/
@Test
public void testClose() {
public void testClose() throws Throwable {
System.out.println("-close "+solr.toString());
solr.close();
// we must close the instance to free all resources instead of only closing the connector
// solr.close();
localCollectionInstance.close();
System.out.println("+reopen "+solr.toString());
initTesting();