Skip to content

Commit

Permalink
fix for solr write.lock after mode change http://mantis.tokeek.de/vie…
Browse files Browse the repository at this point in the history
…w.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().
  • Loading branch information
reger committed Sep 21, 2016
1 parent 1178645 commit 330768c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Expand Up @@ -96,11 +96,18 @@ public void disconnectRemote() {
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() {
Expand Down
4 changes: 2 additions & 2 deletions source/net/yacy/search/index/Fulltext.java
Expand Up @@ -577,7 +577,7 @@ public void restoreSolr(File solrDumpZipFile) {
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);
Expand Down Expand Up @@ -610,7 +610,7 @@ public void optimize(final int size) {
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();
Expand Down
Expand Up @@ -20,7 +20,7 @@
public class EmbeddedSolrConnectorTest {

static EmbeddedSolrConnector solr;

static EmbeddedInstance localCollectionInstance;
public EmbeddedSolrConnectorTest() {
}

Expand All @@ -35,7 +35,7 @@ public static void initTesting() {
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) {
Expand All @@ -45,7 +45,7 @@ public static void initTesting() {

@AfterClass
public static void finalizeTesting() {
solr.close();
localCollectionInstance.close();
}

/**
Expand Down Expand Up @@ -179,9 +179,11 @@ public void testUdate_withMultivaluedDateField() throws SolrException, IOExcepti
* 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();
Expand Down

0 comments on commit 330768c

Please sign in to comment.