[ZBX-5125] Incorrect query in upgrade script to 2.0 Created: 2012 Jun 04 Updated: 2017 May 30 Resolved: 2012 Sep 25 |
|
Status: | Closed |
Project: | ZABBIX BUGS AND ISSUES |
Component/s: | Installation (I) |
Affects Version/s: | 2.0.0 |
Fix Version/s: | 2.0.3rc1, 2.0.4rc1, 2.1.0 |
Type: | Incident report | Priority: | Major |
Reporter: | Alexey Pustovalov | Assignee: | Unassigned |
Resolution: | Fixed | Votes: | 2 |
Labels: | upgrade | ||
Remaining Estimate: | Not Specified | ||
Time Spent: | Not Specified | ||
Original Estimate: | Not Specified |
Issue Links: |
|
Description |
cat upgrades/dbpatches/2.0/mysql/patch.sql | mysql zabbix Whereas "discovery_groupid" column modified to NOT NULL, then executes the next query: The "discovery_groupid" column can not be NULL. The problem may happen when discovery_groupid references to non exist groupid. |
Comments |
Comment by Gertjan Awater [ 2012 Jun 05 ] |
almost the same here: |
Comment by Alexey Pustovalov [ 2012 Jun 11 ] |
Second problem: This is should help: |
Comment by Gertjan Awater [ 2012 Jul 03 ] |
almost the same error as before: Executed your four rows of sql code prior to running ./zabbix-2.0.0/upgrades/dbpatches/2.0/mysql/patch.sql |
Comment by Alexey Pustovalov [ 2012 Jul 05 ] |
also we can use IGNORE syntax for creating UNIQUE indexes. For example: IGNORE is a MySQL extension to standard SQL. It controls how ALTER TABLE works if there are duplicates on unique keys in the new table or if warnings occur when strict mode is enabled. If IGNORE is not specified, the copy is aborted and rolled back if duplicate-key errors occur. If IGNORE is specified, only the first row is used of rows with duplicates on a unique key. The other conflicting rows are deleted. Incorrect values are truncated to the closest matching acceptable value. |
Comment by dimir [ 2012 Jul 09 ] |
Fixed in development branch svn://svn.zabbix.com/branches/dev/ZBX-5125 |
Comment by Gertjan Awater [ 2012 Jul 10 ] |
restored 1.8.6 DB, tried again. Upgrade still crashes on line 104, which looks like this now: |
Comment by dimir [ 2012 Jul 10 ] |
Gertjan, could you take the development branch when upgrading to 2.0: svn co svn://svn.zabbix.com/branches/dev/ZBX-5125 And try to upgrade using that? |
Comment by Gertjan Awater [ 2012 Jul 11 ] |
That did the trick...script has been running for hours now, so I guess it's past line 104 |
Comment by dimir [ 2012 Jul 11 ] |
Has it been also that long before too? Or there was no "before" ? How big is your DB? |
Comment by Gertjan Awater [ 2012 Jul 11 ] |
patch.sql used to crash within 5 minutes on line 104. DB is 6GB, running conversion on a rather small sized VM. mysqld runnin 100% cpu. It's OK, no rush...no direct need for 2.0 here. Would just be nice to be able to stand up at zabconf when the question "who is running 2.0?" comes |
Comment by dimir [ 2012 Jul 11 ] |
Oh, thanks for all the info. It's obvious then it takes that long. See you on zabconf! :-D |
Comment by Alexander Vladishev [ 2012 Jul 11 ] |
Great! Successfully tested! |
Comment by dimir [ 2012 Jul 17 ] |
Fixed in pre-2.0.2 r28925, pre-2.1.0 r28926. |
Comment by Alexey Pustovalov [ 2012 Jul 20 ] |
New bugs in the upgrade script |
Comment by Alexey Pustovalov [ 2012 Jul 20 ] |
(1) CREATE UNIQUE INDEX hostmacro_1 ON hostmacro (hostid,macro); <dimir> I believe this was resolved in r29350. CLOSED |
Comment by Alexander Vladishev [ 2012 Jul 20 ] |
Fixed in the development branch svn://svn.zabbix.com/branches/dev/ZBX-5125 |
Comment by dimir [ 2012 Aug 01 ] |
Successfully tested. Alexey, thank you for you suggestions! However, we have used a bit different approach. We delete the duplicate rows leaving the one with the lowest ID by executing something like this: DELETE FROM hostmacro Similar for the problem with hosts_groups table. |
Comment by Alexander Vladishev [ 2012 Aug 01 ] |
Fixed in pre-2.0.3 r29350 and pre-2.1.0 r29351. |
Comment by Alexey Pustovalov [ 2012 Aug 16 ] |
(3) ERROR 1062 (23000) at line 1752: Duplicate entry '63377-63378' for key 'trigger_depends_1' The problem can appear when the table contains rows with identical triggerid_down and triggerid_up pairs. <dimir> RESOLVED in r30344 <Sasha> Successfully tested! TESTED dimir CLOSED |
Comment by Alexey Pustovalov [ 2012 Aug 17 ] |
Also DELETE FROM hostmacro Will not work. Because MySQL does not support queries like this: http://stackoverflow.com/questions/45494/mysql-error-1093-cant-specify-target-table-for-update-in-from-clause mysql> DELETE FROM hostmacro <Sasha> It happens on MySQL 5.5. MySQL 5.0.51 works without errors. <Sasha> RESOLVED r30430 dimir Looks great, CLOSED |
Comment by dimir [ 2012 Aug 20 ] |
I did not say we used this query for MySQL. Please check files: upgrades/dbpatches/2.0/mysql/patch/hostmacro.sql |
Comment by Alexey Pustovalov [ 2012 Oct 03 ] |
A new error: <Sasha> RESOLVED in r30754 dimir Great, CLOSED |
Comment by Alexey Pustovalov [ 2012 Oct 07 ] |
More simple examples of queries: DELETE hm FROM hostmacro hm JOIN (SELECT MAX(hostmacroid) AS hostmacroid FROM hostmacro hm GROUP BY hm.hostid, hm.macro HAVING COUNT(*) > 1) hm2 USING(hostmacroid); DELETE hm1 FROM hostmacro as hm1,hostmacro as hm2 WHERE hm1.hostid = hm2.hostid AND hm1.macro = hm2.macro AND hm1.hostmacroid>hm2.hostmacroid |
Comment by Alexey Pustovalov [ 2012 Oct 11 ] |
The new one: mysql> ALTER TABLE items ADD CONSTRAINT c_items_2 FOREIGN KEY (templateid) REFERENCES items (itemid) ON DELETE CASCADE; ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`test_zbx`.<result 2 when explaining filename '#sql-ca8_77'>, CONSTRAINT `c_items_2` FOREIGN KEY (`templateid`) REFERENCES `items` (`itemid`) ON DELETE CASCADE) We does not check that templateid which not null may does not equal any itemid. But we should non-remove corrupted templated items. we should mark it as host items. <Sasha> We already check item existence from a template. Alexey, please re-reproduce the issue. CREATE TEMPORARY TABLE tmp_items_itemid (itemid bigint unsigned PRIMARY KEY); INSERT INTO tmp_items_itemid (itemid) (SELECT itemid FROM items); UPDATE items SET templateid=NULL WHERE templateid=0 OR templateid NOT IN (SELECT itemid FROM tmp_items_itemid); DROP TABLE tmp_items_itemid; IBM DB2, PostgreSQL, Oracle: UPDATE items SET templateid=NULL WHERE templateid=0 OR templateid NOT IN (SELECT itemid FROM items); <dotneft> Sorry. It is my mistake. <Sasha> CLOSED |
Comment by dimir [ 2012 Oct 30 ] |
Changes successfully tested. |
Comment by Alexander Vladishev [ 2012 Oct 31 ] |
Fixed in version pre-2.0.4 r31167 and pre-2.1.0 (trunk) r31168. |