Browse Source

sql - update rollback.sh to include a count report option and a blocks table option

master
kanoi 9 years ago
parent
commit
e65ddb3b26
  1. 95
      sql/rollback.sh

95
sql/rollback.sh

@ -13,12 +13,24 @@
# then you need to convince Kano to update the ckdb -y option to handle # then you need to convince Kano to update the ckdb -y option to handle
# that, with the current db, and also add code to the -y option to # that, with the current db, and also add code to the -y option to
# update the DB # update the DB
# i.e. the ckdb -y option needs updating # i.e. the ckdb -y options/code need updating
# 6) Blocks commands manually entered using ckpmsg (confirm,orphan,reject,etc)
# will not be automatically restored if you use -b, you'll need to redo
# them again manually
# #
# The basic use of this script is for when something goes wrong with the # The basic use of this script is for when something goes wrong with the
# database and the CCLs are OK - so you can roll back to before the # database and the CCLs are OK - so you can roll back to before the
# database problem and reload all the data # database problem and reload all the data
# #
# It may be unnecessary to delete/expire blocks records since the reload will
# attempt to load all old and new blocks records in the CCLs being
# reloaded, no matter what
# Also, deleting blocks history will lose all manual block changes
# done with confirms, orphans, rejects, etc
# However, if the block summarisations are wrong or the blocks table is
# corrupt, you will need to delete/expire them to correct them and then
# redo the manual blocks changes after reloading
#
# Deleting markersummaries would only be an option if you know for sure # Deleting markersummaries would only be an option if you know for sure
# that all data is in the CCLs # that all data is in the CCLs
# It would be ideal to do a markersummary table dump before a rollback # It would be ideal to do a markersummary table dump before a rollback
@ -34,6 +46,8 @@
# to before the SEQ restart 0 point, then ckdb couldn't know this unless # to before the SEQ restart 0 point, then ckdb couldn't know this unless
# the data was inconsistent # the data was inconsistent
# #
# -c will show you record counts but not change anything
#
# -e will of course allow you to compare all but markersummary, before and # -e will of course allow you to compare all but markersummary, before and
# after rolling back, by manually comparing the expired record with the # after rolling back, by manually comparing the expired record with the
# new replacement unexpired record - but it deletes the markersummary data # new replacement unexpired record - but it deletes the markersummary data
@ -53,11 +67,16 @@
# #
usAge() usAge()
{ {
echo "usAge: `basename $0` [-n] -e|-r|-m workinfoid" echo "usAge: `basename $0` [-b] [-n] -c|-e|-r|-m workinfoid"
echo " Preferred option is just -e as long as you aren't missing reload data" echo " Preferred option is just -e as long as you aren't missing reload data"
echo " The order of options must match the usAge order"
echo
echo " -b = include blocks when deleting/expiring (otherwise left untouched)"
echo echo
echo " -n = use 'now()' instead of the date timestamp of now, for expiry date" echo " -n = use 'now()' instead of the date timestamp of now, for expiry date"
echo echo
echo " -c = report the counts of rows that would be affected, but don't do it"
echo
echo " -e = rollback by deleteing expired data and expiring unexpired data," echo " -e = rollback by deleteing expired data and expiring unexpired data,"
echo " but deleting markersummary" echo " but deleting markersummary"
echo echo
@ -66,9 +85,9 @@ usAge()
echo " but don't touch markersummary" echo " but don't touch markersummary"
echo " N.B. -m is expected to cause problems with ckdb" echo " N.B. -m is expected to cause problems with ckdb"
echo echo
echo " generates the sql on stdout" echo " generates the sql on stdout, that you would feed into pgsql"
echo echo
echo " Read `basename $0` for an explanation" echo " Read `basename $0` for a more detailed explanation"
exit 1 exit 1
} }
# #
@ -98,17 +117,37 @@ process()
unex="expirydate > '6666-06-01'" unex="expirydate > '6666-06-01'"
oldex="expirydate < '6666-06-01'" oldex="expirydate < '6666-06-01'"
# #
if [ "$opt" = "-c" ] ; then
echo "\\echo 'count markersummary'"
echo "select count(*),min(markerid) as min_markerid,max(markerid) as max_markerid,"
echo " sum(diffacc) as sum_diffacc,min(firstshareacc) as min_firstshareacc,"
echo " max(lastshareacc) as max_lastshareacc"
echo " from markersummary where markerid in"
echo " (select distinct markerid from workmarkers where workinfoidend >= $wi);"
fi
if [ "$opt" = "-r" -o "$opt" = "-e" ] ; then if [ "$opt" = "-r" -o "$opt" = "-e" ] ; then
echo "\\echo 'delete markersummary'" echo "\\echo 'delete markersummary'"
echo "delete from markersummary where markerid in" echo "delete from markersummary where markerid in"
echo " (select distinct markerid from workmarkers where workinfoidend >= $wi);" echo " (select distinct markerid from workmarkers where workinfoidend >= $wi);"
fi fi
#
if [ "$opt" = "-c" ] ; then
echo "\\echo 'count marks'"
echo "select count(*),min(workinfoid) as min_workinfoid,"
echo " max(workinfoid) as max_workinfoid"
echo " from marks where workinfoid >= $wi;"
echo "\\echo 'count workmarkers'"
echo "select count(*),min(workinfoidstart) as min_workinfoidstart,"
echo " max(workinfoidend) as max_workinfoidend"
echo " from workmarkers where workinfoidend >= $wi;"
fi
if [ "$opt" = "-r" ] ; then if [ "$opt" = "-r" ] ; then
echo "\\echo 'delete marks'" echo "\\echo 'delete marks'"
echo "delete from marks where workinfoid >= $wi;" echo "delete from marks where workinfoid >= $wi;"
echo "\\echo 'delete workmarkers'" echo "\\echo 'delete workmarkers'"
echo "delete from workmarkers where workinfoidend >= $wi;" echo "delete from workmarkers where workinfoidend >= $wi;"
else fi
if [ "$opt" = "-e" -o "$opt" = "-m" ] ; then
echo "\\echo 'delete/update marks'" echo "\\echo 'delete/update marks'"
echo "delete from marks where $oldex and workinfoid >= $wi;" echo "delete from marks where $oldex and workinfoid >= $wi;"
echo "update marks set $ex where $unex and workinfoid >= $wi;" echo "update marks set $ex where $unex and workinfoid >= $wi;"
@ -117,20 +156,51 @@ process()
echo "update workmarkers set $ex where $unex and workinfoidend >= $wi;" echo "update workmarkers set $ex where $unex and workinfoidend >= $wi;"
fi fi
# #
if [ "$opt" = "-c" ] ; then
echo "\\echo 'count blocks'"
echo "select count(*),min(workinfoid) as min_workinfoid,"
echo " max(workinfoid) as max_workinfoid"
echo " from blocks where workinfoid >= $wi;"
echo "\\echo 'count workinfo'"
echo "select count(*),min(workinfoid) as min_workinfoid,"
echo " max(workinfoid) as max_workinfoid"
echo " from workinfo where workinfoid >= $wi;"
fi
if [ "$opt" = "-r" ] ; then if [ "$opt" = "-r" ] ; then
if [ "$deblk" ] ; then
echo "\\echo 'delete blocks'" echo "\\echo 'delete blocks'"
echo "delete from blocks where workinfoid >= $wi;" echo "delete from blocks where workinfoid >= $wi;"
fi
echo "\\echo 'delete workinfo'" echo "\\echo 'delete workinfo'"
echo "delete from workinfo where workinfoid >= $wi;" echo "delete from workinfo where workinfoid >= $wi;"
else fi
if [ "$opt" = "-e" -o "$opt" = "-m" ] ; then
if [ "$deblk" ] ; then
echo "\\echo 'delete/update blocks'" echo "\\echo 'delete/update blocks'"
echo "delete from blocks where $oldex and workinfoid >= $wi;" echo "delete from blocks where $oldex and workinfoid >= $wi;"
echo "update blocks set $ex where $unex and workinfoid >= $wi;" echo "update blocks set $ex where $unex and workinfoid >= $wi;"
fi
echo "\\echo 'delete/update workinfo'" echo "\\echo 'delete/update workinfo'"
echo "delete from workinfo where $oldex and workinfoid >= $wi;" echo "delete from workinfo where $oldex and workinfoid >= $wi;"
echo "update workinfo set $ex where $unex and workinfoid >= $wi;" echo "update workinfo set $ex where $unex and workinfoid >= $wi;"
fi fi
# #
if [ "$opt" = "-c" ] ; then
echo "\\echo 'count miningpayouts'"
echo "select count(*),min(payoutid) as min_payoutid,"
echo " max(payoutid) as max_payoutid"
echo " from miningpayouts where payoutid in"
echo " (select distinct payoutid from payouts where workinfoidend >= $wi);"
echo "\\echo 'count payments'"
echo "select count(*),min(payoutid) as min_payoutid,"
echo " max(payoutid) as max_payoutid"
echo " from payments where payoutid in"
echo " (select distinct payoutid from payouts where workinfoidend >= $wi);"
echo "\\echo 'count payouts'"
echo "select count(*),min(workinfoidstart) as min_workinfoidstart,"
echo " max(workinfoidend) as max_workinfoidend"
echo " from payouts where workinfoidend >= $wi;"
fi
if [ "$opt" = "-r" ] ; then if [ "$opt" = "-r" ] ; then
echo "\\echo 'delete miningpayouts'" echo "\\echo 'delete miningpayouts'"
echo "delete from miningpayouts where payoutid in" echo "delete from miningpayouts where payoutid in"
@ -140,7 +210,8 @@ process()
echo " (select distinct payoutid from payouts where workinfoidend >= $wi);" echo " (select distinct payoutid from payouts where workinfoidend >= $wi);"
echo "\\echo 'delete payouts'" echo "\\echo 'delete payouts'"
echo "delete from payouts where workinfoidend >= $wi;" echo "delete from payouts where workinfoidend >= $wi;"
else fi
if [ "$opt" = "-e" -o "$opt" = "-m" ] ; then
echo "\\echo 'delete/update miningpayouts'" echo "\\echo 'delete/update miningpayouts'"
echo "delete from miningpayouts where $oldex and payoutid in" echo "delete from miningpayouts where $oldex and payoutid in"
echo " (select distinct payoutid from payouts where workinfoidend >= $wi);" echo " (select distinct payoutid from payouts where workinfoidend >= $wi);"
@ -156,11 +227,13 @@ process()
echo "update payouts set $ex where workinfoidend >= $wi and $unex;" echo "update payouts set $ex where workinfoidend >= $wi and $unex;"
fi fi
# #
if [ "$opt" = "-e" -o "$opt" = "-m" -o "$opt" = "-r" ] ; then
idctl markerid workmarkers idctl markerid workmarkers
idctl paymentid payments idctl paymentid payments
idctl payoutid payouts idctl payoutid payouts
# this makes sure the worker data is consistent - don't remove this # this makes sure the worker data is consistent - don't remove this
idctl workerid workers idctl workerid workers
fi
} }
# #
if [ -z "$1" ] ; then if [ -z "$1" ] ; then
@ -171,13 +244,19 @@ if [ "$1" = "-?" -o "$1" = "-h" -o "$1" = "-help" -o "$1" = "--help" ] ; then
usAge usAge
fi fi
# #
deblk=""
if [ "$1" = "-b" ] ; then
deblk="y"
shift
fi
#
usenow="" usenow=""
if [ "$1" = "-n" ] ; then if [ "$1" = "-n" ] ; then
usenow="y" usenow="y"
shift shift
fi fi
# #
if [ "$1" != "-r" -a "$1" != "-e" -a "$1" != "-m" ] ; then if [ "$1" != "-c" -a "$1" != "-e" -a "$1" != "-r" -a "$1" != "-m" ] ; then
echo "ERR: Unknown p1='$1'" echo "ERR: Unknown p1='$1'"
usAge usAge
fi fi

Loading…
Cancel
Save