Skip to content

Commit f1622fc

Browse files
authoredAug 25, 2022
Copy situational configuration using a temporary file and mv to improve concurrency (#3359)
* Use mv while updating situational configuration files to improve concurrency
1 parent 552654f commit f1622fc

File tree

3 files changed

+30
-24
lines changed

3 files changed

+30
-24
lines changed
 

‎operator/src/main/resources/scripts/livenessProbe.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
# Copyright (c) 2017, 2021, Oracle and/or its affiliates.
3+
# Copyright (c) 2017, 2022, Oracle and/or its affiliates.
44
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
55

66
# Kubernetes periodically calls this liveness probe script to determine whether
@@ -35,9 +35,9 @@ if [ ! "${DYNAMIC_CONFIG_OVERRIDE:-notset}" = notset ]; then
3535
tgt_file=$tgt_dir/$tgt_file # add back in tgt dir path
3636
[ -f "$tgt_file" ] && [ -z "$(diff $local_fname $tgt_file 2>&1)" ] && continue # nothing changed
3737
trace "Copying file '$local_fname' to '$tgt_file'."
38-
cp $local_fname $tgt_file # TBD ignore any error?
38+
copyIfChanged $local_fname $tgt_file
3939
if [ -O "$tgt_file" ]; then
40-
chmod 770 $tgt_file # TBD ignore any error?
40+
chmod 770 $tgt_file
4141
fi
4242
done
4343
for local_fname in ${tgt_dir}/*.xml ; do

‎operator/src/main/resources/scripts/startServer.sh

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
# Copyright (c) 2017, 2021, Oracle and/or its affiliates.
3+
# Copyright (c) 2017, 2022, Oracle and/or its affiliates.
44
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
55

66
#
@@ -29,25 +29,6 @@ fi
2929
exportInstallHomes
3030

3131
#
32-
# Define helper fn to copy a file only if src & tgt differ
33-
#
34-
35-
function copyIfChanged() {
36-
[ ! -f "${1?}" ] && trace SEVERE "File '$1' not found." && exit 1
37-
if [ ! -f "${2?}" ] || [ ! -z "`diff $1 $2 2>&1`" ]; then
38-
trace "Copying '$1' to '$2'."
39-
cp $1 $2
40-
[ $? -ne 0 ] && trace SEVERE "failed cp $1 $2" && exitOrLoop
41-
if [ -O "$2" ]; then
42-
chmod 770 $2
43-
[ $? -ne 0 ] && trace SEVERE "failed chmod 770 $2" && exitOrLoop
44-
fi
45-
else
46-
trace "Skipping copy of '$1' to '$2' -- these files already match."
47-
fi
48-
}
49-
50-
#
5132
# if the auxiliary image feature is active, verify the mount, and log mount information
5233
#
5334
checkAuxiliaryImage || exitOrLoop

‎operator/src/main/resources/scripts/utils.sh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2017, 2021, Oracle and/or its affiliates.
1+
# Copyright (c) 2017, 2022, Oracle and/or its affiliates.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
set -o pipefail
@@ -17,6 +17,31 @@ source ${SCRIPTPATH}/utils_base.sh
1717
# [ $? -ne 0 ] && echo "[SEVERE] Missing file ${SCRIPTPATH}/utils.sh" && exit 1
1818
#
1919

20+
#
21+
# Define helper fn to copy a file only if src & tgt differ
22+
#
23+
24+
function copyIfChanged() {
25+
[ ! -f "${1?}" ] && trace SEVERE "File '$1' not found." && exit 1
26+
if [ ! -f "${2?}" ] || [ ! -z "`diff $1 $2 2>&1`" ]; then
27+
trace "Copying '$1' to '$2'."
28+
# Copy the source file to a temporary file in the same directory as the target and then
29+
# move the temporary file to the target. This is done because the target file may be read by another
30+
# process during the copy operation, such as can happen for situational configuration files stored in a
31+
# domain home on a persistent volume.
32+
tmp_file=$(mktemp -p $(dirname $2))
33+
cp $1 $tmp_file
34+
mv $tmp_file $2
35+
[ $? -ne 0 ] && trace SEVERE "failed cp $1 $2" && exitOrLoop
36+
if [ -O "$2" ]; then
37+
chmod 770 $2
38+
[ $? -ne 0 ] && trace SEVERE "failed chmod 770 $2" && exitOrLoop
39+
fi
40+
else
41+
trace "Skipping copy of '$1' to '$2' -- these files already match."
42+
fi
43+
}
44+
2045
# exportInstallHomes
2146
# purpose: export MW_HOME, WL_HOME, ORACLE_HOME
2247
# with defaults as needed

0 commit comments

Comments
 (0)