You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by gr...@apache.org on 2016/08/09 13:31:30 UTC

flink git commit: [FLINK-4212] [scripts] Lock PID file when starting daemons

Repository: flink
Updated Branches:
  refs/heads/master 5133c896c -> 46b427fac


[FLINK-4212] [scripts] Lock PID file when starting daemons


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/46b427fa
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/46b427fa
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/46b427fa

Branch: refs/heads/master
Commit: 46b427fac9cfceca7839fc93f06ba758101f4fee
Parents: 5133c89
Author: Greg Hogan <co...@greghogan.com>
Authored: Thu Jul 14 11:55:41 2016 -0400
Committer: Greg Hogan <co...@greghogan.com>
Committed: Tue Aug 9 08:51:02 2016 -0400

----------------------------------------------------------------------
 flink-dist/src/main/flink-bin/bin/flink-daemon.sh | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/46b427fa/flink-dist/src/main/flink-bin/bin/flink-daemon.sh
----------------------------------------------------------------------
diff --git a/flink-dist/src/main/flink-bin/bin/flink-daemon.sh b/flink-dist/src/main/flink-bin/bin/flink-daemon.sh
index 5cd9f60..2230e92 100644
--- a/flink-dist/src/main/flink-bin/bin/flink-daemon.sh
+++ b/flink-dist/src/main/flink-bin/bin/flink-daemon.sh
@@ -58,6 +58,18 @@ pid=$FLINK_PID_DIR/flink-$FLINK_IDENT_STRING-$DAEMON.pid
 
 mkdir -p "$FLINK_PID_DIR"
 
+# Log files for daemons are indexed from the process ID's position in the PID
+# file. The following lock prevents a race condition during daemon startup
+# when multiple daemons read, index, and write to the PID file concurrently.
+# The lock is created on the PID directory since a lock file cannot be safely
+# removed. The daemon is started with the lock closed and the lock remains
+# active in this script until the script exits.
+command -v flock >/dev/null 2>&1
+if [[ $? -eq 0 ]]; then
+    exec 200<"$FLINK_PID_DIR"
+    flock 200
+fi
+
 # Ascending ID depending on number of lines in pid file.
 # This allows us to start multiple daemon of each type.
 id=$([ -f "$pid" ] && echo $(wc -l < $pid) || echo "0")
@@ -101,7 +113,7 @@ case $STARTSTOP in
         fi
 
         echo "Starting $DAEMON daemon on host $HOSTNAME."
-        $JAVA_RUN $JVM_ARGS ${FLINK_ENV_JAVA_OPTS} "${log_setting[@]}" -classpath "`manglePathList "$FLINK_TM_CLASSPATH:$INTERNAL_HADOOP_CLASSPATHS"`" ${CLASS_TO_RUN} "${ARGS[@]}" > "$out" 2>&1 < /dev/null &
+        $JAVA_RUN $JVM_ARGS ${FLINK_ENV_JAVA_OPTS} "${log_setting[@]}" -classpath "`manglePathList "$FLINK_TM_CLASSPATH:$INTERNAL_HADOOP_CLASSPATHS"`" ${CLASS_TO_RUN} "${ARGS[@]}" > "$out" 200<&- 2>&1 < /dev/null &
 
         mypid=$!