SOLR-4203: An ephemeral directory implementation should cause the transaction log to be ignored on startup.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1422399 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2012-12-15 22:58:01 +00:00
parent 2fb382ee07
commit 4d32c5d6bc
4 changed files with 32 additions and 2 deletions

View File

@ -91,7 +91,7 @@ public abstract class DirectoryFactory implements NamedListInitializedPlugin,
/**
* This remove is special in that it may be called even after
* the factory has been closed. Remove only makes sense for
* peristent directory factories.
* persistent directory factories.
*
* @param path to remove
* @throws IOException If there is a low-level I/O error.
@ -140,6 +140,12 @@ public abstract class DirectoryFactory implements NamedListInitializedPlugin,
*/
public abstract void incRef(Directory directory);
/**
* @return true if data is kept after close.
*/
public abstract boolean isPersistent();
/**
* Releases the Directory so that it may be closed when it is no longer
* referenced.

View File

@ -44,6 +44,10 @@ public abstract class EphemeralDirectoryFactory extends CachingDirectoryFactory
}
}
public boolean isPersistent() {
return false;
}
@Override
public void remove(Directory dir) throws IOException {
// ram dir does not persist its dir anywhere

View File

@ -44,6 +44,10 @@ public class StandardDirectoryFactory extends CachingDirectoryFactory {
return new File(path).getCanonicalPath();
}
public boolean isPersistent() {
return true;
}
@Override
public void remove(Directory dir) throws IOException {
CacheValue val = byDirectoryCache.get(dir);

View File

@ -21,6 +21,7 @@ package org.apache.solr.update;
import java.io.IOException;
import java.util.Vector;
import org.apache.commons.io.FileUtils;
import org.apache.solr.core.PluginInfo;
import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrEventListener;
@ -53,7 +54,7 @@ public abstract class UpdateHandler implements SolrInfoMBean {
protected Vector<SolrEventListener> softCommitCallbacks = new Vector<SolrEventListener>();
protected Vector<SolrEventListener> optimizeCallbacks = new Vector<SolrEventListener>();
protected UpdateLog ulog;
protected volatile UpdateLog ulog;
private void parseEventListeners() {
final Class<SolrEventListener> clazz = SolrEventListener.class;
@ -83,6 +84,14 @@ public abstract class UpdateHandler implements SolrInfoMBean {
}
}
// not thread safe - for startup
protected void clearLog() throws IOException {
if (ulog != null) {
ulog.close(false);
FileUtils.deleteDirectory(ulog.getLogDir());
initLog();
}
}
protected void callPostCommitCallbacks() {
for (SolrEventListener listener : commitCallbacks) {
@ -109,6 +118,13 @@ public abstract class UpdateHandler implements SolrInfoMBean {
idFieldType = idField!=null ? idField.getType() : null;
parseEventListeners();
initLog();
if (!core.getDirectoryFactory().isPersistent()) {
try {
clearLog();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
/**