diff options
| author | Álvaro Herrera <alvherre@kurilemu.de> | 2025-10-21 10:51:55 +0300 |
|---|---|---|
| committer | Álvaro Herrera <alvherre@kurilemu.de> | 2025-10-21 10:51:55 +0300 |
| commit | b7cc6474e930d4429b15657d6910e1e32066de5e (patch) | |
| tree | 26d481b65447ad0695504c84382486fcbad186ab /src/include/storage/bufmgr.h | |
| parent | 9fd29d7ff476f3f1c1a22d6d6f730e813eddd960 (diff) | |
Make smgr access for a BufferManagerRelation safer in relcache inval
Currently there's no bug, because we have no code path where we
invalidate relcache entries where it'd cause a problem. But it's more
robust to do it this way in case we introduce such a path later, as some
Postgres forks reportedly already have.
Author: Daniil Davydov <3danissimo@gmail.com>
Reviewed-by: Stepan Neretin <slpmcf@gmail.com>
Discussion: https://postgr.es/m/CAJDiXgj3FNzAhV+jjPqxMs3jz=OgPohsoXFj_fh-L+nS+13CKQ@mail.gmail.com
Diffstat (limited to 'src/include/storage/bufmgr.h')
| -rw-r--r-- | src/include/storage/bufmgr.h | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index 3f37b294af6..b5f8f3c5d42 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -98,8 +98,11 @@ typedef struct SMgrRelationData *SMgrRelation; /* * Some functions identify relations either by relation or smgr + - * relpersistence. Used via the BMR_REL()/BMR_SMGR() macros below. This - * allows us to use the same function for both recovery and normal operation. + * relpersistence, initialized via the BMR_REL()/BMR_SMGR() macros below. + * This allows us to use the same function for both recovery and normal + * operation. When BMR_REL is used, it's not valid to cache its rd_smgr here, + * because our pointer would be obsolete in case of relcache invalidation. + * For simplicity, use BMR_GET_SMGR to read the smgr. */ typedef struct BufferManagerRelation { @@ -108,8 +111,12 @@ typedef struct BufferManagerRelation char relpersistence; } BufferManagerRelation; -#define BMR_REL(p_rel) ((BufferManagerRelation){.rel = p_rel}) -#define BMR_SMGR(p_smgr, p_relpersistence) ((BufferManagerRelation){.smgr = p_smgr, .relpersistence = p_relpersistence}) +#define BMR_REL(p_rel) \ + ((BufferManagerRelation){.rel = p_rel}) +#define BMR_SMGR(p_smgr, p_relpersistence) \ + ((BufferManagerRelation){.smgr = p_smgr, .relpersistence = p_relpersistence}) +#define BMR_GET_SMGR(bmr) \ + (RelationIsValid((bmr).rel) ? RelationGetSmgr((bmr).rel) : (bmr).smgr) /* Zero out page if reading fails. */ #define READ_BUFFERS_ZERO_ON_ERROR (1 << 0) |
