Skip to content

Commit

Permalink
OAK-4044 - eventually remove stale lock files in embedded Solr dataDir
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/oak/trunk@1731908 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
tteofili committed Feb 23, 2016
1 parent 4ca0872 commit de1bfbf
Showing 1 changed file with 24 additions and 18 deletions.
Expand Up @@ -16,13 +16,15 @@
*/
package org.apache.jackrabbit.oak.plugins.index.solr.server;

import javax.annotation.CheckForNull;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import javax.annotation.CheckForNull;

import org.apache.commons.io.FileUtils;
import org.apache.jackrabbit.oak.commons.IOUtils;
import org.apache.jackrabbit.oak.plugins.index.solr.configuration.EmbeddedSolrServerConfiguration;
import org.apache.jackrabbit.oak.plugins.index.solr.configuration.SolrServerConfigurationDefaults;
Expand All @@ -48,8 +50,6 @@ public EmbeddedSolrServerProvider(EmbeddedSolrServerConfiguration solrServerConf
this.solrServerConfiguration = solrServerConfiguration;
}

private SolrServer solrServer;

private SolrServer createSolrServer() throws Exception {

log.info("creating new embedded solr server with config: {}", solrServerConfiguration);
Expand Down Expand Up @@ -174,6 +174,25 @@ private void checkSolrConfiguration(String solrHomePath, String coreName) throws
} else if (!solrCorePathFile.isDirectory()) {
throw new IOException("a non directory file with the specified name already exists for the given Solr core path'" + solrCorePathFile.getAbsolutePath());
}
// clean data dir
File solrDataPathFile = new File(solrHomePathFile + "/" + coreName + "/data/index");
if (solrDataPathFile.exists()) {
log.debug("deleting stale lock files");
File[] locks = solrDataPathFile.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return "write.lock".equals(name);
}
});
log.debug("found {} lock files", locks.length);
// remove eventaul previous lock files (e.g. due to ungraceful shutdown)
if (locks.length > 0) {
for (File f : locks) {
FileUtils.forceDelete(f);
log.debug("deleted {}", f.getAbsolutePath());
}
}
}

// check if the a core with the given coreName exists
String[] files = solrHomePathFile.list();
Expand Down Expand Up @@ -217,12 +236,7 @@ private void copy(String resource, String dir) throws IOException {
@CheckForNull
@Override
public SolrServer getSolrServer() throws Exception {
synchronized (this) {
if (solrServer == null) {
solrServer = createSolrServer();
}
}
return solrServer;
return createSolrServer();
}

@CheckForNull
Expand Down Expand Up @@ -262,14 +276,6 @@ public void shutdown() {

@Override
public void close() throws IOException {
try {
synchronized (this) {
if (solrServer != null) {
solrServer.shutdown();
}
}
} catch (Exception e) {
// do nothing
}
// do nothing
}
}

0 comments on commit de1bfbf

Please sign in to comment.