Re: minor improvement in snapbuild: use existing interface and remove fake code

From: Yuefei Shi <shiyuefei1004(at)gmail(dot)com>
To: ocean_li_996 <ocean_li_996(at)163(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org, "mohen(dot)lhy(at)alibaba-inc(dot)com" <mohen(dot)lhy(at)alibaba-inc(dot)com>
Subject: Re: minor improvement in snapbuild: use existing interface and remove fake code
Date: 2025-11-18 01:13:12
Message-ID: CAD43U4UnOtW+qvZov9L3YzPjJO8JaseBsQyy73tTU_Sjjt1bcw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,
ocean_li_996 <ocean_li_996(at)163(dot)com> 于2025年11月18日周二 08:48写道:

> Hi hackers,
> While reviewing the snapbuild implementation, I noticed several small
> changes that could improve code clarity, correctness, and reuse.
> I have prepared a patch with these modifications (attached):
>
> 1. Removed the Assert in SnapBuildGetOrBuildSnapshot(). When called from
> logicalmsg_decode(), this Assert may not hold, which looks like a bug.
>
> 2. In SnapBuildProcessChange(), now reuse SnapBuildGetOrBuildSnapshot() to
> obtain the snapshot.
>
> 3. Removed handling of SNAPBUILD_START and SNAPBUILD_BUILDING_SNAPSHOT states
> in SnapBuildCommitTxn(). When entering this function,
> builder->state is always SNAPBUILD_FULL_SNAPSHOT or SNAPBUILD_CONSISTENT.
>

- /* only build a new snapshot if we don't have a prebuilt one */
- if (builder->snapshot == NULL)
- {
- builder->snapshot = SnapBuildBuildSnapshot(builder);
- /* increase refcount for the snapshot builder */
- SnapBuildSnapIncRefcount(builder->snapshot);
- }
+ Snapshot snapshot = SnapBuildGetOrBuildSnapshot(builder);

/*
* Increase refcount for the transaction we're handing the snapshot
* out to.
*/
- SnapBuildSnapIncRefcount(builder->snapshot);
+ SnapBuildSnapIncRefcount(snapshot);
ReorderBufferSetBaseSnapshot(builder->reorder, xid, lsn,
- builder->snapshot);
+ snapshot);

The snapshot created above is a temporary variable and is not recorded into
builder->snapshot, which may cause a leak.

Best regards,
Yuefei Shi

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message wenhui qiu 2025-11-18 01:47:45 Re: POC: make mxidoff 64 bits
Previous Message Chao Li 2025-11-18 01:13:01 Should the doc be enhance for "CONNECTION LIMIT"?