MT#3963 Execute all db-schema scripts in sequential order sorted by ID revision number

Without this change the following ordering is present:

 3.0:   http://paste.mgm.sipwise.com/show/513/
  vs
 trunk: http://paste.mgm.sipwise.com/show/514/

So /usr/share/ngcp-db-schema/db_scripts/base/0070_not_replicated.up
is executed between 0060_* and 0080_* on ngcp 3.0 but after 6746.up
(the last script without the _not_replicated.up suffix) and
together with all the other *_not_replicated scripts before the
next bunch of scripts (being /usr/share/ngcp-db-schema/db_scripts/diff/).

This adds a short penalty on execution time because we re-run
ngcp-check-rev-applied for the *_not_replicated scripts but it's
the only way to get it right if we want to execute all db-schema
scripts in sequential order sorted by their ID revision number.
mprokop/mt4973_sp2-db
Michael Prokop 12 years ago committed by Michael Prokop
parent 84ff40c0e8
commit 50eb0a078d

@ -107,44 +107,36 @@ apply_revision() {
}
# execute the rev script iff there's no entry for *any* host yet
apply_generic_revs() {
apply_revs() {
[ -n "$1" ] || return 1
revs="$1"
for missing_revision in $(ngcp-check-rev-applied --schema db_schema --revision $revs | awk '/^No match for revision/ {print $5}') ; do
revision_file="$(find /usr/share/ngcp-db-schema/ -name "$missing_revision")"
if [ -r "$revision_file" ] ; then
apply_revision "$revision_file"
else
echo "Warning: missing revision $missing_revision identified but could not find according db-schema file."
fi
done
}
# execute the rev script iff there's no entry for the *current* host yet
apply_host_specific_revs() {
[ -n "$1" ] || return 1
revs="$1"
for missing_revision in $(ngcp-check-rev-applied --schema db_schema --revision $revs --node "$hostname" | awk '/^No match for revision/ {print $5}') ; do
revision_file="$(find /usr/share/ngcp-db-schema/ -name "$missing_revision")"
# execute the rev script iff there's no entry for the *current* host yet
case "$revision_file" in
*_not_replicated.up)
if ngcp-check-rev-applied --schema db_schema --revision $missing_revision --node "$hostname" | grep -q 'already executed' ; then
continue
fi
;;
esac
if [ -r "$revision_file" ] ; then
apply_revision "$revision_file"
else
echo "Warning: missing revision $missing_revision identified but could not find according file."
echo "Warning: missing revision $missing_revision identified but could not find according db-schema file."
fi
done
}
revision_wrapper() {
[ -n "$1" ] || return 1
local host_specific_revs;
local generic_revs;
local revlist
for rev in $* ; do
@ -160,22 +152,23 @@ revision_wrapper() {
case "$revname" in
# the scripts that should be executed on *all* hosts, no matter whether
# they are active or inactive, since the script's content doesn't get replicated
# NOTE: the actual logic is inside the apply_revs to avoid *_not_replicated.up
# scripts being executed independent from the other ones
*_not_replicated.up)
host_specific_revs="$host_specific_revs $(basename $rev)"
revlist="$revlist $(basename $rev)"
;;
*)
if running_on_active_node ; then
echo "Replication script ${revname} noted, nothing to do on active node"
else
generic_revs="$generic_revs $(basename $rev)"
revlist="$revlist $(basename $rev)"
fi
;;
esac
done
apply_generic_revs "$generic_revs"
apply_host_specific_revs "$host_specific_revs"
apply_revs "$revlist"
}
# make sure we get sorted 10XXX after 9XXX

Loading…
Cancel
Save