Skip to content

Commit b0c0297

Browse files
committed
Rework peon.sh
1 parent 249c8dd commit b0c0297

File tree

4 files changed

+13
-21
lines changed

4 files changed

+13
-21
lines changed

distribution/docker/peon.sh

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@
3939
# - DRUID_CONFIG_${service} -- full path to a file for druid 'service' properties
4040

4141
# This script is very similar to druid.sh, used exclusively for the kubernetes-overlord-extension.
42+
# Specifically, it is used by K8sTaskAdapter and PodTemplateTaskAdapter to start up Peon tasks.
4243

4344
set -e
4445
SERVICE="overlord"
4546

46-
echo "$(date -Is) startup service $SERVICE"
47+
echo "$(date -Is) startup service peon"
4748

4849
# We put all the config in /tmp/conf to allow for a
4950
# read-only root filesystem
@@ -159,15 +160,12 @@ fi
159160

160161
# take the ${TASK_JSON} environment variable and base64 decode, unzip and throw it in ${TASK_DIR}/task.json.
161162
# If TASK_JSON is not set, CliPeon will pull the task.json file from deep storage.
162-
if [ -n "$TASK_ID" ]; then
163-
# In the case of running with Kubernetes, see https://github.com/apache/druid/pull/18206 for more information.
164-
mkdir -p ${TASK_DIR}/${TASK_ID}; [ -n "$TASK_JSON" ] && echo ${TASK_JSON} | base64 -d | gzip -d > ${TASK_DIR}/${TASK_ID}/task.json;
165-
else
166-
mkdir -p ${TASK_DIR}; [ -n "$TASK_JSON" ] && echo ${TASK_JSON} | base64 -d | gzip -d > ${TASK_DIR}/task.json;
167-
fi
163+
mkdir -p ${TASK_DIR}; [ -n "$TASK_JSON" ] && echo ${TASK_JSON} | base64 -d | gzip -d > ${TASK_DIR}/task.json;
168164

165+
# Start peon using CliPeon, with variables `Main internal peon TASK_ID ATTEMPT_ID`
169166
if [ -n "$TASK_ID" ]; then
170-
exec bin/run-java ${JAVA_OPTS} -cp $COMMON_CONF_DIR:$SERVICE_CONF_DIR:lib/*: org.apache.druid.cli.Main internal peon --taskId "${TASK_ID}" "$@"
167+
# TASK_ID is only set from PodTemplateTaskAdapter
168+
exec bin/run-java ${JAVA_OPTS} -cp $COMMON_CONF_DIR:$SERVICE_CONF_DIR:lib/*: org.apache.druid.cli.Main internal peon "${TASK_DIR}" 1 --taskId "${TASK_ID}" "$@"
171169
else
172-
exec bin/run-java ${JAVA_OPTS} -cp $COMMON_CONF_DIR:$SERVICE_CONF_DIR:lib/*: org.apache.druid.cli.Main internal peon "$@"
170+
exec bin/run-java ${JAVA_OPTS} -cp $COMMON_CONF_DIR:$SERVICE_CONF_DIR:lib/*: org.apache.druid.cli.Main internal peon "${TASK_DIR}" 1 "$@"
173171
fi

extensions-core/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/taskadapter/K8sTaskAdapter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public Job fromTask(Task task) throws IOException
124124
PeonCommandContext context = new PeonCommandContext(
125125
generateCommand(task),
126126
javaOpts(task),
127-
taskConfig.getBaseTaskDir(),
127+
taskConfig.getTaskDir(task.getId()),
128128
taskRunnerConfig.getCpuCoreInMicro(),
129129
node.isEnableTlsPort()
130130
);
@@ -408,6 +408,9 @@ private List<String> javaOpts(Task task)
408408
);
409409
}
410410

411+
javaOpts.add(org.apache.druid.java.util.common.StringUtils.format(
412+
"-Ddruid.indexer.task.baseTaskDir=%s", taskConfig.getBaseTaskDir().getAbsolutePath()
413+
));
411414
javaOpts.add(org.apache.druid.java.util.common.StringUtils.format("-Ddruid.port=%d", DruidK8sConstants.PORT));
412415
javaOpts.add(org.apache.druid.java.util.common.StringUtils.format(
413416
"-Ddruid.plaintextPort=%d",
@@ -435,8 +438,6 @@ private List<String> generateCommand(Task task)
435438
{
436439
final List<String> command = new ArrayList<>();
437440
command.add("/peon.sh");
438-
command.add(taskConfig.getBaseTaskDir().getAbsolutePath());
439-
command.add("1"); // the attemptId is always 1, we never run the task twice on the same pod.
440441

441442
String nodeType = task.getNodeType();
442443
if (nodeType != null) {

extensions-core/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/taskadapter/PodTemplateTaskAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ private Collection<EnvVar> getEnv(Task task) throws IOException
217217
List<EnvVar> envVars = Lists.newArrayList(
218218
new EnvVarBuilder()
219219
.withName(DruidK8sConstants.TASK_DIR_ENV)
220-
.withValue(taskConfig.getBaseDir())
220+
.withValue(taskConfig.getTaskDir(task.getId()).getAbsolutePath())
221221
.build(),
222222
new EnvVarBuilder()
223223
.withName(DruidK8sConstants.TASK_ID_ENV)

services/src/main/java/org/apache/druid/cli/CliPeon.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,6 @@ public void configure(Binder binder)
235235

236236
taskDirPath = taskAndStatusFile.get(0);
237237
attemptId = taskAndStatusFile.get(1);
238-
boolean isK8sMode = properties.getProperty("druid.indexer.runner.type", "").contains("k8s");
239-
if (isK8sMode) {
240-
// Need to connect task directory to include taskId.
241-
// This is to ensure task reports, status files will be written and read from the correct path.
242-
taskDirPath = Paths.get(taskDirPath, taskId).toString();
243-
}
244238

245239
binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/peon");
246240
binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0);
@@ -263,11 +257,10 @@ public void configure(Binder binder)
263257
.setStatusFile(Paths.get(taskDirPath, "attempt", attemptId, "status.json").toFile());
264258

265259
binder.bind(Properties.class).toInstance(properties);
266-
if (isK8sMode) {
260+
if (properties.getProperty("druid.indexer.runner.type", "").contains("k8s")) {
267261
log.info("Running peon in k8s mode");
268262
executorLifecycleConfig.setParentStreamDefined(false);
269263
}
270-
log.info("Attempt[%s] at Running peon task in taskDirPath[%s]", attemptId, taskDirPath);
271264

272265
binder.bind(ExecutorLifecycleConfig.class).toInstance(executorLifecycleConfig);
273266

0 commit comments

Comments
 (0)