This is an automated email from the ASF dual-hosted git repository.

chesnay pushed a commit to branch dev-master
in repository https://gitbox.apache.org/repos/asf/flink-docker.git


The following commit(s) were added to refs/heads/dev-master by this push:
     new 39685f4  [FLINK-21034] Refactor jemalloc switch to environment variable
39685f4 is described below

commit 39685f407a787dbb404332384e6ab3457ec216b3
Author: Chesnay Schepler <[email protected]>
AuthorDate: Wed Jan 20 21:32:45 2021 +0100

    [FLINK-21034] Refactor jemalloc switch to environment variable
---
 docker-entrypoint.sh             | 27 ++++++++-------------------
 testing/bin/config.sh            | 24 ++++++++++++++++++++++++
 testing/bin/docker-entrypoint.sh | 37 +++++++++++++++++++++++++++++++++++++
 testing/run_travis_tests.sh      |  2 ++
 testing/testing_lib.sh           |  9 +++++++++
 5 files changed, 80 insertions(+), 19 deletions(-)

diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh
index 65f8fc8..a982a33 100755
--- a/docker-entrypoint.sh
+++ b/docker-entrypoint.sh
@@ -22,7 +22,6 @@ COMMAND_STANDALONE="standalone-job"
 # Deprecated, should be remove in Flink release 1.13
 COMMAND_NATIVE_KUBERNETES="native-k8s"
 COMMAND_HISTORY_SERVER="history-server"
-COMMAND_DISABLE_JEMALLOC="disable-jemalloc"
 
 # If unspecified, the hostname of the container is taken as the JobManager 
address
 JOB_MANAGER_RPC_ADDRESS=${JOB_MANAGER_RPC_ADDRESS:-$(hostname -f)}
@@ -95,40 +94,34 @@ prepare_job_manager_start() {
     envsubst < "${CONF_FILE}" > "${CONF_FILE}.tmp" && mv "${CONF_FILE}.tmp" 
"${CONF_FILE}"
 }
 
-disable_jemalloc_env() {
-  # use nameref '_args' to update the passed 'args' within function
-  local -n _args=$1
-  if [ "${_args[0]}" = ${COMMAND_DISABLE_JEMALLOC} ]; then
-      echo "Disable Jemalloc as the memory allocator"
-      _args=("${_args[@]:1}")
-  else
-      export LD_PRELOAD=$LD_PRELOAD:/usr/lib/x86_64-linux-gnu/libjemalloc.so
-  fi
+maybe_enable_jemalloc() {
+    if [ "${DISABLE_JEMALLOC:-false}" == "false" ]; then
+        export LD_PRELOAD=$LD_PRELOAD:/usr/lib/x86_64-linux-gnu/libjemalloc.so
+    fi
 }
 
+maybe_enable_jemalloc
+
 args=("$@")
 if [ "$1" = "help" ]; then
-    printf "Usage: $(basename "$0") 
(jobmanager|${COMMAND_STANDALONE}|taskmanager|${COMMAND_HISTORY_SERVER}) 
[${COMMAND_DISABLE_JEMALLOC}]\n"
+    printf "Usage: $(basename "$0") 
(jobmanager|${COMMAND_STANDALONE}|taskmanager|${COMMAND_HISTORY_SERVER})\n"
     printf "    Or $(basename "$0") help\n\n"
-    printf "By default, Flink image adopts jemalloc as default memory 
allocator and will disable jemalloc if option '${COMMAND_DISABLE_JEMALLOC}' 
given.\n"
+    printf "By default, Flink image adopts jemalloc as default memory 
allocator. This behavior can be disabled by setting the 'DISABLE_JEMALLOC' 
environment variable to 'true'.\n"
     exit 0
 elif [ "$1" = "jobmanager" ]; then
     args=("${args[@]:1}")
-    disable_jemalloc_env args
 
     prepare_job_manager_start
 
     exec $(drop_privs_cmd) "$FLINK_HOME/bin/jobmanager.sh" start-foreground 
"${args[@]}"
 elif [ "$1" = ${COMMAND_STANDALONE} ]; then
     args=("${args[@]:1}")
-    disable_jemalloc_env args
 
     prepare_job_manager_start
 
     exec $(drop_privs_cmd) "$FLINK_HOME/bin/standalone-job.sh" 
start-foreground "${args[@]}"
 elif [ "$1" = ${COMMAND_HISTORY_SERVER} ]; then
     args=("${args[@]:1}")
-    disable_jemalloc_env args
 
     echo "Starting History Server"
     copy_plugins_if_required
@@ -141,7 +134,6 @@ elif [ "$1" = ${COMMAND_HISTORY_SERVER} ]; then
     exec $(drop_privs_cmd) "$FLINK_HOME/bin/historyserver.sh" start-foreground 
"${args[@]}"
 elif [ "$1" = "taskmanager" ]; then
     args=("${args[@]:1}")
-    disable_jemalloc_env args
 
     echo "Starting Task Manager"
     copy_plugins_if_required
@@ -159,7 +151,6 @@ elif [ "$1" = "taskmanager" ]; then
     exec $(drop_privs_cmd) "$FLINK_HOME/bin/taskmanager.sh" start-foreground 
"${args[@]}"
 elif [ "$1" = "$COMMAND_NATIVE_KUBERNETES" ]; then
     args=("${args[@]:1}")
-    disable_jemalloc_env args
 
     copy_plugins_if_required
 
@@ -173,8 +164,6 @@ fi
 
 args=("${args[@]}")
 
-disable_jemalloc_env args
-
 copy_plugins_if_required
 
 # Set the Flink related environments
diff --git a/testing/bin/config.sh b/testing/bin/config.sh
new file mode 100644
index 0000000..30189b3
--- /dev/null
+++ b/testing/bin/config.sh
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+
+###############################################################################
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+# limitations under the License.
+###############################################################################
+
+# stand-in for the distribution
+constructFlinkClassPath() {
+    echo ""
+}
diff --git a/testing/bin/docker-entrypoint.sh b/testing/bin/docker-entrypoint.sh
new file mode 100755
index 0000000..5df2015
--- /dev/null
+++ b/testing/bin/docker-entrypoint.sh
@@ -0,0 +1,37 @@
+#!/bin/bash -e
+
+###############################################################################
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+# limitations under the License.
+###############################################################################
+
+if ! [ "$1" == "hello" ] || ! [ "$2" == "world" ]; then
+    echo "Incorrect arguments passed through:" "$@"
+    exit 1
+fi
+
+originalLdPreloadSetting=$3
+jemallocDisabled=$4
+
+if [ "$jemallocDisabled" == "true" ] && ! [ "$originalLdPreloadSetting" == 
"$LD_PRELOAD" ]; then
+    echo "jemalloc was not disabled; expected LD_PRELOAD to be 
'$originalLdPreloadSetting' but was '$LD_PRELOAD'"
+    exit 1
+fi
+
+if [ "$jemallocDisabled" == "false" ] && [ "$originalLdPreloadSetting" == 
"$LD_PRELOAD" ]; then
+    echo "jemalloc was disabled; expected LD_PRELOAD to be different than 
'$originalLdPreloadSetting'."
+    exit 1
+fi
diff --git a/testing/run_travis_tests.sh b/testing/run_travis_tests.sh
index 0ee578a..04f093c 100755
--- a/testing/run_travis_tests.sh
+++ b/testing/run_travis_tests.sh
@@ -11,6 +11,8 @@ fi
 
 BRANCH="$TRAVIS_BRANCH"
 
+test_docker_entrypoint
+
 ./add-custom.sh -u 
"https://s3.amazonaws.com/flink-nightly/flink-1.11-SNAPSHOT-bin-hadoop2.tgz"; -n 
test-java8
 
 # test Flink with Java11 image as well
diff --git a/testing/testing_lib.sh b/testing/testing_lib.sh
index f619791..f964950 100644
--- a/testing/testing_lib.sh
+++ b/testing/testing_lib.sh
@@ -244,4 +244,13 @@ function smoke_test_one_image_non_root() {
     internal_smoke_test_images "$dockerfiles" "--user flink"
 }
 
+function test_docker_entrypoint() {
+    export FLINK_HOME=$(pwd)/testing
+
+    originalLdPreloadSetting=$LD_PRELOAD
+
+    ./docker-entrypoint.sh $(pwd)/testing/bin/docker-entrypoint.sh hello world 
"$originalLdPreloadSetting" false
+    DISABLE_JEMALLOC=true ./docker-entrypoint.sh 
$(pwd)/testing/bin/docker-entrypoint.sh hello world "$originalLdPreloadSetting" 
true
+}
+
 # vim: ts=4 sw=4 et

Reply via email to