Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge pull request #562 from zanata/skipLockCheckUnlessNFS
Browse files Browse the repository at this point in the history
Allow Zanata to start even if Lucene lock files are found
  • Loading branch information
seanf committed Oct 21, 2014
2 parents 9ea87d5 + 1324521 commit cc2d7a5
Showing 1 changed file with 36 additions and 10 deletions.
46 changes: 36 additions & 10 deletions zanata-war/src/main/java/org/zanata/ZanataInit.java
Expand Up @@ -22,7 +22,12 @@

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.Proxy;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Properties;
import java.util.jar.Attributes;
Expand All @@ -38,7 +43,6 @@
import javax.naming.NamingException;
import javax.servlet.ServletContext;

import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -155,25 +159,47 @@ public void initZanata() throws Exception {
}

private void checkLuceneLocks(File indexDir)
throws ZanataInitializationException {
throws IOException, ZanataInitializationException {
if (!indexDir.exists()) {
if (indexDir.mkdirs()) {
log.info("Created lucene index directory.");
} else {
log.warn("Could not create lucene index directory");
}
}
if (mightUseNFS(indexDir)) {
// we don't trust Lucene's NativeFSLockFactory for NFS locks
String docURL = "http://docs.jboss.org/hibernate/search/4.4/reference/en-US/html/search-configuration.html#search-configuration-directory-lockfactories";
log.warn("The Hibernate Search index dir '{}' might be NFS. " +
"NativeFSLockFactory might not be safe: {}" +
indexDir, docURL);
}
Collection<File> lockFiles =
FileUtils.listFiles(indexDir, new String[] { "lock" }, true);
Collection<String> lockedDirs = Lists.newArrayList();
for (File f : lockFiles) {
lockedDirs.add(f.getParent());
}
if (!lockFiles.isEmpty()) {
log.error("Lucene lock files found. Check if Zanata is already running. Otherwise, Zanata was not shut down cleanly: delete the locked directories: "
+ lockedDirs);
throw new ZanataInitializationException("Found lock files: "
+ lockFiles);
log.info("Lucene lock files found: {}", lockFiles);
}
}

/**
* Returns true if any of the files appear to be stored in NFS (or we
* can't tell).
*/
private boolean mightUseNFS(File... files) {
try {
FileSystem fileSystem = FileSystems.getDefault();
for (File file: files) {
Path path = fileSystem.getPath(file.getAbsolutePath());
String fileStoreType = Files.getFileStore(path).type();
if (fileStoreType.toLowerCase().contains("nfs")) {
return true;
}
}
return false;
} catch (IOException e) {
log.warn(e.toString(), e);
// assume the worst case
return true;
}
}

Expand Down

0 comments on commit cc2d7a5

Please sign in to comment.