Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

Properly lock solrInstances for reboot and restoration of embedded Solr

lucciomanf4676015611e
diff --git a/source/net/yacy/search/index/Fulltext.java b/source/net/yacy/search/index/Fulltext.java
index a4938cb0f..685fe2010 100644
--- a/source/net/yacy/search/index/Fulltext.java
+++ b/source/net/yacy/search/index/Fulltext.java
@@ -40,6 +40,7 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.locks.ReentrantLock;
import java.util.regex.Pattern;
import java.util.zip.Deflater;
import java.util.zip.GZIPOutputStream;
@@ -96,6 +97,10 @@ public final class Fulltext {
private final File archivePath;
private Export exportthread; // will have a export thread assigned if exporter is running
private InstanceMirror solrInstances;
+
+ /** Synchronization lock for solrInstances property */
+ private ReentrantLock solrInstancesLock;
+
private final CollectionConfiguration collectionConfiguration;
private final WebgraphConfiguration webgraphConfiguration;
private boolean writeWebgraph;
@@ -106,6 +111,7 @@ public final class Fulltext {
this.archivePath = archivePath;
this.exportthread = null; // will have a export thread assigned if exporter is running
this.solrInstances = new InstanceMirror();
+ this.solrInstancesLock = new ReentrantLock();
this.collectionConfiguration = collectionConfiguration;
this.webgraphConfiguration = webgraphConfiguration;
this.writeWebgraph = false;
@@ -198,22 +204,35 @@ public final class Fulltext {
}
public EmbeddedInstance getEmbeddedInstance() {
- synchronized (this.solrInstances) {
- if (this.solrInstances.isConnectedEmbedded()) return this.solrInstances.getEmbedded();
+ this.solrInstancesLock.lock();
+ try {
+ if (this.solrInstances.isConnectedEmbedded()) {
+ return this.solrInstances.getEmbedded();
+ }
return null;
+ } finally {
+ this.solrInstancesLock.unlock();
}
}
public SolrConnector getDefaultConnector() {
- synchronized (this.solrInstances) {
+ this.solrInstancesLock.lock();
+ try {
return this.solrInstances.getDefaultMirrorConnector();
+ } finally {
+ this.solrInstancesLock.unlock();
}
}
public SolrConnector getWebgraphConnector() {
- if (!this.writeWebgraph) return null;
- synchronized (this.solrInstances) {
+ if (!this.writeWebgraph) {
+ return null;
+ }
+ this.solrInstancesLock.lock();
+ try {
return this.solrInstances.getGenericMirrorConnector(WebgraphSchema.CORE_NAME);
+ } finally {
+ this.solrInstancesLock.unlock();
}
}
@@ -232,8 +251,11 @@ public final class Fulltext {
}
public void clearLocalSolr() throws IOException {
- if (this.exportthread != null) this.exportthread.interrupt();
- synchronized (this.solrInstances) {
+ if (this.exportthread != null) {
+ this.exportthread.interrupt();
+ }
+ this.solrInstancesLock.lock();
+ try {
EmbeddedInstance instance = this.solrInstances.getEmbedded();
if (instance != null) {
for (String name: instance.getCoreNames()) {
@@ -242,11 +264,14 @@ public final class Fulltext {
this.commit(false);
}
this.solrInstances.clearCaches();
+ } finally {
+ this.solrInstancesLock.unlock();
}
}
public void clearRemoteSolr() throws IOException {
- synchronized (this.solrInstances) {
+ this.solrInstancesLock.lock();
+ try {
ShardInstance instance = this.solrInstances.getRemote();
if (instance != null) {
for (String name: instance.getCoreNames()) {
@@ -254,6 +279,8 @@ public final class Fulltext {
}
}
this.solrInstances.clearCaches();
+ } finally {
+ this.solrInstancesLock.unlock();
}
}
@@ -593,7 +620,8 @@ public final class Fulltext {
}
final File storagePath = esc.getContainerPath();
final File zipOut = new File(this.archivePath, storagePath.getName() + "_" + GenericFormatter.SHORT_DAY_FORMATTER.format() + ".zip");
- synchronized (this.solrInstances) {
+ this.solrInstancesLock.lock();
+ try {
this.disconnectLocalSolr();
try {
ZIPWriter.zip(storagePath, zipOut);
@@ -606,6 +634,8 @@ public final class Fulltext {
ConcurrentLog.logException(e);
}
}
+ } finally {
+ this.solrInstancesLock.unlock();
}
return zipOut;
}
@@ -621,7 +651,8 @@ public final class Fulltext {
throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, "No embedded Solr available.");
}
final File storagePath = esc.getContainerPath();
- synchronized (this.solrInstances) {
+ this.solrInstancesLock.lock();
+ try {
// this.disconnectLocalSolr(); // moved to (InstanceMirror) sorlInstances.close()
this.solrInstances.close();
try {
@@ -636,6 +667,8 @@ public final class Fulltext {
ConcurrentLog.logException(e);
}
}
+ } finally {
+ this.solrInstancesLock.unlock();
}
}
@@ -654,7 +687,8 @@ public final class Fulltext {
* Please check before that the local embedded Solr is enabled and no external remote Solr is attached.
*/
public void rebootEmbeddedLocalSolr() {
- synchronized (this.solrInstances) {
+ this.solrInstancesLock.lock();
+ try {
this.disconnectLocalSolr();
// this.solrInstances.close(); // moved to (InstanceMirror) sorlInstances.close()
this.solrInstances = new InstanceMirror();
@@ -663,6 +697,8 @@ public final class Fulltext {
} catch (final IOException e) {
ConcurrentLog.logException(e);
}
+ } finally {
+ this.solrInstancesLock.unlock();
}
}