From: | Kevin Grittner <kgrittn(at)ymail(dot)com> |
---|---|
To: | Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>, Merlin Moncure <mmoncure(at)gmail(dot)com>, Greg Stark <stark(at)mit(dot)edu> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Josh Berkus <josh(at)agliodbs(dot)com>, "nikita(dot)y(dot)volkov(at)mail(dot)ru" <nikita(dot)y(dot)volkov(at)mail(dot)ru>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: BUG #12330: ACID is broken for unique constraints |
Date: | 2014-12-30 03:00:43 |
Message-ID: | 1499898951.1513980.1419908444000.JavaMail.yahoo@jws10072.mail.ne1.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs pgsql-hackers |
Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com> wrote:
> On 12/29/14, 10:53 AM, Kevin Grittner wrote:
>> Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:
>>
>>> Serialization errors only exist as a concession to concurrency
>>> and performance. Again, they should be returned as sparsely as
>>> possible because they provide absolutely (as Tom pointed
>>> out) zero detail to the application.
>>
>> That is false. They provide an *extremely* valuable piece of
>> information which is not currently available when you get a
>> duplicate key error -- whether the error occurred because of a
>> race condition and will not fail for the same cause if retried.
>
> As for missing details like the duplicated key value, is there a
> reasonable way to add that as an errdetail() to a serialization
> failure error?
Sure. What we've been discussing is the case where a unique index
is checked for a duplicate with visibility which would cause it to
fail; whether, at transaction isolation level of serializable, to
check to see if the committed transaction which created the
existing entry overlaps the entry checking for duplicates, and use
a different SQLSTATE. Anything available for display in the detail
currently would still be available. We give different detail
messages for different types of serialization failures; it would
seem a little silly not to mention the table and the duplicate
values for this type of serialization failure. My guess is that in
production this would be completely ignored by the software, but
logging it might be helpful in tuning.
> We do still have to be careful here though; you could still have
> code using our documented upsert methodology inside a serialized
> transaction. For example, via a 3rd party extension that can't
> assume you're using serialized transactions. Would it still be OK
> to treat that as a serialization failure and bubble that all the
> way back to the application?
If the current upsert function example were used, unmodified, by
serializable transactions with the suggested changes, it would not
loop back for another try within the function, but generate a
serialization failure for the transaction as a whole. If there was
a framework watching for that and retrying transactions when it is
seen, the transaction would start over and see the new state and
behave correctly. Without the change I'm proposing, I bet it would
loop endlessly, until interrupted. [tries it] Yep, there it is.
All the hand-wringing about how we might break existing
applications is entirely backwards. Under either repeatable read
or serializable that technique goes to 100% of one CPU until you
cancel it -- completely broken. If it generated a serialization
failure the code in our docs would throw the serialization failure
out to the client, which (in most environments using serializable
transactions, or even repeatable read) would retry the transaction
from the beginning, with much less pain. It makes me wonder
whether it would be better to generate the serialization failure
for both repeatable read and serializable, since those are the
cases where the sample code in our docs generates the endless loop.
> As part of this, we should probably modify our upsert example so
> it takes transaction_isolation into account...
Probably.
--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
From | Date | Subject | |
---|---|---|---|
Next Message | ijbalazs | 2014-12-30 07:39:35 | Re: BUG #11039: installation fails when trying to install C++ redistributable |
Previous Message | Adrian Klaver | 2014-12-30 00:35:24 | Re: [GENERAL] Rollback on include error in psql |
From | Date | Subject | |
---|---|---|---|
Next Message | Jim Nasby | 2014-12-30 03:10:56 | Re: ctidscan as an example of custom-scan (Re: [v9.5] Custom Plan API) |
Previous Message | Andreas Karlsson | 2014-12-30 02:48:29 | Re: patch : Allow toast tables to be moved to a different tablespace |