pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Replace RelationOpenSmgr() with RelationGetSmgr().
5+ messages / 1 participants
[nested] [flat]

* pgsql: Replace RelationOpenSmgr() with RelationGetSmgr().
@ 2021-07-12 21:01 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2021-07-12 21:01 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Replace RelationOpenSmgr() with RelationGetSmgr().

The idea behind this patch is to design out bugs like the one fixed
by commit 9d523119f.  Previously, once one did RelationOpenSmgr(rel),
it was considered okay to access rel->rd_smgr directly for some
not-very-clear interval.  But since that pointer will be cleared by
relcache flushes, we had bugs arising from overreliance on a previous
RelationOpenSmgr call still being effective.

Now, very little code except that in rel.h and relcache.c should ever
touch the rd_smgr field directly.  The normal coding rule is to use
RelationGetSmgr(rel) and not expect the result to be valid for longer
than one smgr function call.  There are a couple of places where using
the function every single time seemed like overkill, but they are now
annotated with large warning comments.

Amul Sul, after an idea of mine.

Discussion: https://postgr.es/m/CANiYTQsU7yMFpQYnv=BrcRVqK_3U3mtAzAsJCaqtzsDHfsUbdQ@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f10f0ae420ee62400876ab34dca2c09c20dcd030

Modified Files
--------------
contrib/amcheck/verify_nbtree.c           |  3 +-
contrib/bloom/blinsert.c                  |  6 ++--
contrib/pg_prewarm/autoprewarm.c          |  4 +--
contrib/pg_prewarm/pg_prewarm.c           |  5 ++-
contrib/pg_visibility/pg_visibility.c     |  6 ++--
src/backend/access/gist/gistbuild.c       | 14 ++++----
src/backend/access/hash/hashpage.c        |  4 +--
src/backend/access/heap/heapam_handler.c  |  7 ++--
src/backend/access/heap/rewriteheap.c     | 15 +++------
src/backend/access/heap/visibilitymap.c   | 53 ++++++++++++++++---------------
src/backend/access/nbtree/nbtree.c        |  6 ++--
src/backend/access/nbtree/nbtsort.c       | 14 +++-----
src/backend/access/spgist/spginsert.c     | 14 ++++----
src/backend/access/table/tableam.c        |  7 ++--
src/backend/catalog/heap.c                |  2 --
src/backend/catalog/index.c               |  5 ++-
src/backend/catalog/storage.c             | 46 ++++++++++++++++++---------
src/backend/commands/tablecmds.c          |  7 ++--
src/backend/storage/buffer/bufmgr.c       | 24 ++++----------
src/backend/storage/freespace/freespace.c | 52 ++++++++++++++++++------------
src/include/utils/rel.h                   | 37 +++++++++++++--------
21 files changed, 165 insertions(+), 166 deletions(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Replace RelationOpenSmgr() with RelationGetSmgr().
@ 2022-11-17 21:55 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2022-11-17 21:55 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Replace RelationOpenSmgr() with RelationGetSmgr().

This is a back-patch of the v15-era commit f10f0ae42 into older
supported branches.  The idea is to design out bugs in which an
ill-timed relcache flush clears rel->rd_smgr partway through
some code sequence that wasn't expecting that.  We had another
report today of a corner case that reliably crashes v14 under
debug_discard_caches (nee CLOBBER_CACHE_ALWAYS), and therefore
would crash once in a blue moon in the field.  We're unlikely
to get rid of all such code paths unless we adopt the more
rigorous coding rules instituted by f10f0ae42.  Therefore,
even though this is a bit invasive, it's time to back-patch.
Some comfort can be taken in the fact that f10f0ae42 has been
in v15 for 16 months without problems.

I left the RelationOpenSmgr macro present in the back branches,
even though no core code should use it anymore, in order to not break
third-party extensions in minor releases.  Such extensions might opt
to start using RelationGetSmgr instead, to reduce their code
differential between v15 and earlier branches.  This carries a hazard
of failing to compile against headers from existing minor releases.
However, once compiled the extension should work fine even with such
releases, because RelationGetSmgr is a "static inline" function so
it creates no link-time dependency.  So depending on distribution
practices, that might be an OK tradeoff.

Per report from Spyridon Dimitrios Agathos.  Original patch
by Amul Sul.

Discussion: https://postgr.es/m/CAFM5RaqdgyusQvmWkyPYaWMwoK5gigdtW-7HcgHgOeAw7mqJ_Q@mail.gmail.com
Discussion: https://postgr.es/m/CANiYTQsU7yMFpQYnv=BrcRVqK_3U3mtAzAsJCaqtzsDHfsUbdQ@mail.gmail.com

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/32d5a4974c81aeaca7ffc025f0a5fda88b71cba6

Modified Files
--------------
contrib/amcheck/verify_nbtree.c           |  3 +-
contrib/bloom/blinsert.c                  |  6 ++--
contrib/pg_prewarm/autoprewarm.c          |  4 +--
contrib/pg_prewarm/pg_prewarm.c           |  5 ++-
contrib/pg_visibility/pg_visibility.c     |  6 ++--
src/backend/access/gist/gistbuild.c       | 19 ++++-------
src/backend/access/hash/hashpage.c        |  4 +--
src/backend/access/heap/heapam_handler.c  |  7 ++--
src/backend/access/heap/rewriteheap.c     | 15 +++------
src/backend/access/heap/visibilitymap.c   | 53 ++++++++++++++++---------------
src/backend/access/nbtree/nbtree.c        |  6 ++--
src/backend/access/nbtree/nbtsort.c       | 14 +++-----
src/backend/access/spgist/spginsert.c     | 14 ++++----
src/backend/access/table/tableam.c        |  7 ++--
src/backend/catalog/heap.c                |  2 --
src/backend/catalog/index.c               |  5 ++-
src/backend/catalog/storage.c             | 46 ++++++++++++++++++---------
src/backend/commands/tablecmds.c          |  7 ++--
src/backend/storage/buffer/bufmgr.c       | 24 ++++----------
src/backend/storage/freespace/freespace.c | 52 ++++++++++++++++++------------
src/include/utils/rel.h                   | 34 +++++++++++++++++---
21 files changed, 171 insertions(+), 162 deletions(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Replace RelationOpenSmgr() with RelationGetSmgr().
@ 2022-11-17 21:55 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2022-11-17 21:55 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Replace RelationOpenSmgr() with RelationGetSmgr().

This is a back-patch of the v15-era commit f10f0ae42 into older
supported branches.  The idea is to design out bugs in which an
ill-timed relcache flush clears rel->rd_smgr partway through
some code sequence that wasn't expecting that.  We had another
report today of a corner case that reliably crashes v14 under
debug_discard_caches (nee CLOBBER_CACHE_ALWAYS), and therefore
would crash once in a blue moon in the field.  We're unlikely
to get rid of all such code paths unless we adopt the more
rigorous coding rules instituted by f10f0ae42.  Therefore,
even though this is a bit invasive, it's time to back-patch.
Some comfort can be taken in the fact that f10f0ae42 has been
in v15 for 16 months without problems.

I left the RelationOpenSmgr macro present in the back branches,
even though no core code should use it anymore, in order to not break
third-party extensions in minor releases.  Such extensions might opt
to start using RelationGetSmgr instead, to reduce their code
differential between v15 and earlier branches.  This carries a hazard
of failing to compile against headers from existing minor releases.
However, once compiled the extension should work fine even with such
releases, because RelationGetSmgr is a "static inline" function so
it creates no link-time dependency.  So depending on distribution
practices, that might be an OK tradeoff.

Per report from Spyridon Dimitrios Agathos.  Original patch
by Amul Sul.

Discussion: https://postgr.es/m/CAFM5RaqdgyusQvmWkyPYaWMwoK5gigdtW-7HcgHgOeAw7mqJ_Q@mail.gmail.com
Discussion: https://postgr.es/m/CANiYTQsU7yMFpQYnv=BrcRVqK_3U3mtAzAsJCaqtzsDHfsUbdQ@mail.gmail.com

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/9a299cf7c21f30ca5d045faaf725e8216d3cc5f5

Modified Files
--------------
contrib/amcheck/verify_nbtree.c           |  3 +-
contrib/bloom/blinsert.c                  |  6 ++--
contrib/pg_prewarm/autoprewarm.c          |  4 +--
contrib/pg_prewarm/pg_prewarm.c           |  5 ++-
contrib/pg_visibility/pg_visibility.c     |  6 ++--
src/backend/access/gist/gistbuild.c       |  2 +-
src/backend/access/hash/hashpage.c        |  4 +--
src/backend/access/heap/heapam_handler.c  |  7 ++--
src/backend/access/heap/rewriteheap.c     | 15 +++------
src/backend/access/heap/visibilitymap.c   | 54 ++++++++++++++++---------------
src/backend/access/nbtree/nbtree.c        |  6 ++--
src/backend/access/nbtree/nbtsort.c       | 14 +++-----
src/backend/access/spgist/spginsert.c     | 14 ++++----
src/backend/access/table/tableam.c        |  7 ++--
src/backend/catalog/heap.c                |  2 --
src/backend/catalog/index.c               |  5 ++-
src/backend/catalog/storage.c             | 48 ++++++++++++++++++---------
src/backend/commands/tablecmds.c          |  7 ++--
src/backend/storage/buffer/bufmgr.c       | 24 ++++----------
src/backend/storage/freespace/freespace.c | 51 +++++++++++++++++------------
src/include/utils/rel.h                   | 34 ++++++++++++++++---
21 files changed, 166 insertions(+), 152 deletions(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Replace RelationOpenSmgr() with RelationGetSmgr().
@ 2022-11-17 21:55 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2022-11-17 21:55 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Replace RelationOpenSmgr() with RelationGetSmgr().

This is a back-patch of the v15-era commit f10f0ae42 into older
supported branches.  The idea is to design out bugs in which an
ill-timed relcache flush clears rel->rd_smgr partway through
some code sequence that wasn't expecting that.  We had another
report today of a corner case that reliably crashes v14 under
debug_discard_caches (nee CLOBBER_CACHE_ALWAYS), and therefore
would crash once in a blue moon in the field.  We're unlikely
to get rid of all such code paths unless we adopt the more
rigorous coding rules instituted by f10f0ae42.  Therefore,
even though this is a bit invasive, it's time to back-patch.
Some comfort can be taken in the fact that f10f0ae42 has been
in v15 for 16 months without problems.

I left the RelationOpenSmgr macro present in the back branches,
even though no core code should use it anymore, in order to not break
third-party extensions in minor releases.  Such extensions might opt
to start using RelationGetSmgr instead, to reduce their code
differential between v15 and earlier branches.  This carries a hazard
of failing to compile against headers from existing minor releases.
However, once compiled the extension should work fine even with such
releases, because RelationGetSmgr is a "static inline" function so
it creates no link-time dependency.  So depending on distribution
practices, that might be an OK tradeoff.

Per report from Spyridon Dimitrios Agathos.  Original patch
by Amul Sul.

Discussion: https://postgr.es/m/CAFM5RaqdgyusQvmWkyPYaWMwoK5gigdtW-7HcgHgOeAw7mqJ_Q@mail.gmail.com
Discussion: https://postgr.es/m/CANiYTQsU7yMFpQYnv=BrcRVqK_3U3mtAzAsJCaqtzsDHfsUbdQ@mail.gmail.com

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/e21856fd652ad1d6bfcc63bb427d29622359f948

Modified Files
--------------
contrib/amcheck/verify_nbtree.c           |  3 +-
contrib/bloom/blinsert.c                  |  6 ++--
contrib/pg_prewarm/autoprewarm.c          |  4 +--
contrib/pg_prewarm/pg_prewarm.c           |  5 ++-
contrib/pg_visibility/pg_visibility.c     |  4 +--
src/backend/access/gist/gistbuild.c       |  2 +-
src/backend/access/hash/hashpage.c        |  4 +--
src/backend/access/heap/heapam.c          |  5 ++-
src/backend/access/heap/heapam_handler.c  | 20 ++++++-----
src/backend/access/heap/rewriteheap.c     |  7 ++--
src/backend/access/heap/visibilitymap.c   | 56 ++++++++++++++++---------------
src/backend/access/nbtree/nbtree.c        |  6 ++--
src/backend/access/nbtree/nbtsort.c       | 14 +++-----
src/backend/access/spgist/spginsert.c     | 14 ++++----
src/backend/catalog/heap.c                |  2 --
src/backend/catalog/index.c               |  5 ++-
src/backend/catalog/storage.c             | 44 ++++++++++++++++--------
src/backend/commands/tablecmds.c          |  7 ++--
src/backend/storage/buffer/bufmgr.c       | 26 ++++----------
src/backend/storage/freespace/freespace.c | 53 +++++++++++++++++------------
src/include/utils/rel.h                   | 34 ++++++++++++++++---
21 files changed, 173 insertions(+), 148 deletions(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Replace RelationOpenSmgr() with RelationGetSmgr().
@ 2022-11-17 21:55 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2022-11-17 21:55 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Replace RelationOpenSmgr() with RelationGetSmgr().

This is a back-patch of the v15-era commit f10f0ae42 into older
supported branches.  The idea is to design out bugs in which an
ill-timed relcache flush clears rel->rd_smgr partway through
some code sequence that wasn't expecting that.  We had another
report today of a corner case that reliably crashes v14 under
debug_discard_caches (nee CLOBBER_CACHE_ALWAYS), and therefore
would crash once in a blue moon in the field.  We're unlikely
to get rid of all such code paths unless we adopt the more
rigorous coding rules instituted by f10f0ae42.  Therefore,
even though this is a bit invasive, it's time to back-patch.
Some comfort can be taken in the fact that f10f0ae42 has been
in v15 for 16 months without problems.

I left the RelationOpenSmgr macro present in the back branches,
even though no core code should use it anymore, in order to not break
third-party extensions in minor releases.  Such extensions might opt
to start using RelationGetSmgr instead, to reduce their code
differential between v15 and earlier branches.  This carries a hazard
of failing to compile against headers from existing minor releases.
However, once compiled the extension should work fine even with such
releases, because RelationGetSmgr is a "static inline" function so
it creates no link-time dependency.  So depending on distribution
practices, that might be an OK tradeoff.

Per report from Spyridon Dimitrios Agathos.  Original patch
by Amul Sul.

Discussion: https://postgr.es/m/CAFM5RaqdgyusQvmWkyPYaWMwoK5gigdtW-7HcgHgOeAw7mqJ_Q@mail.gmail.com
Discussion: https://postgr.es/m/CANiYTQsU7yMFpQYnv=BrcRVqK_3U3mtAzAsJCaqtzsDHfsUbdQ@mail.gmail.com

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/d4acf2eb94f3464d5f439ca83a4188496cd5841a

Modified Files
--------------
contrib/amcheck/verify_nbtree.c           |  3 +-
contrib/bloom/blinsert.c                  |  6 ++--
contrib/pg_prewarm/autoprewarm.c          |  4 +--
contrib/pg_prewarm/pg_prewarm.c           |  5 ++-
contrib/pg_visibility/pg_visibility.c     |  4 +--
src/backend/access/gist/gistbuild.c       |  2 +-
src/backend/access/hash/hashpage.c        |  4 +--
src/backend/access/heap/heapam.c          |  5 ++-
src/backend/access/heap/rewriteheap.c     |  7 ++--
src/backend/access/heap/visibilitymap.c   | 56 ++++++++++++++++---------------
src/backend/access/nbtree/nbtree.c        |  6 ++--
src/backend/access/nbtree/nbtsort.c       | 14 +++-----
src/backend/access/spgist/spginsert.c     | 14 ++++----
src/backend/catalog/heap.c                | 10 ++----
src/backend/catalog/index.c               |  5 ++-
src/backend/catalog/storage.c             | 20 +++++------
src/backend/commands/tablecmds.c          |  8 ++---
src/backend/storage/buffer/bufmgr.c       | 26 ++++----------
src/backend/storage/freespace/freespace.c | 53 +++++++++++++++++------------
src/include/utils/rel.h                   | 34 ++++++++++++++++---
20 files changed, 144 insertions(+), 142 deletions(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2022-11-17 21:55 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-07-12 21:01 pgsql: Replace RelationOpenSmgr() with RelationGetSmgr(). Tom Lane <tgl@sss.pgh.pa.us>
2022-11-17 21:55 pgsql: Replace RelationOpenSmgr() with RelationGetSmgr(). Tom Lane <tgl@sss.pgh.pa.us>
2022-11-17 21:55 pgsql: Replace RelationOpenSmgr() with RelationGetSmgr(). Tom Lane <tgl@sss.pgh.pa.us>
2022-11-17 21:55 pgsql: Replace RelationOpenSmgr() with RelationGetSmgr(). Tom Lane <tgl@sss.pgh.pa.us>
2022-11-17 21:55 pgsql: Replace RelationOpenSmgr() with RelationGetSmgr(). Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox