From 37dd4786515d78db928d6bdd7fd844452f0dd0c9 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Thu, 29 Mar 2018 13:48:23 +0200 Subject: lib/mysql-functions: mysql_cleanup: remove obsolete files and file_providers partition by partition --- lib/mysql-functions | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/lib/mysql-functions b/lib/mysql-functions index 095f1cc..418f15b 100755 --- a/lib/mysql-functions +++ b/lib/mysql-functions @@ -785,6 +785,7 @@ mysql_find_build_assignment_loops() { # clean up left overs from mysql database mysql_cleanup() { local operator + local partition if [ "$#" = '0' ]; then operator='DELETE' elif [ "$#" = '1' ] && [ "x$1" = 'xdry' ]; then @@ -892,23 +893,29 @@ mysql_cleanup() { fi printf ' WHERE `build_slaves`.`currently_building` IS NULL' printf ' AND `build_slaves`.`logged_lines` IS NOT NULL;\n' - # remove obsolete file_providers - printf '%s FROM `file_providers`' \ - "${operator}" - printf ' WHERE NOT EXISTS (' - printf 'SELECT * FROM `binary_packages`' - printf ' WHERE `binary_packages`.`id`=`file_providers`.`package`' - printf ') OR NOT EXISTS (' - printf 'SELECT * FROM `files`' - printf ' WHERE `files`.`id`=`file_providers`.`file`' - printf ');\n' - # remove obsolete files - printf '%s FROM `files`' \ - "${operator}" - printf ' WHERE NOT EXISTS (' - printf 'SELECT * FROM `file_providers`' - printf ' WHERE `files`.`id`=`file_providers`.`file`' - printf ');\n' + for partition in $(seq 0 15); do + # remove obsolete file_providers + printf '%s FROM `file_providers` PARTITION (p%s)' \ + "${operator}" "${partition}" + printf ' WHERE NOT EXISTS (' + printf 'SELECT * FROM `binary_packages`' + printf ' WHERE `binary_packages`.`id`=`file_providers`.`package`' + printf ') OR NOT EXISTS (' + printf 'SELECT * FROM `files` PARTITION (p%s)' \ + "${partition}" + printf ' WHERE `files`.`id`=`file_providers`.`file`' + printf ' AND `files`.`name_hash`=`file_providers`.`name_hash`' + printf ');\n' + # remove obsolete files + printf '%s FROM `files` PARTITION (p%s)' \ + "${operator}" "${partition}" + printf ' WHERE NOT EXISTS (' + printf 'SELECT * FROM `file_providers` PARTITION (p%s)' \ + "${partition}" + printf ' WHERE `files`.`id`=`file_providers`.`file`' + printf ' AND `files`.`name_hash`=`file_providers`.`name_hash`' + printf ');\n' + done } | \ mysql_run_query } -- cgit v1.2.3-70-g09d2