Skip to content

Commit

Permalink
SOLR-16962: Restore ability to configure tlog directory (#183)
Browse files Browse the repository at this point in the history
* Revert "SOLR-16962: Restore ability to configure tlog directory (#132)"

This reverts commit f4cee66.

* SOLR-16962: Restore ability to configure tlog directory

backported from in-process upsteam PR at commit ea8e829

* fix missing import

* remove redundant arg

backported from in-process upsteam PR at commit 794753e
  • Loading branch information
magibney authored Mar 7, 2024
1 parent 66f8f1e commit b146583
Show file tree
Hide file tree
Showing 17 changed files with 302 additions and 188 deletions.
2 changes: 1 addition & 1 deletion solr/core/src/java/org/apache/solr/cloud/ZkController.java
Original file line number Diff line number Diff line change
Expand Up @@ -1769,7 +1769,7 @@ public void publish(
props.put("dataDir", core.getDataDir());
UpdateLog ulog = core.getUpdateHandler().getUpdateLog();
if (ulog != null) {
props.put("ulogDir", ulog.getLogDir());
props.put("ulogDir", ulog.getUlogDir());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.apache.solr.common.params.CoreAdminParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.Utils;
import org.apache.solr.update.UpdateLog;
import org.apache.solr.util.TimeOut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -261,7 +260,7 @@ private void moveHdfsReplica(
SKIP_CREATE_REPLICA_IN_CLUSTER_STATE,
skipCreateReplicaInClusterState,
CoreAdminParams.ULOG_DIR,
ulogDir.substring(0, ulogDir.lastIndexOf(UpdateLog.TLOG_NAME)),
ulogDir,
CoreAdminParams.DATA_DIR,
dataDir,
ZkStateReader.REPLICA_TYPE,
Expand Down
39 changes: 38 additions & 1 deletion solr/core/src/java/org/apache/solr/core/SolrCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
import org.apache.solr.update.SolrCoreState.IndexWriterCloser;
import org.apache.solr.update.SolrIndexWriter;
import org.apache.solr.update.UpdateHandler;
import org.apache.solr.update.UpdateLog;
import org.apache.solr.update.VersionInfo;
import org.apache.solr.update.processor.DistributedUpdateProcessorFactory;
import org.apache.solr.update.processor.LogUpdateProcessorFactory;
Expand Down Expand Up @@ -3319,6 +3320,22 @@ public void unloadOnClose(
log.error(
"Failed to flag data dir for removal for core: {} dir: {}", name, getDataDir(), e);
}
// ulogDir may be outside dataDir and instanceDir, so we have to explicitly ensure it's
// removed; ulog is most closely associated with data, so we bundle it with logic under
// `deleteDataDir`
UpdateHandler uh = getUpdateHandler();
UpdateLog ulog;
if (uh != null && (ulog = uh.getUpdateLog()) != null) {
try {
directoryFactory.remove(ulog.getTlogDir(), true);
} catch (Exception e) {
log.error(
"Failed to flag tlog dir for removal for core: {} dir: {}",
name,
ulog.getTlogDir(),
e);
}
}
}
if (deleteInstanceDir) {
addCloseHook(
Expand All @@ -3344,7 +3361,8 @@ public void postClose(SolrCore core) {
public static void deleteUnloadedCore(
CoreDescriptor cd, boolean deleteDataDir, boolean deleteInstanceDir) {
if (deleteDataDir) {
Path dataDir = cd.getInstanceDir().resolve(cd.getDataDir());
Path instanceDir = cd.getInstanceDir();
Path dataDir = instanceDir.resolve(cd.getDataDir());
try {
PathUtils.deleteDirectory(dataDir);
} catch (IOException e) {
Expand All @@ -3354,6 +3372,25 @@ public static void deleteUnloadedCore(
dataDir.toAbsolutePath(),
e);
}
String ulogDir = cd.getUlogDir();
if (ulogDir != null) {
Path ulogDirPath = instanceDir.resolve(ulogDir);
if (!ulogDirPath.startsWith(dataDir)
&& (!deleteInstanceDir || !ulogDirPath.startsWith(instanceDir))) {
// external ulogDir, we have to remove it explicitly
try {
Path tlogPath =
UpdateLog.ulogToTlogDir(cd.getName(), ulogDirPath, instanceDir, dataDir.toString());
PathUtils.deleteDirectory(tlogPath);
} catch (IOException e) {
log.error(
"Failed to delete external ulog dir for core: {} ulogDir: {}",
cd.getName(),
ulogDirPath,
e);
}
}
}
}
if (deleteInstanceDir) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,7 @@ private void copyTmpConfFiles2Conf(Path tmpconfDir) {
*/
private boolean copyTmpTlogFiles2Tlog(File tmpTlogDir) {
Path tlogDir =
FileSystems.getDefault().getPath(solrCore.getUpdateHandler().getUpdateLog().getLogDir());
FileSystems.getDefault().getPath(solrCore.getUpdateHandler().getUpdateLog().getTlogDir());
Path backupTlogDir =
FileSystems.getDefault()
.getPath(tlogDir.getParent().toAbsolutePath().toString(), tmpTlogDir.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,7 @@ public LocalFsTlogFileStream(SolrParams solrParams) {
@Override
protected Path initFile() {
// if it is a tlog file read from tlog directory
return Path.of(core.getUpdateHandler().getUpdateLog().getLogDir(), tlogFileName);
return Path.of(core.getUpdateHandler().getUpdateLog().getTlogDir(), tlogFileName);
}
}

Expand Down
18 changes: 13 additions & 5 deletions solr/core/src/java/org/apache/solr/update/UpdateHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,24 @@ public UpdateHandler(SolrCore core, UpdateLog updateLog) {
? dirFactory.newDefaultUpdateLog()
: core.getResourceLoader().newInstance(ulogPluginInfo, UpdateLog.class, true);

if (!core.isReloaded() && !dirFactory.isPersistent()) {
ulog.clearLog(core, ulogPluginInfo);
}

if (log.isInfoEnabled()) {
log.info("Using UpdateLog implementation: {}", ulog.getClass().getName());
}
ulog.init(ulogPluginInfo);
ulog.init(this, core);
ulog.initTlogDir(core);

try {
if (!core.isReloaded() && !dirFactory.isPersistent()) {
ulog.clearLog();
}

ulog.init(this, core);
} catch (Throwable t) {
ulog.close(false, false);
throw t;
}
} else {
// `ulog.init(UpdateHandler, SolrCore)` is deferred until the end of subclass ctor.
ulog = updateLog;
}
}
Expand Down
Loading

0 comments on commit b146583

Please sign in to comment.