Re: database abstraction layer

From: Date: Wed, 03 Feb 2010 01:31:21 +0000
Subject: Re: database abstraction layer
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-301766@lists.php.net to get a copy of this message
Rene Veerman wrote:
i haven't had the pleasure yet of writing for sites that generate so many hits/sec that they'd update the max value of any table at exactly the same time. i usually ask for the max value about 2 milliseconds before doing the insert. And if the insert fails, i can auto-retry via a wrapper function after sleep(rand(1,3)); I dare say i could work this way at facebook <g> (not that i really want to, happy with where i am)
This is a race condition... all you need are two hits per day... one from person A and one from person B. If they happen within short enough temporal proximity then the race is on. Now... a big fat lock around the table before the request for max ID and the insert query ought to mitigate your issue. Although I wouldn't call my function getMaxId() I would call it getNextId() :) Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP

« previous php.general (#301766) next »