Matt S Trout wrote: > On Fri, Jul 27, 2007 at 06:38:19PM -0700, Mesdaq, Ali wrote: >> This came up in the Catalyst list today so I am posting here for >> discussion or bug reporting. >> >> The issue is that it seems the find_or_create() call can have a hiccup >> in high load situations where find_or_create is called more than once at >> the same time with the same value. So what happens is both calls try to >> do a find and return nothing then they attempt to insert and once >> succeeds and one gets an error of: >> >> DBIx::Class::ResultSet::find_or_create(): DBI Exception: >> DBD::mysql::st execute failed: Duplicate entry > > My initial response to this was the same as everybody else's, "catch the damn > exception". > > My second response was "can't we make this atomic somehow?" ... but of course > the answer is no. We could do transaction stuff and ... throw a different > exception. > > I don't like your "return -1" approach though. > > Three possiblities: > > (1) trap duplicate key exception and do what you describe > - do DBs give a sanely trappable exception here? > > (2) try the re-select no matter what the exception > - actually -probably- safe. performance issues?
Ha ha, unless you're using DBD::SQLite 1.13, then the key violation throws and exception and the next call fails with the same error, even when it's an unrelated query like a select. Gebus, what a retarded bug find weekend that was. :-)
signature.asc
Description: OpenPGP digital signature
_______________________________________________ List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class Wiki: http://dbix-class.shadowcatsystems.co.uk/ IRC: irc.perl.org#dbix-class SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/ Searchable Archive: http://www.mail-archive.com/[email protected]/
