Re: [HACKERS] [OSSTEST PATCH 0/1] PostgreSQL db: Retry on constraintviolation [and 2 more messages] [and 1 more messages] - Mailing list pgsql-hackers
From | Kevin Grittner |
---|---|
Subject | Re: [HACKERS] [OSSTEST PATCH 0/1] PostgreSQL db: Retry on constraintviolation [and 2 more messages] [and 1 more messages] |
Date | |
Msg-id | CACjxUsO2cO70FV2xueUd-cP20XeYotWAxbMBUGTRFsCtO7JHGg@mail.gmail.com Whole thread Raw |
In response to | Re: [HACKERS] [OSSTEST PATCH 0/1] PostgreSQL db: Retry on constraintviolation [and 2 more messages] [and 1 more messages] (Ian Jackson <ian.jackson@eu.citrix.com>) |
Responses |
Re: [HACKERS] [OSSTEST PATCH 0/1] PostgreSQL db: Retry on constraintviolation [and 2 more messages] [and 1 more messages]
|
List | pgsql-hackers |
On Wed, Dec 14, 2016 at 11:12 AM, Ian Jackson <ian.jackson@eu.citrix.com> wrote: > Kevin Grittner writes ("Re: [HACKERS] [OSSTEST PATCH 0/1] PostgreSQL db: Retry on constraint violation [and 2 more messages][and 1 more messages]"): >> On Wed, Dec 14, 2016 at 10:20 AM, Ian Jackson <ian.jackson@eu.citrix.com> wrote: >> I would alter that slightly to: >> >> There is a consistent serialization of all serializable >> transactions which successfully commit. > > Here `serializable' means SERIALIZABLE ? I'm not entirely sure what you mean to convey by the capitalization, so I'll just say that 'serializable' there referred to the transaction isolation level. (I *think* that was what you were getting at.) >> For examples, please see this Wiki page. You might be particularly >> interested in the examples in the "Read Only Transactions" section: >> >> https://wiki.postgresql.org/wiki/SSI > > Thanks. I read that part of the wiki page. But in that example, we > are told that T1 will be aborted, not T3. That is true in the first "Deposit Report") example in that section. The second ("Rollover") example shows the read-only transaction (T3) being the one which is aborted and retried. > Can it happen that a transaction which does not make any update > attempts, will see "impossible" data, and that this is only detected > at COMMIT ? Does that apply even to READ ONLY transactions ? As Robert pointed out, a read-only transaction cannot normally be aborted by a serialization failure on COMMIT. Under exceptional conditions, like an attempt to suppress the serialization failure, you might see the commit aborted, though. Also as pointed out by Robert, the state seen by a read-only transaction doesn't lack internal consistency, but it will be rolled back with a serialization failure exception if it can show a state which is inconsistent with some successfully-committed state of the database. In the "Rollover" example, the first time T3 is attempted its SELECT it would have shown rows containing 100 and 11, were it not canceled. That could have been consistent with the earlier state of 100 and 10 and the business rules that the first number can only change by having the second number added to it, and the second number can only change by being incremented; but that state and those rules don't fit with the *later* state of 110, 11, because that requires that the second number be added to the first before it was incremented, and if we allow the result of the first T3 transaction attempt to be seen, it would tell us that the increment happened first. Since we've already allowed successful commit of transactions putting things into a state only consistent with adding 10 to 100 before incrementing 10 to 11, cancel the read-only transaction and start over. This time it will show something consistent with the apparent order of execution of the other transactions. Note that neither the order that the first two transaction started in (T1->T2) nor the order they committed in (T2->T1) determines the apparent order of execution. It is the rw-dependencies that control (T1 reads a version of data before T2's work is applied, so T1 *appears* to have run before T2 in apparent order of execution.) Since both are successfully committed with that apparent order of execution, a third transaction (T3), which sees the work of T2 (since it had committed when the snapshot for T3 was taken) but not T1 (since it had not committed when the snapshot for T3 was taken) cannot be allowed to proceed. I know an example like that can cause one's head to hurt a bit (been there), but even if you don't fight your way to a full grasp of that case, it will hopefully give you some idea of both why we can have high concurrency with this approach, and why it is necessary to discard results from failed transactions. >> Once a serialization failure occurs the transaction is flagged as >> "doomed" and will not, under any circumstances be allowed to >> commit. If you find any exception to that, please report it as a >> bug. > > Right. I think this prevents any exception-catching arrangements from > suppressing the serialisation failure. Since AIUI it is not possible > to run the outer COMMIT from within an exception trapping context. Right. > If it /is/ possible to run that outer COMMIT in a way which swallows > the exception then [...] That is not possible, as I understand things. -- Kevin Grittner EDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
pgsql-hackers by date: