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

Commit

Permalink
Skip Lucene lock check unless NFS is used
Browse files Browse the repository at this point in the history
  • Loading branch information
seanf committed Aug 19, 2014
1 parent 6ab883a commit 6f8b8cc
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 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 @@ -148,7 +152,7 @@ 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.");
Expand All @@ -158,15 +162,39 @@ private void checkLuceneLocks(File indexDir)
}
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);
// we don't trust Lucene's NativeFSLockFactory for NFS locks
if (anyUsesNFS(lockFiles)) {
log.error(
"Lucene lock files found. Check if Zanata is already " +
"running. Otherwise, Zanata was not shut down " +
"cleanly: delete the locks: "
+ lockFiles);
throw new ZanataInitializationException("Found lock files: "
+ lockFiles);
}
}
}

private boolean anyUsesNFS(Collection<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().startsWith("nfs")) {
return true;
}
}
return false;
} catch (NoClassDefFoundError e) {
log.warn("Unable to load Java 1.7 FileSystem classes: " + e.toString());
// assume the worst case
return true;
} catch (IOException e) {
log.warn(e.toString(), e);
// assume the worst case
return true;
}
}

Expand Down

0 comments on commit 6f8b8cc

Please sign in to comment.