Confused about TransactionIdSetTreeStatus

From: Japin Li <japinli(at)hotmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Confused about TransactionIdSetTreeStatus
Date: 2022-10-25 09:02:25
Message-ID: MEYP282MB166963056D71539C3D0D5F4BB6319@MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Hi, hackers

I'm a bit confused about TransactionIdSetTreeStatus, the comment says if
subtransactions cross multiple CLOG pages, it will mark the subxids, that
are on the same page as the main transaction, as sub-committed, and then
set main transaction and subtransactions to committed (step 2).

* Example:
* TransactionId t commits and has subxids t1, t2, t3, t4
* t is on page p1, t1 is also on p1, t2 and t3 are on p2, t4 is on p3
* 1. update pages2-3:
* page2: set t2,t3 as sub-committed
* page3: set t4 as sub-committed
* 2. update page1:
* set t1 as sub-committed,
* then set t as committed,
then set t1 as committed
* 3. update pages2-3:
* page2: set t2,t3 as committed
* page3: set t4 as committed

However, the code marks the main transaction and subtransactions directly
to the committed.

/*
* If this is a commit then we care about doing this correctly (i.e.
* using the subcommitted intermediate status). By here, we know
* we're updating more than one page of clog, so we must mark entries
* that are *not* on the first page so that they show as subcommitted
* before we then return to update the status to fully committed.
*
* To avoid touching the first page twice, skip marking subcommitted
* for the subxids on that first page.
*/
if (status == TRANSACTION_STATUS_COMMITTED)
set_status_by_pages(nsubxids - nsubxids_on_first_page,
subxids + nsubxids_on_first_page,
TRANSACTION_STATUS_SUB_COMMITTED, lsn);

/*
* Now set the parent and subtransactions on same page as the parent,
* if any
*/
pageno = TransactionIdToPage(xid);
TransactionIdSetPageStatus(xid, nsubxids_on_first_page, subxids, status,
lsn, pageno, false);

/*
* Now work through the rest of the subxids one clog page at a time,
* starting from the second page onwards, like we did above.
*/
set_status_by_pages(nsubxids - nsubxids_on_first_page,
subxids + nsubxids_on_first_page,
status, lsn);

Is the comment correct? If not, should we remove it?

--
Regrads,
Japin Li.
ChengDu WenWu Information Technology Co.,Ltd.

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Laurenz Albe 2022-10-25 09:08:27 Re: Make EXPLAIN generate a generic plan for a parameterized query
Previous Message Alvaro Herrera 2022-10-25 08:33:31 Re: Proposal: Adding isbgworker column to pg_stat_activity