Обсуждение: A question about StartSubTransaction
Hi hackers, I found the StartSubTransaction has the following code: static void StartSubTransaction(void) { [...] s->state = TRANS_START; /* * Initialize subsystems for new subtransaction * * must initialize resource-management stuff first */ AtSubStart_Memory(); AtSubStart_ResourceOwner(); AfterTriggerBeginSubXact(); s->state = TRANS_INPROGRESS; [...] } IIRC, AtSubStart_Memory, AtSubStart_ResourceOwner and AfterTriggerBeginSubXact don't use s->state. Why should we set s->state to TRANS_START and then TRANS_INPROGRESS? -- Regrads, Japin Li. ChengDu WenWu Information Technology Co.,Ltd.
Japin Li <japinli@hotmail.com> writes: > IIRC, AtSubStart_Memory, AtSubStart_ResourceOwner and AfterTriggerBeginSubXact don't > use s->state. No, they don't. > Why should we set s->state to TRANS_START and then TRANS_INPROGRESS? I believe it's so that if an error gets thrown somewhere in that area, we'll recover properly. I'd be the first to say that this stuff isn't terribly well-tested, since it's hard to force an error there. regards, tom lane
On Wed, 14 Sep 2022 at 13:52, Tom Lane <tgl@sss.pgh.pa.us> wrote: > Japin Li <japinli@hotmail.com> writes: >> Why should we set s->state to TRANS_START and then TRANS_INPROGRESS? > > I believe it's so that if an error gets thrown somewhere in that > area, we'll recover properly. I'd be the first to say that this > stuff isn't terribly well-tested, since it's hard to force an > error there. > Thanks for the explanation! Maybe more comments here is better. -- Regrads, Japin Li. ChengDu WenWu Information Technology Co.,Ltd.