From: Tim Starling Date: Mon, 5 Jul 2004 03:02:47 +0000 (+0000) Subject: The link cache is constructed without FOR UPDATE, so collisions in these insert state... X-Git-Tag: 1.5.0alpha1~2719 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=c31cc66f5273d31d3bfb9a9eb9ebebbb2915d2bf;p=lhc%2Fweb%2Fwiklou.git The link cache is constructed without FOR UPDATE, so collisions in these insert statements appear to be possible, and judging by the DB error log and reports of link table corruption, quite common. Ignoring errors prevents the wholesale failure of a link table update, although it's possible links which should have been removed may remain. Hence this is a temporary solution, a better solution may be to switch LinkCache to FOR UPDATE mode --- diff --git a/includes/LinksUpdate.php b/includes/LinksUpdate.php index 104e442471..5d293907ca 100644 --- a/includes/LinksUpdate.php +++ b/includes/LinksUpdate.php @@ -54,7 +54,10 @@ class LinksUpdate { # Do the insertion $sql = ""; if ( 0 != count( $add ) ) { - $sql = "INSERT INTO links (l_from,l_to) VALUES "; + # The link cache was constructed without FOR UPDATE, so there may be collisions + # Ignoring for now, I'm not sure if that causes problems or not, but I'm fairly + # sure it's better than without IGNORE + $sql = "INSERT IGNORE INTO links (l_from,l_to) VALUES "; $first = true; foreach( $add as $lt => $lid ) { @@ -90,7 +93,7 @@ class LinksUpdate { # Do additions $sql = ""; if ( 0 != count ( $add ) ) { - $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES "; + $sql = "INSERT IGNORE INTO brokenlinks (bl_from,bl_to) VALUES "; $first = true; foreach( $add as $blt ) { $blt = wfStrencode( $blt ); @@ -116,7 +119,7 @@ class LinksUpdate { $sql = ""; $image = Namespace::getImage(); if ( 0 != count ( $add ) ) { - $sql = "INSERT INTO imagelinks (il_from,il_to) VALUES "; + $sql = "INSERT IGNORE INTO imagelinks (il_from,il_to) VALUES "; $first = true; foreach( $add as $iname => $val ) { # FIXME: Change all this to avoid unnecessary duplication @@ -145,7 +148,7 @@ class LinksUpdate { # Do the insertion $sql = ""; if ( 0 != count ( $add ) ) { - $sql = "INSERT INTO categorylinks (cl_from,cl_to,cl_sortkey) VALUES "; + $sql = "INSERT IGNORE INTO categorylinks (cl_from,cl_to,cl_sortkey) VALUES "; $first = true; foreach( $add as $cname => $sortkey ) { # FIXME: Change all this to avoid unnecessary duplication @@ -284,7 +287,9 @@ class LinksUpdate { $res = wfQuery( $sql, DB_READ, $fname ); if ( 0 == wfNumRows( $res ) ) { return; } - $sql = "INSERT INTO links (l_from,l_to) VALUES "; + # Ignore errors. If a link existed in both the brokenlinks table and the links + # table, that's an error which can be fixed at this stage by simply ignoring collisions + $sql = "INSERT IGNORE INTO links (l_from,l_to) VALUES "; $now = wfTimestampNow(); $sql2 = "UPDATE cur SET cur_touched='{$now}' WHERE cur_id IN ("; $first = true;