A question about StartSubTransaction

Started by Japin Liover 3 years ago3 messages
#1Japin Li
japinli@hotmail.com

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.

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Japin Li (#1)
Re: A question about StartSubTransaction

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

#3Japin Li
japinli@hotmail.com
In reply to: Tom Lane (#2)
Re: A question about StartSubTransaction

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.