SOLR-4203: empty the tlog dir without instantiating an updatelog

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1422746 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2012-12-17 03:16:22 +00:00
parent 099a5dcb78
commit 0a73b63883
2 changed files with 20 additions and 13 deletions

View File

@ -18,10 +18,10 @@
package org.apache.solr.update;
import java.io.File;
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;
@ -74,8 +74,7 @@ public abstract class UpdateHandler implements SolrInfoMBean {
}
private void initLog() {
PluginInfo ulogPluginInfo = core.getSolrConfig().getPluginInfo(UpdateLog.class.getName());
private void initLog(PluginInfo ulogPluginInfo) {
if (ulogPluginInfo != null && ulogPluginInfo.isEnabled()) {
ulog = new UpdateLog();
ulog.init(ulogPluginInfo);
@ -85,11 +84,16 @@ public abstract class UpdateHandler implements SolrInfoMBean {
}
// not thread safe - for startup
protected void clearLog() throws IOException {
private void clearLog(PluginInfo ulogPluginInfo) {
if (ulog != null) {
ulog.close(false, true);
//FileUtils.deleteDirectory(ulog.getLogDir());
initLog();
String[] files = UpdateLog.getLogList(UpdateLog.getTlogDir(ulogPluginInfo));
for (String file : files) {
File f = new File(file);
boolean s = f.delete();
if (!s) {
log.error("Could not remove tlog file:" + f);
}
}
}
}
@ -117,14 +121,11 @@ public abstract class UpdateHandler implements SolrInfoMBean {
idField = schema.getUniqueKeyField();
idFieldType = idField!=null ? idField.getType() : null;
parseEventListeners();
initLog();
PluginInfo ulogPluginInfo = core.getSolrConfig().getPluginInfo(UpdateLog.class.getName());
if (!core.isReloaded() && !core.getDirectoryFactory().isPersistent()) {
try {
clearLog();
} catch (IOException e) {
throw new RuntimeException(e);
}
clearLog(ulogPluginInfo);
}
initLog(ulogPluginInfo);
}
/**

View File

@ -1394,6 +1394,12 @@ public class UpdateLog implements PluginInfoInitialized {
}
}
}
public static File getTlogDir(PluginInfo info) {
String dataDir = (String)info.initArgs.get("dir");
return new File(dataDir, TLOG_NAME);
}
}