Re: minor improvement in snapbuild: use existing interface and remove fake code
| От | Yuefei Shi |
|---|---|
| Тема | Re: minor improvement in snapbuild: use existing interface and remove fake code |
| Дата | |
| Msg-id | CAD43U4UnOtW+qvZov9L3YzPjJO8JaseBsQyy73tTU_Sjjt1bcw@mail.gmail.com обсуждение исходный текст |
| Ответ на | minor improvement in snapbuild: use existing interface and remove fake code (ocean_li_996 <ocean_li_996@163.com>) |
| Ответы |
Re: minor improvement in snapbuild: use existing interface and remove fake code
|
| Список | pgsql-hackers |
Hi,
ocean_li_996 <ocean_li_996@163.com> 于2025年11月18日周二 08:48写道:
Hi hackers,While reviewing thesnapbuildimplementation, I noticed several small changes that could improve code clarity, correctness, and reuse.I have prepared a patch with these modifications (attached):1. Removed theAssertinSnapBuildGetOrBuildSnapshot(). When called fromlogicalmsg_decode(), thisAssertmay not hold, which looks like a bug.2. InSnapBuildProcessChange(), now reuseSnapBuildGetOrBuildSnapshot()to obtain the snapshot.
3. Removed handling ofSNAPBUILD_STARTandSNAPBUILD_BUILDING_SNAPSHOTstates inSnapBuildCommitTxn(). When entering this function,builder->stateis alwaysSNAPBUILD_FULL_SNAPSHOTorSNAPBUILD_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);
- 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
В списке pgsql-hackers по дате отправления: