From: | Jeff Davis <jdavis-pgsql(at)empires(dot)org> |
---|---|
To: | Christopher Browne <cbbrowne(at)acm(dot)org> |
Cc: | PostgreSQL General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Am I locking more than I need to? |
Date: | 2004-05-21 20:25:20 |
Message-ID: | 1085171120.2274.979.camel@jeff |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
> That seems to be the right understanding. The exception handling does
> need to be in the application. And the right response may be, for a
> web app, to, at that point, simply stop, pull the "cart" contents as
> they are now, and then report back to the user:
>
> - Problem: Attempt to simultaneously request multiple quantities of
> Product Foo (Could someone be messing with your cart???)
>
> - Here's what's in your cart right now...
>
Interesting. I suppose in my application it probably is a good idea to
give an error, seeing as one physical person can't do anything quickly
enough to violate the UNIQUE.
What if postgres were to have nested transactions (I misstated above as
2PC for some reason)? Would it be desirable to do the checking on the
server side in a function (attempt to insert, and if we get a unique
constraint violation we update) rather than the application?
> Well, I'm not sure what the likely alternatives are, without, let's
> say, creating a lockable table for each 'cart.' And that would seem
> likely to have pretty heavy effects on the application, too.
>
> Whether you "lock" or "detect errors" seems like a "six of one, half a
> dozen of the other" to me, and the latter is likely to be WAY more
> efficient :-).
One thing that I didn't think of before is this: if I have a table of
all the carts, then could I do a "SELECT ... WHERE cart_id=X FOR UPDATE"
right before I did the test to see whether I should insert or update?
That would basically be a row lock on just the cart I'm modifying,
preventing other concurrent accesses (assuming that they are also trying
to "SELECT ... FOR UPDATE") from locking the same cart, right? But it
would allow other carts to be modified without waiting. Is this a viable
solution?
Thanks,
Jeff
From | Date | Subject | |
---|---|---|---|
Next Message | Jim Seymour | 2004-05-21 20:42:29 | Re: Truncating 'now' to seconds |
Previous Message | Vivek Khera | 2004-05-21 19:13:18 | Re: Is Linux 2.6.5 kernel good enough for production? |