Skip to content

Commit

Permalink
Add parameter to run compactor as root (#3500)
Browse files Browse the repository at this point in the history
Enable this parameter if compactor needs to be executed as root user. Otherwise by default
the compactor runs as the same user as the corfu server.
  • Loading branch information
SravanthiAshokKumar committed Jan 25, 2023
1 parent 11e7987 commit 198b0bb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public class CorfuServer {
+ "[-P <prefix>] [-R <retention>] <port>"
+ "[--compaction-trigger-freq-ms=<compaction_trigger_freq_ms>]"
+ "[--compactor-script=<compactor_script_path>]"
+ "[--compactor-config=<compactor_config_path>]\n"
+ "[--compactor-config=<compactor_config_path>]"
+ "[--run-compactor-as-root]\n"
+ "\n"
+ "Options:\n"
+ " -l <path>, --log-path=<path> "
Expand Down Expand Up @@ -181,6 +182,9 @@ public class CorfuServer {
+ " --compactor-config=<compactor_config_path> "
+ " Path containing the external corfu store compactor config\n"
+ " "
+ " --run-compactor-as-root "
+ " To execute the compactor runner as a root user \n"
+ " "
+ " --management-server-threads=<management_server_threads> "
+ " Number of threads dedicated for the management server [default: 4].\n"
+ " "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -32,6 +33,7 @@ public void invokeCheckpointing() {

String compactorScriptPath = serverContext.getCompactorScriptPath().get();
String compactorConfigPath = serverContext.getCompactorConfig().get();
boolean runCompactorAsRoot = serverContext.getRunCompactorAsRoot();
List<String> endpoint = Arrays.asList(serverContext.getLocalEndpoint().split(":"));
String hostName = endpoint.get(0);
String port = endpoint.get(1);
Expand All @@ -40,8 +42,14 @@ public void invokeCheckpointing() {
shutdown();
}

ProcessBuilder pb = new ProcessBuilder("sudo", compactorScriptPath, "--hostname", hostName, "--port",
port, "--compactorConfig", compactorConfigPath, "--startCheckpointing=true");
List<String> compactorCmd = new ArrayList<>();
if (runCompactorAsRoot) {
compactorCmd.add("sudo");
}
compactorCmd.addAll(Arrays.asList(compactorScriptPath, "--hostname", hostName, "--port",
port, "--compactorConfig", compactorConfigPath, "--startCheckpointing=true"));

ProcessBuilder pb = new ProcessBuilder(compactorCmd);
pb.redirectOutput(ProcessBuilder.Redirect.PIPE);
pb.redirectError(ProcessBuilder.Redirect.PIPE);
this.checkpointerProcess = pb.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ public Optional<String> getCompactorScriptPath() {
return getServerConfig("--compactor-script");
}

public boolean getRunCompactorAsRoot() {
return (boolean) getServerConfig().get("--run-compactor-as-root");
}

public String getPluginConfigFilePath() {
String pluginConfigFilePath = getServerConfig(String.class, "--plugin");
return pluginConfigFilePath == null ? PLUGIN_CONFIG_FILE_PATH : pluginConfigFilePath;
Expand Down

0 comments on commit 198b0bb

Please sign in to comment.