summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-03-29 13:33:34 +0200
committerErich Eckner <git@eckner.net>2018-03-29 13:33:34 +0200
commit792664b9373ded19f242163b3f9cfe16c224d5db (patch)
treed870096d5bec251ee64916bcd48a683c09468535 /lib
parentd5ca342e17b3bfd16875ddbf7d705a16976f466e (diff)
downloadbuilder-792664b9373ded19f242163b3f9cfe16c224d5db.tar.xz
lib/mysql-functions, bin/return-assignment: mysql_insert_package_files_query() new and used
Diffstat (limited to 'lib')
-rwxr-xr-xlib/mysql-functions83
1 files changed, 83 insertions, 0 deletions
diff --git a/lib/mysql-functions b/lib/mysql-functions
index da58fe7..095f1cc 100755
--- a/lib/mysql-functions
+++ b/lib/mysql-functions
@@ -1166,3 +1166,86 @@ for link in \
mysql_join__generic "${table_a}" "${column_a}" "${table_b}" "${column_b}"
mysql_join__generic "${table_b}" "${column_b}" "${table_a}" "${column_a}"
done
+
+# mysql_insert_package_files_query $file_list_file
+# Writes a query, inserting files listed in $file_list_file into database.
+# The file is expected to have the following \t separated columns:
+# pkgname epoch pkgver pkgrel sub_pkgrel arch path name
+mysql_insert_package_files_query() {
+
+ local partition
+ local partitions_count
+
+ partitions_count=16
+
+ if [ ! -r "$1" ]; then
+ >&2 printf 'mysql_insert_package_files: File "%s" is not readable.\n' \
+ "$1"
+ return 2
+ fi
+
+ printf 'DROP TEMPORARY TABLE IF EXISTS `pkg_files`;\n'
+ printf 'CREATE TEMPORARY TABLE `pkg_files` ('
+ printf '`pkgname` VARCHAR(64),'
+ printf '`epoch` MEDIUMINT,'
+ printf '`pkgver` VARCHAR(64),'
+ printf '`pkgrel` MEDIUMINT,'
+ printf '`sub_pkgrel` MEDIUMINT,'
+ printf '`arch` VARCHAR(16),'
+ printf '`path` TEXT,'
+ printf '`name` TEXT,'
+ printf '`absolute_name_hash` VARCHAR(56),'
+ printf '`name_hash` MEDIUMINT'
+ printf ');\n'
+ printf 'LOAD DATA LOCAL INFILE "%s" INTO TABLE `pkg_files`' \
+ "${1}"
+ printf ' (`pkgname`, `epoch`, `pkgver`, `pkgrel`, `sub_pkgrel`, `arch`, `path`, `name`);\n'
+ printf 'UPDATE `pkg_files` SET'
+ printf ' `pkg_files`.`name_hash`=CAST(CONV(SUBSTR(SHA2(`pkg_files`.`name`,224),1,2),16,10) AS INT),'
+ printf ' `pkg_files`.`absolute_name_hash`=SHA2(CONCAT(`pkg_files`.`path`,`pkg_files`.`name`),224);\n'
+ for partition in $(seq 0 $((partitions_count-1))); do
+ printf 'INSERT IGNORE INTO `files` PARTITION (p%s) (`path`,`name`,`name_hash`,`absolute_name_hash`)' \
+ "${partition}"
+ printf ' SELECT '
+ printf '`pkg_files`.`%s`,' \
+ 'path' 'name' 'name_hash' 'absolute_name_hash' | \
+ sed 's/,$//'
+ printf ' FROM `pkg_files`'
+ printf ' WHERE `pkg_files`.`name_hash` MOD %s = %s;\n' \
+ "${partitions_count}" "${partition}"
+ printf 'INSERT IGNORE INTO `file_providers` PARTITION (p%s) (`package`,`file`,`file_name_hash`)' \
+ "${partition}"
+ printf ' SELECT `binary_packages`.`id`,`files`.`id`,`files`.`name_hash` FROM `pkg_files`'
+ printf ' JOIN `binary_packages` ON'
+ printf ' `binary_packages`.`%s`=`pkg_files`.`%s` AND' \
+ 'pkgname' 'pkgname' \
+ 'epoch' 'epoch' \
+ 'pkgver' 'pkgver' \
+ 'pkgrel' 'pkgrel' \
+ 'sub_pkgrel' 'sub_pkgrel' | \
+ sed 's/ AND$//'
+ if [ -n "${slave}" ]; then
+ mysql_join_binary_packages_build_slaves
+ printf ' AND `build_slaves`.`name`=from_base64("%s")' \
+ "$(
+ printf '%s' "${slave}" | \
+ base64 -w0
+ )"
+ fi
+ mysql_join_binary_packages_architectures
+ printf ' AND `pkg_files`.`arch`=`architectures`.`name`'
+ mysql_join_binary_packages_repositories
+ if [ -n "${slave}" ]; then
+ printf ' AND `repositories`.`name`="build-list"'
+ else
+ printf ' AND `repositories`.`is_on_master_mirror`'
+ fi
+ printf ' JOIN `files` PARTITION (p%s)' \
+ "${partition}"
+ printf ' ON `files`.`name_hash`=`pkg_files`.`name_hash`'
+ printf ' AND `files`.`absolute_name_hash`=`pkg_files`.`absolute_name_hash`'
+ printf ' WHERE `pkg_files`.`name_hash` MOD %s = %s;\n' \
+ "${partitions_count}" "${partition}"
+ done
+
+}