-
Notifications
You must be signed in to change notification settings - Fork 218
Copy situational configuration using a temporary file and mv to improve concurrency #3359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/bin/bash | ||
|
||
# Copyright (c) 2017, 2021, Oracle and/or its affiliates. | ||
# Copyright (c) 2017, 2022, Oracle and/or its affiliates. | ||
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. | ||
|
||
# Kubernetes periodically calls this liveness probe script to determine whether | ||
|
@@ -35,9 +35,9 @@ if [ ! "${DYNAMIC_CONFIG_OVERRIDE:-notset}" = notset ]; then | |
tgt_file=$tgt_dir/$tgt_file # add back in tgt dir path | ||
[ -f "$tgt_file" ] && [ -z "$(diff $local_fname $tgt_file 2>&1)" ] && continue # nothing changed | ||
trace "Copying file '$local_fname' to '$tgt_file'." | ||
cp $local_fname $tgt_file # TBD ignore any error? | ||
copyIfChanged $local_fname $tgt_file | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that "copyIfChanged" exits with SEVERE if the copy or chmod fails. My assumption is that's the original reason why the function wasn't originally used here. Is this something we want to happen in the livenessprobe? IIRC, its copy was supposed to be more of a 'best effort'. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'm okay with the liveness probe failing and the server pod restarting when this copy fails. The other choice is that the server continues running with the old configuration for an unknown amount of time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fine by me. |
||
if [ -O "$tgt_file" ]; then | ||
chmod 770 $tgt_file # TBD ignore any error? | ||
chmod 770 $tgt_file | ||
fi | ||
done | ||
for local_fname in ${tgt_dir}/*.xml ; do | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright (c) 2017, 2021, Oracle and/or its affiliates. | ||
# Copyright (c) 2017, 2022, Oracle and/or its affiliates. | ||
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. | ||
|
||
set -o pipefail | ||
|
@@ -17,6 +17,31 @@ source ${SCRIPTPATH}/utils_base.sh | |
# [ $? -ne 0 ] && echo "[SEVERE] Missing file ${SCRIPTPATH}/utils.sh" && exit 1 | ||
# | ||
|
||
# | ||
# Define helper fn to copy a file only if src & tgt differ | ||
# | ||
|
||
function copyIfChanged() { | ||
[ ! -f "${1?}" ] && trace SEVERE "File '$1' not found." && exit 1 | ||
if [ ! -f "${2?}" ] || [ ! -z "`diff $1 $2 2>&1`" ]; then | ||
trace "Copying '$1' to '$2'." | ||
# Copy the source file to a temporary file in the same directory as the target and then | ||
# move the temporary file to the target. This is done because the target file may be read by another | ||
# process during the copy operation, such as can happen for situational configuration files stored in a | ||
# domain home on a persistent volume. | ||
tmp_file=$(mktemp -p $(dirname $2)) | ||
cp $1 $tmp_file | ||
mv $tmp_file $2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor comment: Copying to a tmp file and then moving the file is a little subtle. Perhaps add a comment about why we're doing this? |
||
[ $? -ne 0 ] && trace SEVERE "failed cp $1 $2" && exitOrLoop | ||
if [ -O "$2" ]; then | ||
chmod 770 $2 | ||
[ $? -ne 0 ] && trace SEVERE "failed chmod 770 $2" && exitOrLoop | ||
fi | ||
else | ||
trace "Skipping copy of '$1' to '$2' -- these files already match." | ||
fi | ||
} | ||
|
||
# exportInstallHomes | ||
# purpose: export MW_HOME, WL_HOME, ORACLE_HOME | ||
# with defaults as needed | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comment:
The 'copyIfChanged' looks like it already contains the diff/continue logic on lines 36 & the chmod logic on lines 39,40, and 41. I think you can you go ahead and delete these lines.
On the other hand, copyIfChanged is a little talkative - it traces even when it decides to skip the copy. This might be a little distracting since the liveness probe is frequently invoked.