Commit 47336166 authored by Thomas Markwalder's avatar Thomas Markwalder

[#344,!173] Scrubbed CQL upgrade script of "non-portables"

parent e6290f00
......@@ -3,7 +3,7 @@
prefix=@prefix@
# Include utilities. Use installed version if available and
# use build version if it isn't.
if [ -e @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh ]; then
if [ -e "@datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh" ]; then
. @datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh
else
. @abs_top_builddir@/src/bin/admin/admin-utils.sh
......@@ -12,7 +12,7 @@ fi
# Need a path for temporary files created during upgrade data migration
# Use the state directory in the install path directory if it exists, otherwise
# use the build tree
if [ -e @localstatedir@/@PACKAGE_NAME@ ]; then
if [ -e "@localstatedir@/@PACKAGE_NAME@" ]; then
temp_file_dir="@localstatedir@/@PACKAGE_NAME@"
else
temp_file_dir="@abs_top_builddir@/src/share/database/scripts/cql"
......@@ -62,22 +62,22 @@ INSERT INTO schema_version (version, minor) VALUES(3, 0);
-- This line concludes database upgrade to version 3.0
EOF
if [ $? -ne 0 ]
if [ "$?" -ne 0 ]
then
echo Schema udpate FAILED!
exit -1
exit 1
fi
}
# Function to delete temporary migration files
clean_up() {
# clean up the files
if [ -e $export_file ]
if [ -e "$export_file" ]
then
rm $export_file
fi
if [ -e $update_file ]
if [ -e "$update_file" ]
then
rm $update_file
fi
......@@ -95,7 +95,7 @@ exit_now() {
explanation=$1
clean_up
if [ $status -eq 0 ]
if [ "$status" -eq 0 ]
then
echo "Data Migration SUCCESS! $explanation"
else
......@@ -175,9 +175,19 @@ migrate_host_data() {
TO '$export_file'"
cqlsh $cqlargs -e "$query"
if [ $? -ne 0 ]
if [ "$?" -ne 0 ]
then
exit_now -1 "Cassandra export failed! Could not migrate data!"
exit_now 1 "Cassandra export failed! Could not migrate data!"
fi
# Strip the carriage returns that CQL insists on adding.
if [ -e "$export_file" ]
then
cat $export_file | tr -d '\015' > $export_file.2
mv $export_file.2 $export_file
else
# Shouldn't happen but then again we're talking about CQL here
exit_now 1 "Cassandra export file $export_file is missing?"
fi
# Iterate through the exported data, accumulating update statements,
......@@ -188,10 +198,11 @@ migrate_host_data() {
while read line
do
let line_cnt++;
line_cnt=$((line_cnt + 1));
update_cols=""
xIFS="$IFS"
IFS=$'\r,'
IFS=$','
i=1
# Parse the column values
for val in $line
......@@ -211,30 +222,30 @@ migrate_host_data() {
;;
*)
# We're going to assume that since any error is fatal
exit_now -1 "Line# $line_cnt, too many values, wrong or corrupt file"
exit_now 1 "Line# $line_cnt, too many values, wrong or corrupt file"
;;
esac
let i++
i=$((i + 1))
done
if [ $i -ne 5 ]
if [ "$i" -ne 5 ]
then
# We're going to assume that since any error is fatal
exit_now -1 "Line# $line_cnt, too few values, wrong or corrupt file"
exit_now 1 "Line# $line_cnt, too few values, wrong or corrupt file"
fi
# If any of the current host's columns need to be replace, append an update for it
if [ ! -z "$update_cols" ]
then
echo "update host_reservations set $update_cols where id = $host_id;" >> $update_file
let update_cnt++
update_cnt=$((update_cnt + 1))
fi
IFS="$xIFS"
done < $export_file
# If we didn't record any updates, then hey, we're good to go!
if [ $update_cnt == 0 ]
if [ "$update_cnt" -eq 0 ]
then
exit_now 0 "Completed successfully: No updates were needed"
fi
......@@ -243,10 +254,9 @@ migrate_host_data() {
echo "$update_cnt update statements written to $update_file"
echo "Running the updates..."
cqlsh $cqlargs -f "$update_file"
if [ $? -ne 0 ]
if [ "$?" -ne 0 ]
then
exit_now -1 "Cassandra updates failed"
exit -1
exit_now 1 "Cassandra updates failed"
fi
exit_now 0 "Updated $update_cnt of $line_cnt records"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment