agora inbox for [email protected]help / color / mirror / Atom feed
security release 24+ messages / 3 participants [nested] [flat]
* security release @ 2018-11-08 17:30 Pavel Stehule <[email protected]> 0 siblings, 1 reply; 24+ messages in thread From: Pavel Stehule @ 2018-11-08 17:30 UTC (permalink / raw) To: pgsql-hackers Ahoj dnes byly zverejneny opravne verze viz https://www.postgresql.org/about/news/1905/ Pokud si hrajete s PostgreSQL 11, pripadne ji pouzivate produkcne, tak neodkladejte upgrade. Pavel ^ permalink raw reply [nested|flat] 24+ messages in thread
* Re: security release @ 2018-11-08 17:39 Robert Haas <[email protected]> parent: Pavel Stehule <[email protected]> 0 siblings, 1 reply; 24+ messages in thread From: Robert Haas @ 2018-11-08 17:39 UTC (permalink / raw) To: Pavel Stehule <[email protected]>; +Cc: pgsql-hackers On Thu, Nov 8, 2018 at 12:31 PM Pavel Stehule <[email protected]> wrote: > Ahoj > > dnes byly zverejneny opravne verze viz https://www.postgresql.org/about/news/1905/ > > Pokud si hrajete s PostgreSQL 11, pripadne ji pouzivate produkcne, tak neodkladejte upgrade. Wrong list? -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company ^ permalink raw reply [nested|flat] 24+ messages in thread
* Re: security release @ 2018-11-08 17:54 Pavel Stehule <[email protected]> parent: Robert Haas <[email protected]> 0 siblings, 0 replies; 24+ messages in thread From: Pavel Stehule @ 2018-11-08 17:54 UTC (permalink / raw) To: Robert Haas <[email protected]>; +Cc: pgsql-hackers čt 8. 11. 2018 v 18:40 odesílatel Robert Haas <[email protected]> napsal: > On Thu, Nov 8, 2018 at 12:31 PM Pavel Stehule <[email protected]> > wrote: > > Ahoj > > > > dnes byly zverejneny opravne verze viz > https://www.postgresql.org/about/news/1905/ > > > > Pokud si hrajete s PostgreSQL 11, pripadne ji pouzivate produkcne, tak > neodkladejte upgrade. > > Wrong list? > yes, I am sorry. Regards Pavel > > -- > Robert Haas > EnterpriseDB: http://www.enterprisedb.com > The Enterprise PostgreSQL Company > ^ permalink raw reply [nested|flat] 24+ messages in thread
* [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. @ 2021-01-20 14:59 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 24+ messages in thread From: Kyotaro Horiguchi @ 2021-01-20 14:59 UTC (permalink / raw) WAL-skipping optimization omits bumping page LSN when ALTER TABLE SET TABLESPACE. Also heap_page_prune does the same. However, old_snapshot_threshold feature needs page LSN to be kept updated on these operations so that TestForOldSnapshot properly find identify whether a snapshot is invalidated. --- src/backend/access/heap/pruneheap.c | 14 ++++++++++++++ src/backend/catalog/storage.c | 8 ++++++++ src/include/storage/bufmgr.h | 3 ++- src/include/utils/rel.h | 4 ++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index e3a716a2a2..33c0841b36 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -70,6 +70,8 @@ static void heap_prune_record_redirect(PruneState *prstate, static void heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum); static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * Optionally prune and repair fragmentation in the specified page. @@ -331,6 +333,18 @@ heap_page_prune(Relation relation, Buffer buffer, PageSetLSN(BufferGetPage(buffer), recptr); } + else if (relation->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + { + XLogRecPtr currlsn = GetXLogInsertRecPtr(); + Page page = BufferGetPage(buffer); + + Assert(wal_level < WAL_LEVEL_REPLICA); + + /* we need to update page LSN to notify reader of pruning */ + if (PageGetLSN(page) == currlsn) + currlsn = gistXLogAssignLSN(); + PageSetLSN(page, currlsn); + } } else { diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index cba7a9ada0..488ac6f760 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -75,6 +75,8 @@ typedef struct PendingRelSync static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ HTAB *pendingSyncHash = NULL; +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * AddPendingSync @@ -414,6 +416,7 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, bool copying_initfork; BlockNumber nblocks; BlockNumber blkno; + XLogRecPtr fakepagelsn; page = (Page) buf.data; @@ -434,6 +437,9 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, use_wal = XLogIsNeeded() && (relpersistence == RELPERSISTENCE_PERMANENT || copying_initfork); + if (!use_wal) + fakepagelsn = gistXLogAssignLSN(); + nblocks = smgrnblocks(src, forkNum); for (blkno = 0; blkno < nblocks; blkno++) @@ -460,6 +466,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, */ if (use_wal) log_newpage(&dst->smgr_rnode.node, forkNum, blkno, page, false); + else + PageSetLSN(page, fakepagelsn); PageSetChecksumInplace(page, blkno); diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index e641174798..9ab9e7394c 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -19,6 +19,7 @@ #include "storage/buf.h" #include "storage/bufpage.h" #include "storage/relfilenode.h" +#include "utils/rel.h" #include "utils/relcache.h" #include "utils/snapmgr.h" @@ -289,7 +290,7 @@ TestForOldSnapshot(Snapshot snapshot, Relation relation, Page page) && ((snapshot)->snapshot_type == SNAPSHOT_MVCC || (snapshot)->snapshot_type == SNAPSHOT_TOAST) && !XLogRecPtrIsInvalid((snapshot)->lsn) - && (!XLogIsNeeded() || PageGetLSN(page) > (snapshot)->lsn)) + && PageGetLSN(page) > (snapshot)->lsn) TestForOldSnapshot_impl(snapshot, relation); } diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f58d65cf28..35e53c8d74 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -618,8 +618,8 @@ typedef struct ViewOptions * decoding snapshot. */ #define RelationIsAccessibleInLogicalDecoding(relation) \ - (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + (XLogLogicalInfoActive() && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* -- 2.27.0 ----Next_Part(Thu_Jan_21_00_28_44_2021_003)---- ^ permalink raw reply [nested|flat] 24+ messages in thread
* [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. @ 2021-01-20 14:59 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 24+ messages in thread From: Kyotaro Horiguchi @ 2021-01-20 14:59 UTC (permalink / raw) WAL-skipping optimization omits bumping page LSN when ALTER TABLE SET TABLESPACE. Also heap_page_prune does the same. However, old_snapshot_threshold feature needs page LSN to be kept updated on these operations so that TestForOldSnapshot properly find identify whether a snapshot is invalidated. --- src/backend/access/heap/pruneheap.c | 14 ++++++++++++++ src/backend/catalog/storage.c | 8 ++++++++ src/include/storage/bufmgr.h | 3 ++- src/include/utils/rel.h | 4 ++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index e3a716a2a2..33c0841b36 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -70,6 +70,8 @@ static void heap_prune_record_redirect(PruneState *prstate, static void heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum); static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * Optionally prune and repair fragmentation in the specified page. @@ -331,6 +333,18 @@ heap_page_prune(Relation relation, Buffer buffer, PageSetLSN(BufferGetPage(buffer), recptr); } + else if (relation->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + { + XLogRecPtr currlsn = GetXLogInsertRecPtr(); + Page page = BufferGetPage(buffer); + + Assert(wal_level < WAL_LEVEL_REPLICA); + + /* we need to update page LSN to notify reader of pruning */ + if (PageGetLSN(page) == currlsn) + currlsn = gistXLogAssignLSN(); + PageSetLSN(page, currlsn); + } } else { diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index cba7a9ada0..488ac6f760 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -75,6 +75,8 @@ typedef struct PendingRelSync static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ HTAB *pendingSyncHash = NULL; +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * AddPendingSync @@ -414,6 +416,7 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, bool copying_initfork; BlockNumber nblocks; BlockNumber blkno; + XLogRecPtr fakepagelsn; page = (Page) buf.data; @@ -434,6 +437,9 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, use_wal = XLogIsNeeded() && (relpersistence == RELPERSISTENCE_PERMANENT || copying_initfork); + if (!use_wal) + fakepagelsn = gistXLogAssignLSN(); + nblocks = smgrnblocks(src, forkNum); for (blkno = 0; blkno < nblocks; blkno++) @@ -460,6 +466,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, */ if (use_wal) log_newpage(&dst->smgr_rnode.node, forkNum, blkno, page, false); + else + PageSetLSN(page, fakepagelsn); PageSetChecksumInplace(page, blkno); diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index e641174798..9ab9e7394c 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -19,6 +19,7 @@ #include "storage/buf.h" #include "storage/bufpage.h" #include "storage/relfilenode.h" +#include "utils/rel.h" #include "utils/relcache.h" #include "utils/snapmgr.h" @@ -289,7 +290,7 @@ TestForOldSnapshot(Snapshot snapshot, Relation relation, Page page) && ((snapshot)->snapshot_type == SNAPSHOT_MVCC || (snapshot)->snapshot_type == SNAPSHOT_TOAST) && !XLogRecPtrIsInvalid((snapshot)->lsn) - && (!XLogIsNeeded() || PageGetLSN(page) > (snapshot)->lsn)) + && PageGetLSN(page) > (snapshot)->lsn) TestForOldSnapshot_impl(snapshot, relation); } diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f58d65cf28..35e53c8d74 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -618,8 +618,8 @@ typedef struct ViewOptions * decoding snapshot. */ #define RelationIsAccessibleInLogicalDecoding(relation) \ - (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + (XLogLogicalInfoActive() && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* -- 2.27.0 ----Next_Part(Thu_Jan_21_00_28_44_2021_003)---- ^ permalink raw reply [nested|flat] 24+ messages in thread
* [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. @ 2021-01-20 14:59 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 24+ messages in thread From: Kyotaro Horiguchi @ 2021-01-20 14:59 UTC (permalink / raw) WAL-skipping optimization omits bumping page LSN when ALTER TABLE SET TABLESPACE. Also heap_page_prune does the same. However, old_snapshot_threshold feature needs page LSN to be kept updated on these operations so that TestForOldSnapshot properly find identify whether a snapshot is invalidated. --- src/backend/access/heap/pruneheap.c | 14 ++++++++++++++ src/backend/catalog/storage.c | 8 ++++++++ src/include/storage/bufmgr.h | 3 ++- src/include/utils/rel.h | 4 ++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index e3a716a2a2..33c0841b36 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -70,6 +70,8 @@ static void heap_prune_record_redirect(PruneState *prstate, static void heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum); static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * Optionally prune and repair fragmentation in the specified page. @@ -331,6 +333,18 @@ heap_page_prune(Relation relation, Buffer buffer, PageSetLSN(BufferGetPage(buffer), recptr); } + else if (relation->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + { + XLogRecPtr currlsn = GetXLogInsertRecPtr(); + Page page = BufferGetPage(buffer); + + Assert(wal_level < WAL_LEVEL_REPLICA); + + /* we need to update page LSN to notify reader of pruning */ + if (PageGetLSN(page) == currlsn) + currlsn = gistXLogAssignLSN(); + PageSetLSN(page, currlsn); + } } else { diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index cba7a9ada0..488ac6f760 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -75,6 +75,8 @@ typedef struct PendingRelSync static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ HTAB *pendingSyncHash = NULL; +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * AddPendingSync @@ -414,6 +416,7 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, bool copying_initfork; BlockNumber nblocks; BlockNumber blkno; + XLogRecPtr fakepagelsn; page = (Page) buf.data; @@ -434,6 +437,9 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, use_wal = XLogIsNeeded() && (relpersistence == RELPERSISTENCE_PERMANENT || copying_initfork); + if (!use_wal) + fakepagelsn = gistXLogAssignLSN(); + nblocks = smgrnblocks(src, forkNum); for (blkno = 0; blkno < nblocks; blkno++) @@ -460,6 +466,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, */ if (use_wal) log_newpage(&dst->smgr_rnode.node, forkNum, blkno, page, false); + else + PageSetLSN(page, fakepagelsn); PageSetChecksumInplace(page, blkno); diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index e641174798..9ab9e7394c 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -19,6 +19,7 @@ #include "storage/buf.h" #include "storage/bufpage.h" #include "storage/relfilenode.h" +#include "utils/rel.h" #include "utils/relcache.h" #include "utils/snapmgr.h" @@ -289,7 +290,7 @@ TestForOldSnapshot(Snapshot snapshot, Relation relation, Page page) && ((snapshot)->snapshot_type == SNAPSHOT_MVCC || (snapshot)->snapshot_type == SNAPSHOT_TOAST) && !XLogRecPtrIsInvalid((snapshot)->lsn) - && (!XLogIsNeeded() || PageGetLSN(page) > (snapshot)->lsn)) + && PageGetLSN(page) > (snapshot)->lsn) TestForOldSnapshot_impl(snapshot, relation); } diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f58d65cf28..35e53c8d74 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -618,8 +618,8 @@ typedef struct ViewOptions * decoding snapshot. */ #define RelationIsAccessibleInLogicalDecoding(relation) \ - (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + (XLogLogicalInfoActive() && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* -- 2.27.0 ----Next_Part(Thu_Jan_21_00_28_44_2021_003)---- ^ permalink raw reply [nested|flat] 24+ messages in thread
* [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. @ 2021-01-20 14:59 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 24+ messages in thread From: Kyotaro Horiguchi @ 2021-01-20 14:59 UTC (permalink / raw) WAL-skipping optimization omits bumping page LSN when ALTER TABLE SET TABLESPACE. Also heap_page_prune does the same. However, old_snapshot_threshold feature needs page LSN to be kept updated on these operations so that TestForOldSnapshot properly find identify whether a snapshot is invalidated. --- src/backend/access/heap/pruneheap.c | 14 ++++++++++++++ src/backend/catalog/storage.c | 8 ++++++++ src/include/storage/bufmgr.h | 3 ++- src/include/utils/rel.h | 4 ++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index e3a716a2a2..33c0841b36 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -70,6 +70,8 @@ static void heap_prune_record_redirect(PruneState *prstate, static void heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum); static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * Optionally prune and repair fragmentation in the specified page. @@ -331,6 +333,18 @@ heap_page_prune(Relation relation, Buffer buffer, PageSetLSN(BufferGetPage(buffer), recptr); } + else if (relation->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + { + XLogRecPtr currlsn = GetXLogInsertRecPtr(); + Page page = BufferGetPage(buffer); + + Assert(wal_level < WAL_LEVEL_REPLICA); + + /* we need to update page LSN to notify reader of pruning */ + if (PageGetLSN(page) == currlsn) + currlsn = gistXLogAssignLSN(); + PageSetLSN(page, currlsn); + } } else { diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index cba7a9ada0..488ac6f760 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -75,6 +75,8 @@ typedef struct PendingRelSync static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ HTAB *pendingSyncHash = NULL; +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * AddPendingSync @@ -414,6 +416,7 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, bool copying_initfork; BlockNumber nblocks; BlockNumber blkno; + XLogRecPtr fakepagelsn; page = (Page) buf.data; @@ -434,6 +437,9 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, use_wal = XLogIsNeeded() && (relpersistence == RELPERSISTENCE_PERMANENT || copying_initfork); + if (!use_wal) + fakepagelsn = gistXLogAssignLSN(); + nblocks = smgrnblocks(src, forkNum); for (blkno = 0; blkno < nblocks; blkno++) @@ -460,6 +466,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, */ if (use_wal) log_newpage(&dst->smgr_rnode.node, forkNum, blkno, page, false); + else + PageSetLSN(page, fakepagelsn); PageSetChecksumInplace(page, blkno); diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index e641174798..9ab9e7394c 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -19,6 +19,7 @@ #include "storage/buf.h" #include "storage/bufpage.h" #include "storage/relfilenode.h" +#include "utils/rel.h" #include "utils/relcache.h" #include "utils/snapmgr.h" @@ -289,7 +290,7 @@ TestForOldSnapshot(Snapshot snapshot, Relation relation, Page page) && ((snapshot)->snapshot_type == SNAPSHOT_MVCC || (snapshot)->snapshot_type == SNAPSHOT_TOAST) && !XLogRecPtrIsInvalid((snapshot)->lsn) - && (!XLogIsNeeded() || PageGetLSN(page) > (snapshot)->lsn)) + && PageGetLSN(page) > (snapshot)->lsn) TestForOldSnapshot_impl(snapshot, relation); } diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f58d65cf28..35e53c8d74 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -618,8 +618,8 @@ typedef struct ViewOptions * decoding snapshot. */ #define RelationIsAccessibleInLogicalDecoding(relation) \ - (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + (XLogLogicalInfoActive() && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* -- 2.27.0 ----Next_Part(Thu_Jan_21_00_28_44_2021_003)---- ^ permalink raw reply [nested|flat] 24+ messages in thread
* [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. @ 2021-01-20 14:59 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 24+ messages in thread From: Kyotaro Horiguchi @ 2021-01-20 14:59 UTC (permalink / raw) WAL-skipping optimization omits bumping page LSN when ALTER TABLE SET TABLESPACE. Also heap_page_prune does the same. However, old_snapshot_threshold feature needs page LSN to be kept updated on these operations so that TestForOldSnapshot properly find identify whether a snapshot is invalidated. --- src/backend/access/heap/pruneheap.c | 14 ++++++++++++++ src/backend/catalog/storage.c | 8 ++++++++ src/include/storage/bufmgr.h | 3 ++- src/include/utils/rel.h | 4 ++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index e3a716a2a2..33c0841b36 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -70,6 +70,8 @@ static void heap_prune_record_redirect(PruneState *prstate, static void heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum); static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * Optionally prune and repair fragmentation in the specified page. @@ -331,6 +333,18 @@ heap_page_prune(Relation relation, Buffer buffer, PageSetLSN(BufferGetPage(buffer), recptr); } + else if (relation->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + { + XLogRecPtr currlsn = GetXLogInsertRecPtr(); + Page page = BufferGetPage(buffer); + + Assert(wal_level < WAL_LEVEL_REPLICA); + + /* we need to update page LSN to notify reader of pruning */ + if (PageGetLSN(page) == currlsn) + currlsn = gistXLogAssignLSN(); + PageSetLSN(page, currlsn); + } } else { diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index cba7a9ada0..488ac6f760 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -75,6 +75,8 @@ typedef struct PendingRelSync static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ HTAB *pendingSyncHash = NULL; +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * AddPendingSync @@ -414,6 +416,7 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, bool copying_initfork; BlockNumber nblocks; BlockNumber blkno; + XLogRecPtr fakepagelsn; page = (Page) buf.data; @@ -434,6 +437,9 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, use_wal = XLogIsNeeded() && (relpersistence == RELPERSISTENCE_PERMANENT || copying_initfork); + if (!use_wal) + fakepagelsn = gistXLogAssignLSN(); + nblocks = smgrnblocks(src, forkNum); for (blkno = 0; blkno < nblocks; blkno++) @@ -460,6 +466,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, */ if (use_wal) log_newpage(&dst->smgr_rnode.node, forkNum, blkno, page, false); + else + PageSetLSN(page, fakepagelsn); PageSetChecksumInplace(page, blkno); diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index e641174798..9ab9e7394c 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -19,6 +19,7 @@ #include "storage/buf.h" #include "storage/bufpage.h" #include "storage/relfilenode.h" +#include "utils/rel.h" #include "utils/relcache.h" #include "utils/snapmgr.h" @@ -289,7 +290,7 @@ TestForOldSnapshot(Snapshot snapshot, Relation relation, Page page) && ((snapshot)->snapshot_type == SNAPSHOT_MVCC || (snapshot)->snapshot_type == SNAPSHOT_TOAST) && !XLogRecPtrIsInvalid((snapshot)->lsn) - && (!XLogIsNeeded() || PageGetLSN(page) > (snapshot)->lsn)) + && PageGetLSN(page) > (snapshot)->lsn) TestForOldSnapshot_impl(snapshot, relation); } diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f58d65cf28..35e53c8d74 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -618,8 +618,8 @@ typedef struct ViewOptions * decoding snapshot. */ #define RelationIsAccessibleInLogicalDecoding(relation) \ - (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + (XLogLogicalInfoActive() && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* -- 2.27.0 ----Next_Part(Thu_Jan_21_00_28_44_2021_003)---- ^ permalink raw reply [nested|flat] 24+ messages in thread
* [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. @ 2021-01-20 14:59 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 24+ messages in thread From: Kyotaro Horiguchi @ 2021-01-20 14:59 UTC (permalink / raw) WAL-skipping optimization omits bumping page LSN when ALTER TABLE SET TABLESPACE. Also heap_page_prune does the same. However, old_snapshot_threshold feature needs page LSN to be kept updated on these operations so that TestForOldSnapshot properly find identify whether a snapshot is invalidated. --- src/backend/access/heap/pruneheap.c | 14 ++++++++++++++ src/backend/catalog/storage.c | 8 ++++++++ src/include/storage/bufmgr.h | 3 ++- src/include/utils/rel.h | 4 ++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index e3a716a2a2..33c0841b36 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -70,6 +70,8 @@ static void heap_prune_record_redirect(PruneState *prstate, static void heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum); static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * Optionally prune and repair fragmentation in the specified page. @@ -331,6 +333,18 @@ heap_page_prune(Relation relation, Buffer buffer, PageSetLSN(BufferGetPage(buffer), recptr); } + else if (relation->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + { + XLogRecPtr currlsn = GetXLogInsertRecPtr(); + Page page = BufferGetPage(buffer); + + Assert(wal_level < WAL_LEVEL_REPLICA); + + /* we need to update page LSN to notify reader of pruning */ + if (PageGetLSN(page) == currlsn) + currlsn = gistXLogAssignLSN(); + PageSetLSN(page, currlsn); + } } else { diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index cba7a9ada0..488ac6f760 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -75,6 +75,8 @@ typedef struct PendingRelSync static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ HTAB *pendingSyncHash = NULL; +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * AddPendingSync @@ -414,6 +416,7 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, bool copying_initfork; BlockNumber nblocks; BlockNumber blkno; + XLogRecPtr fakepagelsn; page = (Page) buf.data; @@ -434,6 +437,9 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, use_wal = XLogIsNeeded() && (relpersistence == RELPERSISTENCE_PERMANENT || copying_initfork); + if (!use_wal) + fakepagelsn = gistXLogAssignLSN(); + nblocks = smgrnblocks(src, forkNum); for (blkno = 0; blkno < nblocks; blkno++) @@ -460,6 +466,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, */ if (use_wal) log_newpage(&dst->smgr_rnode.node, forkNum, blkno, page, false); + else + PageSetLSN(page, fakepagelsn); PageSetChecksumInplace(page, blkno); diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index e641174798..9ab9e7394c 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -19,6 +19,7 @@ #include "storage/buf.h" #include "storage/bufpage.h" #include "storage/relfilenode.h" +#include "utils/rel.h" #include "utils/relcache.h" #include "utils/snapmgr.h" @@ -289,7 +290,7 @@ TestForOldSnapshot(Snapshot snapshot, Relation relation, Page page) && ((snapshot)->snapshot_type == SNAPSHOT_MVCC || (snapshot)->snapshot_type == SNAPSHOT_TOAST) && !XLogRecPtrIsInvalid((snapshot)->lsn) - && (!XLogIsNeeded() || PageGetLSN(page) > (snapshot)->lsn)) + && PageGetLSN(page) > (snapshot)->lsn) TestForOldSnapshot_impl(snapshot, relation); } diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f58d65cf28..35e53c8d74 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -618,8 +618,8 @@ typedef struct ViewOptions * decoding snapshot. */ #define RelationIsAccessibleInLogicalDecoding(relation) \ - (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + (XLogLogicalInfoActive() && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* -- 2.27.0 ----Next_Part(Thu_Jan_21_00_28_44_2021_003)---- ^ permalink raw reply [nested|flat] 24+ messages in thread
* [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. @ 2021-01-20 14:59 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 24+ messages in thread From: Kyotaro Horiguchi @ 2021-01-20 14:59 UTC (permalink / raw) WAL-skipping optimization omits bumping page LSN when ALTER TABLE SET TABLESPACE. Also heap_page_prune does the same. However, old_snapshot_threshold feature needs page LSN to be kept updated on these operations so that TestForOldSnapshot properly find identify whether a snapshot is invalidated. --- src/backend/access/heap/pruneheap.c | 14 ++++++++++++++ src/backend/catalog/storage.c | 8 ++++++++ src/include/storage/bufmgr.h | 3 ++- src/include/utils/rel.h | 4 ++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index e3a716a2a2..33c0841b36 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -70,6 +70,8 @@ static void heap_prune_record_redirect(PruneState *prstate, static void heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum); static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * Optionally prune and repair fragmentation in the specified page. @@ -331,6 +333,18 @@ heap_page_prune(Relation relation, Buffer buffer, PageSetLSN(BufferGetPage(buffer), recptr); } + else if (relation->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + { + XLogRecPtr currlsn = GetXLogInsertRecPtr(); + Page page = BufferGetPage(buffer); + + Assert(wal_level < WAL_LEVEL_REPLICA); + + /* we need to update page LSN to notify reader of pruning */ + if (PageGetLSN(page) == currlsn) + currlsn = gistXLogAssignLSN(); + PageSetLSN(page, currlsn); + } } else { diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index cba7a9ada0..488ac6f760 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -75,6 +75,8 @@ typedef struct PendingRelSync static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ HTAB *pendingSyncHash = NULL; +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * AddPendingSync @@ -414,6 +416,7 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, bool copying_initfork; BlockNumber nblocks; BlockNumber blkno; + XLogRecPtr fakepagelsn; page = (Page) buf.data; @@ -434,6 +437,9 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, use_wal = XLogIsNeeded() && (relpersistence == RELPERSISTENCE_PERMANENT || copying_initfork); + if (!use_wal) + fakepagelsn = gistXLogAssignLSN(); + nblocks = smgrnblocks(src, forkNum); for (blkno = 0; blkno < nblocks; blkno++) @@ -460,6 +466,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, */ if (use_wal) log_newpage(&dst->smgr_rnode.node, forkNum, blkno, page, false); + else + PageSetLSN(page, fakepagelsn); PageSetChecksumInplace(page, blkno); diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index e641174798..9ab9e7394c 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -19,6 +19,7 @@ #include "storage/buf.h" #include "storage/bufpage.h" #include "storage/relfilenode.h" +#include "utils/rel.h" #include "utils/relcache.h" #include "utils/snapmgr.h" @@ -289,7 +290,7 @@ TestForOldSnapshot(Snapshot snapshot, Relation relation, Page page) && ((snapshot)->snapshot_type == SNAPSHOT_MVCC || (snapshot)->snapshot_type == SNAPSHOT_TOAST) && !XLogRecPtrIsInvalid((snapshot)->lsn) - && (!XLogIsNeeded() || PageGetLSN(page) > (snapshot)->lsn)) + && PageGetLSN(page) > (snapshot)->lsn) TestForOldSnapshot_impl(snapshot, relation); } diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f58d65cf28..35e53c8d74 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -618,8 +618,8 @@ typedef struct ViewOptions * decoding snapshot. */ #define RelationIsAccessibleInLogicalDecoding(relation) \ - (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + (XLogLogicalInfoActive() && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* -- 2.27.0 ----Next_Part(Thu_Jan_21_00_28_44_2021_003)---- ^ permalink raw reply [nested|flat] 24+ messages in thread
* [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. @ 2021-01-20 14:59 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 24+ messages in thread From: Kyotaro Horiguchi @ 2021-01-20 14:59 UTC (permalink / raw) WAL-skipping optimization omits bumping page LSN when ALTER TABLE SET TABLESPACE. Also heap_page_prune does the same. However, old_snapshot_threshold feature needs page LSN to be kept updated on these operations so that TestForOldSnapshot properly find identify whether a snapshot is invalidated. --- src/backend/access/heap/pruneheap.c | 14 ++++++++++++++ src/backend/catalog/storage.c | 8 ++++++++ src/include/storage/bufmgr.h | 3 ++- src/include/utils/rel.h | 4 ++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index e3a716a2a2..33c0841b36 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -70,6 +70,8 @@ static void heap_prune_record_redirect(PruneState *prstate, static void heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum); static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * Optionally prune and repair fragmentation in the specified page. @@ -331,6 +333,18 @@ heap_page_prune(Relation relation, Buffer buffer, PageSetLSN(BufferGetPage(buffer), recptr); } + else if (relation->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + { + XLogRecPtr currlsn = GetXLogInsertRecPtr(); + Page page = BufferGetPage(buffer); + + Assert(wal_level < WAL_LEVEL_REPLICA); + + /* we need to update page LSN to notify reader of pruning */ + if (PageGetLSN(page) == currlsn) + currlsn = gistXLogAssignLSN(); + PageSetLSN(page, currlsn); + } } else { diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index cba7a9ada0..488ac6f760 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -75,6 +75,8 @@ typedef struct PendingRelSync static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ HTAB *pendingSyncHash = NULL; +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * AddPendingSync @@ -414,6 +416,7 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, bool copying_initfork; BlockNumber nblocks; BlockNumber blkno; + XLogRecPtr fakepagelsn; page = (Page) buf.data; @@ -434,6 +437,9 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, use_wal = XLogIsNeeded() && (relpersistence == RELPERSISTENCE_PERMANENT || copying_initfork); + if (!use_wal) + fakepagelsn = gistXLogAssignLSN(); + nblocks = smgrnblocks(src, forkNum); for (blkno = 0; blkno < nblocks; blkno++) @@ -460,6 +466,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, */ if (use_wal) log_newpage(&dst->smgr_rnode.node, forkNum, blkno, page, false); + else + PageSetLSN(page, fakepagelsn); PageSetChecksumInplace(page, blkno); diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index e641174798..9ab9e7394c 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -19,6 +19,7 @@ #include "storage/buf.h" #include "storage/bufpage.h" #include "storage/relfilenode.h" +#include "utils/rel.h" #include "utils/relcache.h" #include "utils/snapmgr.h" @@ -289,7 +290,7 @@ TestForOldSnapshot(Snapshot snapshot, Relation relation, Page page) && ((snapshot)->snapshot_type == SNAPSHOT_MVCC || (snapshot)->snapshot_type == SNAPSHOT_TOAST) && !XLogRecPtrIsInvalid((snapshot)->lsn) - && (!XLogIsNeeded() || PageGetLSN(page) > (snapshot)->lsn)) + && PageGetLSN(page) > (snapshot)->lsn) TestForOldSnapshot_impl(snapshot, relation); } diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f58d65cf28..35e53c8d74 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -618,8 +618,8 @@ typedef struct ViewOptions * decoding snapshot. */ #define RelationIsAccessibleInLogicalDecoding(relation) \ - (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + (XLogLogicalInfoActive() && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* -- 2.27.0 ----Next_Part(Thu_Jan_21_00_28_44_2021_003)---- ^ permalink raw reply [nested|flat] 24+ messages in thread
* [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. @ 2021-01-20 14:59 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 24+ messages in thread From: Kyotaro Horiguchi @ 2021-01-20 14:59 UTC (permalink / raw) WAL-skipping optimization omits bumping page LSN when ALTER TABLE SET TABLESPACE. Also heap_page_prune does the same. However, old_snapshot_threshold feature needs page LSN to be kept updated on these operations so that TestForOldSnapshot properly find identify whether a snapshot is invalidated. --- src/backend/access/heap/pruneheap.c | 14 ++++++++++++++ src/backend/catalog/storage.c | 8 ++++++++ src/include/storage/bufmgr.h | 3 ++- src/include/utils/rel.h | 4 ++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index e3a716a2a2..33c0841b36 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -70,6 +70,8 @@ static void heap_prune_record_redirect(PruneState *prstate, static void heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum); static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * Optionally prune and repair fragmentation in the specified page. @@ -331,6 +333,18 @@ heap_page_prune(Relation relation, Buffer buffer, PageSetLSN(BufferGetPage(buffer), recptr); } + else if (relation->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + { + XLogRecPtr currlsn = GetXLogInsertRecPtr(); + Page page = BufferGetPage(buffer); + + Assert(wal_level < WAL_LEVEL_REPLICA); + + /* we need to update page LSN to notify reader of pruning */ + if (PageGetLSN(page) == currlsn) + currlsn = gistXLogAssignLSN(); + PageSetLSN(page, currlsn); + } } else { diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index cba7a9ada0..488ac6f760 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -75,6 +75,8 @@ typedef struct PendingRelSync static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ HTAB *pendingSyncHash = NULL; +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * AddPendingSync @@ -414,6 +416,7 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, bool copying_initfork; BlockNumber nblocks; BlockNumber blkno; + XLogRecPtr fakepagelsn; page = (Page) buf.data; @@ -434,6 +437,9 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, use_wal = XLogIsNeeded() && (relpersistence == RELPERSISTENCE_PERMANENT || copying_initfork); + if (!use_wal) + fakepagelsn = gistXLogAssignLSN(); + nblocks = smgrnblocks(src, forkNum); for (blkno = 0; blkno < nblocks; blkno++) @@ -460,6 +466,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, */ if (use_wal) log_newpage(&dst->smgr_rnode.node, forkNum, blkno, page, false); + else + PageSetLSN(page, fakepagelsn); PageSetChecksumInplace(page, blkno); diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index e641174798..9ab9e7394c 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -19,6 +19,7 @@ #include "storage/buf.h" #include "storage/bufpage.h" #include "storage/relfilenode.h" +#include "utils/rel.h" #include "utils/relcache.h" #include "utils/snapmgr.h" @@ -289,7 +290,7 @@ TestForOldSnapshot(Snapshot snapshot, Relation relation, Page page) && ((snapshot)->snapshot_type == SNAPSHOT_MVCC || (snapshot)->snapshot_type == SNAPSHOT_TOAST) && !XLogRecPtrIsInvalid((snapshot)->lsn) - && (!XLogIsNeeded() || PageGetLSN(page) > (snapshot)->lsn)) + && PageGetLSN(page) > (snapshot)->lsn) TestForOldSnapshot_impl(snapshot, relation); } diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f58d65cf28..35e53c8d74 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -618,8 +618,8 @@ typedef struct ViewOptions * decoding snapshot. */ #define RelationIsAccessibleInLogicalDecoding(relation) \ - (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + (XLogLogicalInfoActive() && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* -- 2.27.0 ----Next_Part(Thu_Jan_21_00_28_44_2021_003)---- ^ permalink raw reply [nested|flat] 24+ messages in thread
* [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. @ 2021-01-20 14:59 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 24+ messages in thread From: Kyotaro Horiguchi @ 2021-01-20 14:59 UTC (permalink / raw) WAL-skipping optimization omits bumping page LSN when ALTER TABLE SET TABLESPACE. Also heap_page_prune does the same. However, old_snapshot_threshold feature needs page LSN to be kept updated on these operations so that TestForOldSnapshot properly find identify whether a snapshot is invalidated. --- src/backend/access/heap/pruneheap.c | 14 ++++++++++++++ src/backend/catalog/storage.c | 8 ++++++++ src/include/storage/bufmgr.h | 3 ++- src/include/utils/rel.h | 4 ++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index e3a716a2a2..33c0841b36 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -70,6 +70,8 @@ static void heap_prune_record_redirect(PruneState *prstate, static void heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum); static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * Optionally prune and repair fragmentation in the specified page. @@ -331,6 +333,18 @@ heap_page_prune(Relation relation, Buffer buffer, PageSetLSN(BufferGetPage(buffer), recptr); } + else if (relation->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + { + XLogRecPtr currlsn = GetXLogInsertRecPtr(); + Page page = BufferGetPage(buffer); + + Assert(wal_level < WAL_LEVEL_REPLICA); + + /* we need to update page LSN to notify reader of pruning */ + if (PageGetLSN(page) == currlsn) + currlsn = gistXLogAssignLSN(); + PageSetLSN(page, currlsn); + } } else { diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index cba7a9ada0..488ac6f760 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -75,6 +75,8 @@ typedef struct PendingRelSync static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ HTAB *pendingSyncHash = NULL; +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * AddPendingSync @@ -414,6 +416,7 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, bool copying_initfork; BlockNumber nblocks; BlockNumber blkno; + XLogRecPtr fakepagelsn; page = (Page) buf.data; @@ -434,6 +437,9 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, use_wal = XLogIsNeeded() && (relpersistence == RELPERSISTENCE_PERMANENT || copying_initfork); + if (!use_wal) + fakepagelsn = gistXLogAssignLSN(); + nblocks = smgrnblocks(src, forkNum); for (blkno = 0; blkno < nblocks; blkno++) @@ -460,6 +466,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, */ if (use_wal) log_newpage(&dst->smgr_rnode.node, forkNum, blkno, page, false); + else + PageSetLSN(page, fakepagelsn); PageSetChecksumInplace(page, blkno); diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index e641174798..9ab9e7394c 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -19,6 +19,7 @@ #include "storage/buf.h" #include "storage/bufpage.h" #include "storage/relfilenode.h" +#include "utils/rel.h" #include "utils/relcache.h" #include "utils/snapmgr.h" @@ -289,7 +290,7 @@ TestForOldSnapshot(Snapshot snapshot, Relation relation, Page page) && ((snapshot)->snapshot_type == SNAPSHOT_MVCC || (snapshot)->snapshot_type == SNAPSHOT_TOAST) && !XLogRecPtrIsInvalid((snapshot)->lsn) - && (!XLogIsNeeded() || PageGetLSN(page) > (snapshot)->lsn)) + && PageGetLSN(page) > (snapshot)->lsn) TestForOldSnapshot_impl(snapshot, relation); } diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f58d65cf28..35e53c8d74 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -618,8 +618,8 @@ typedef struct ViewOptions * decoding snapshot. */ #define RelationIsAccessibleInLogicalDecoding(relation) \ - (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + (XLogLogicalInfoActive() && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* -- 2.27.0 ----Next_Part(Thu_Jan_21_00_28_44_2021_003)---- ^ permalink raw reply [nested|flat] 24+ messages in thread
* [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. @ 2021-01-20 14:59 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 24+ messages in thread From: Kyotaro Horiguchi @ 2021-01-20 14:59 UTC (permalink / raw) WAL-skipping optimization omits bumping page LSN when ALTER TABLE SET TABLESPACE. Also heap_page_prune does the same. However, old_snapshot_threshold feature needs page LSN to be kept updated on these operations so that TestForOldSnapshot properly find identify whether a snapshot is invalidated. --- src/backend/access/heap/pruneheap.c | 14 ++++++++++++++ src/backend/catalog/storage.c | 8 ++++++++ src/include/storage/bufmgr.h | 3 ++- src/include/utils/rel.h | 4 ++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index e3a716a2a2..33c0841b36 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -70,6 +70,8 @@ static void heap_prune_record_redirect(PruneState *prstate, static void heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum); static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * Optionally prune and repair fragmentation in the specified page. @@ -331,6 +333,18 @@ heap_page_prune(Relation relation, Buffer buffer, PageSetLSN(BufferGetPage(buffer), recptr); } + else if (relation->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + { + XLogRecPtr currlsn = GetXLogInsertRecPtr(); + Page page = BufferGetPage(buffer); + + Assert(wal_level < WAL_LEVEL_REPLICA); + + /* we need to update page LSN to notify reader of pruning */ + if (PageGetLSN(page) == currlsn) + currlsn = gistXLogAssignLSN(); + PageSetLSN(page, currlsn); + } } else { diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index cba7a9ada0..488ac6f760 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -75,6 +75,8 @@ typedef struct PendingRelSync static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ HTAB *pendingSyncHash = NULL; +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * AddPendingSync @@ -414,6 +416,7 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, bool copying_initfork; BlockNumber nblocks; BlockNumber blkno; + XLogRecPtr fakepagelsn; page = (Page) buf.data; @@ -434,6 +437,9 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, use_wal = XLogIsNeeded() && (relpersistence == RELPERSISTENCE_PERMANENT || copying_initfork); + if (!use_wal) + fakepagelsn = gistXLogAssignLSN(); + nblocks = smgrnblocks(src, forkNum); for (blkno = 0; blkno < nblocks; blkno++) @@ -460,6 +466,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, */ if (use_wal) log_newpage(&dst->smgr_rnode.node, forkNum, blkno, page, false); + else + PageSetLSN(page, fakepagelsn); PageSetChecksumInplace(page, blkno); diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index e641174798..9ab9e7394c 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -19,6 +19,7 @@ #include "storage/buf.h" #include "storage/bufpage.h" #include "storage/relfilenode.h" +#include "utils/rel.h" #include "utils/relcache.h" #include "utils/snapmgr.h" @@ -289,7 +290,7 @@ TestForOldSnapshot(Snapshot snapshot, Relation relation, Page page) && ((snapshot)->snapshot_type == SNAPSHOT_MVCC || (snapshot)->snapshot_type == SNAPSHOT_TOAST) && !XLogRecPtrIsInvalid((snapshot)->lsn) - && (!XLogIsNeeded() || PageGetLSN(page) > (snapshot)->lsn)) + && PageGetLSN(page) > (snapshot)->lsn) TestForOldSnapshot_impl(snapshot, relation); } diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f58d65cf28..35e53c8d74 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -618,8 +618,8 @@ typedef struct ViewOptions * decoding snapshot. */ #define RelationIsAccessibleInLogicalDecoding(relation) \ - (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + (XLogLogicalInfoActive() && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* -- 2.27.0 ----Next_Part(Thu_Jan_21_00_28_44_2021_003)---- ^ permalink raw reply [nested|flat] 24+ messages in thread
* [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. @ 2021-01-20 14:59 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 24+ messages in thread From: Kyotaro Horiguchi @ 2021-01-20 14:59 UTC (permalink / raw) WAL-skipping optimization omits bumping page LSN when ALTER TABLE SET TABLESPACE. Also heap_page_prune does the same. However, old_snapshot_threshold feature needs page LSN to be kept updated on these operations so that TestForOldSnapshot properly find identify whether a snapshot is invalidated. --- src/backend/access/heap/pruneheap.c | 14 ++++++++++++++ src/backend/catalog/storage.c | 8 ++++++++ src/include/storage/bufmgr.h | 3 ++- src/include/utils/rel.h | 4 ++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index e3a716a2a2..33c0841b36 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -70,6 +70,8 @@ static void heap_prune_record_redirect(PruneState *prstate, static void heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum); static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * Optionally prune and repair fragmentation in the specified page. @@ -331,6 +333,18 @@ heap_page_prune(Relation relation, Buffer buffer, PageSetLSN(BufferGetPage(buffer), recptr); } + else if (relation->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + { + XLogRecPtr currlsn = GetXLogInsertRecPtr(); + Page page = BufferGetPage(buffer); + + Assert(wal_level < WAL_LEVEL_REPLICA); + + /* we need to update page LSN to notify reader of pruning */ + if (PageGetLSN(page) == currlsn) + currlsn = gistXLogAssignLSN(); + PageSetLSN(page, currlsn); + } } else { diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index cba7a9ada0..488ac6f760 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -75,6 +75,8 @@ typedef struct PendingRelSync static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ HTAB *pendingSyncHash = NULL; +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * AddPendingSync @@ -414,6 +416,7 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, bool copying_initfork; BlockNumber nblocks; BlockNumber blkno; + XLogRecPtr fakepagelsn; page = (Page) buf.data; @@ -434,6 +437,9 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, use_wal = XLogIsNeeded() && (relpersistence == RELPERSISTENCE_PERMANENT || copying_initfork); + if (!use_wal) + fakepagelsn = gistXLogAssignLSN(); + nblocks = smgrnblocks(src, forkNum); for (blkno = 0; blkno < nblocks; blkno++) @@ -460,6 +466,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, */ if (use_wal) log_newpage(&dst->smgr_rnode.node, forkNum, blkno, page, false); + else + PageSetLSN(page, fakepagelsn); PageSetChecksumInplace(page, blkno); diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index e641174798..9ab9e7394c 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -19,6 +19,7 @@ #include "storage/buf.h" #include "storage/bufpage.h" #include "storage/relfilenode.h" +#include "utils/rel.h" #include "utils/relcache.h" #include "utils/snapmgr.h" @@ -289,7 +290,7 @@ TestForOldSnapshot(Snapshot snapshot, Relation relation, Page page) && ((snapshot)->snapshot_type == SNAPSHOT_MVCC || (snapshot)->snapshot_type == SNAPSHOT_TOAST) && !XLogRecPtrIsInvalid((snapshot)->lsn) - && (!XLogIsNeeded() || PageGetLSN(page) > (snapshot)->lsn)) + && PageGetLSN(page) > (snapshot)->lsn) TestForOldSnapshot_impl(snapshot, relation); } diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f58d65cf28..35e53c8d74 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -618,8 +618,8 @@ typedef struct ViewOptions * decoding snapshot. */ #define RelationIsAccessibleInLogicalDecoding(relation) \ - (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + (XLogLogicalInfoActive() && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* -- 2.27.0 ----Next_Part(Thu_Jan_21_00_28_44_2021_003)---- ^ permalink raw reply [nested|flat] 24+ messages in thread
* [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. @ 2021-01-20 14:59 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 24+ messages in thread From: Kyotaro Horiguchi @ 2021-01-20 14:59 UTC (permalink / raw) WAL-skipping optimization omits bumping page LSN when ALTER TABLE SET TABLESPACE. Also heap_page_prune does the same. However, old_snapshot_threshold feature needs page LSN to be kept updated on these operations so that TestForOldSnapshot properly find identify whether a snapshot is invalidated. --- src/backend/access/heap/pruneheap.c | 14 ++++++++++++++ src/backend/catalog/storage.c | 8 ++++++++ src/include/storage/bufmgr.h | 3 ++- src/include/utils/rel.h | 4 ++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index e3a716a2a2..33c0841b36 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -70,6 +70,8 @@ static void heap_prune_record_redirect(PruneState *prstate, static void heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum); static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * Optionally prune and repair fragmentation in the specified page. @@ -331,6 +333,18 @@ heap_page_prune(Relation relation, Buffer buffer, PageSetLSN(BufferGetPage(buffer), recptr); } + else if (relation->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + { + XLogRecPtr currlsn = GetXLogInsertRecPtr(); + Page page = BufferGetPage(buffer); + + Assert(wal_level < WAL_LEVEL_REPLICA); + + /* we need to update page LSN to notify reader of pruning */ + if (PageGetLSN(page) == currlsn) + currlsn = gistXLogAssignLSN(); + PageSetLSN(page, currlsn); + } } else { diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index cba7a9ada0..488ac6f760 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -75,6 +75,8 @@ typedef struct PendingRelSync static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ HTAB *pendingSyncHash = NULL; +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * AddPendingSync @@ -414,6 +416,7 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, bool copying_initfork; BlockNumber nblocks; BlockNumber blkno; + XLogRecPtr fakepagelsn; page = (Page) buf.data; @@ -434,6 +437,9 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, use_wal = XLogIsNeeded() && (relpersistence == RELPERSISTENCE_PERMANENT || copying_initfork); + if (!use_wal) + fakepagelsn = gistXLogAssignLSN(); + nblocks = smgrnblocks(src, forkNum); for (blkno = 0; blkno < nblocks; blkno++) @@ -460,6 +466,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, */ if (use_wal) log_newpage(&dst->smgr_rnode.node, forkNum, blkno, page, false); + else + PageSetLSN(page, fakepagelsn); PageSetChecksumInplace(page, blkno); diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index e641174798..9ab9e7394c 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -19,6 +19,7 @@ #include "storage/buf.h" #include "storage/bufpage.h" #include "storage/relfilenode.h" +#include "utils/rel.h" #include "utils/relcache.h" #include "utils/snapmgr.h" @@ -289,7 +290,7 @@ TestForOldSnapshot(Snapshot snapshot, Relation relation, Page page) && ((snapshot)->snapshot_type == SNAPSHOT_MVCC || (snapshot)->snapshot_type == SNAPSHOT_TOAST) && !XLogRecPtrIsInvalid((snapshot)->lsn) - && (!XLogIsNeeded() || PageGetLSN(page) > (snapshot)->lsn)) + && PageGetLSN(page) > (snapshot)->lsn) TestForOldSnapshot_impl(snapshot, relation); } diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f58d65cf28..35e53c8d74 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -618,8 +618,8 @@ typedef struct ViewOptions * decoding snapshot. */ #define RelationIsAccessibleInLogicalDecoding(relation) \ - (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + (XLogLogicalInfoActive() && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* -- 2.27.0 ----Next_Part(Thu_Jan_21_00_28_44_2021_003)---- ^ permalink raw reply [nested|flat] 24+ messages in thread
* [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. @ 2021-01-20 14:59 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 24+ messages in thread From: Kyotaro Horiguchi @ 2021-01-20 14:59 UTC (permalink / raw) WAL-skipping optimization omits bumping page LSN when ALTER TABLE SET TABLESPACE. Also heap_page_prune does the same. However, old_snapshot_threshold feature needs page LSN to be kept updated on these operations so that TestForOldSnapshot properly find identify whether a snapshot is invalidated. --- src/backend/access/heap/pruneheap.c | 14 ++++++++++++++ src/backend/catalog/storage.c | 8 ++++++++ src/include/storage/bufmgr.h | 3 ++- src/include/utils/rel.h | 4 ++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index e3a716a2a2..33c0841b36 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -70,6 +70,8 @@ static void heap_prune_record_redirect(PruneState *prstate, static void heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum); static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * Optionally prune and repair fragmentation in the specified page. @@ -331,6 +333,18 @@ heap_page_prune(Relation relation, Buffer buffer, PageSetLSN(BufferGetPage(buffer), recptr); } + else if (relation->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + { + XLogRecPtr currlsn = GetXLogInsertRecPtr(); + Page page = BufferGetPage(buffer); + + Assert(wal_level < WAL_LEVEL_REPLICA); + + /* we need to update page LSN to notify reader of pruning */ + if (PageGetLSN(page) == currlsn) + currlsn = gistXLogAssignLSN(); + PageSetLSN(page, currlsn); + } } else { diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index cba7a9ada0..488ac6f760 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -75,6 +75,8 @@ typedef struct PendingRelSync static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ HTAB *pendingSyncHash = NULL; +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * AddPendingSync @@ -414,6 +416,7 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, bool copying_initfork; BlockNumber nblocks; BlockNumber blkno; + XLogRecPtr fakepagelsn; page = (Page) buf.data; @@ -434,6 +437,9 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, use_wal = XLogIsNeeded() && (relpersistence == RELPERSISTENCE_PERMANENT || copying_initfork); + if (!use_wal) + fakepagelsn = gistXLogAssignLSN(); + nblocks = smgrnblocks(src, forkNum); for (blkno = 0; blkno < nblocks; blkno++) @@ -460,6 +466,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, */ if (use_wal) log_newpage(&dst->smgr_rnode.node, forkNum, blkno, page, false); + else + PageSetLSN(page, fakepagelsn); PageSetChecksumInplace(page, blkno); diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index e641174798..9ab9e7394c 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -19,6 +19,7 @@ #include "storage/buf.h" #include "storage/bufpage.h" #include "storage/relfilenode.h" +#include "utils/rel.h" #include "utils/relcache.h" #include "utils/snapmgr.h" @@ -289,7 +290,7 @@ TestForOldSnapshot(Snapshot snapshot, Relation relation, Page page) && ((snapshot)->snapshot_type == SNAPSHOT_MVCC || (snapshot)->snapshot_type == SNAPSHOT_TOAST) && !XLogRecPtrIsInvalid((snapshot)->lsn) - && (!XLogIsNeeded() || PageGetLSN(page) > (snapshot)->lsn)) + && PageGetLSN(page) > (snapshot)->lsn) TestForOldSnapshot_impl(snapshot, relation); } diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f58d65cf28..35e53c8d74 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -618,8 +618,8 @@ typedef struct ViewOptions * decoding snapshot. */ #define RelationIsAccessibleInLogicalDecoding(relation) \ - (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + (XLogLogicalInfoActive() && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* -- 2.27.0 ----Next_Part(Thu_Jan_21_00_28_44_2021_003)---- ^ permalink raw reply [nested|flat] 24+ messages in thread
* [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. @ 2021-01-20 14:59 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 24+ messages in thread From: Kyotaro Horiguchi @ 2021-01-20 14:59 UTC (permalink / raw) WAL-skipping optimization omits bumping page LSN when ALTER TABLE SET TABLESPACE. Also heap_page_prune does the same. However, old_snapshot_threshold feature needs page LSN to be kept updated on these operations so that TestForOldSnapshot properly find identify whether a snapshot is invalidated. --- src/backend/access/heap/pruneheap.c | 14 ++++++++++++++ src/backend/catalog/storage.c | 8 ++++++++ src/include/storage/bufmgr.h | 3 ++- src/include/utils/rel.h | 4 ++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index e3a716a2a2..33c0841b36 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -70,6 +70,8 @@ static void heap_prune_record_redirect(PruneState *prstate, static void heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum); static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * Optionally prune and repair fragmentation in the specified page. @@ -331,6 +333,18 @@ heap_page_prune(Relation relation, Buffer buffer, PageSetLSN(BufferGetPage(buffer), recptr); } + else if (relation->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + { + XLogRecPtr currlsn = GetXLogInsertRecPtr(); + Page page = BufferGetPage(buffer); + + Assert(wal_level < WAL_LEVEL_REPLICA); + + /* we need to update page LSN to notify reader of pruning */ + if (PageGetLSN(page) == currlsn) + currlsn = gistXLogAssignLSN(); + PageSetLSN(page, currlsn); + } } else { diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index cba7a9ada0..488ac6f760 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -75,6 +75,8 @@ typedef struct PendingRelSync static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ HTAB *pendingSyncHash = NULL; +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * AddPendingSync @@ -414,6 +416,7 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, bool copying_initfork; BlockNumber nblocks; BlockNumber blkno; + XLogRecPtr fakepagelsn; page = (Page) buf.data; @@ -434,6 +437,9 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, use_wal = XLogIsNeeded() && (relpersistence == RELPERSISTENCE_PERMANENT || copying_initfork); + if (!use_wal) + fakepagelsn = gistXLogAssignLSN(); + nblocks = smgrnblocks(src, forkNum); for (blkno = 0; blkno < nblocks; blkno++) @@ -460,6 +466,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, */ if (use_wal) log_newpage(&dst->smgr_rnode.node, forkNum, blkno, page, false); + else + PageSetLSN(page, fakepagelsn); PageSetChecksumInplace(page, blkno); diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index e641174798..9ab9e7394c 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -19,6 +19,7 @@ #include "storage/buf.h" #include "storage/bufpage.h" #include "storage/relfilenode.h" +#include "utils/rel.h" #include "utils/relcache.h" #include "utils/snapmgr.h" @@ -289,7 +290,7 @@ TestForOldSnapshot(Snapshot snapshot, Relation relation, Page page) && ((snapshot)->snapshot_type == SNAPSHOT_MVCC || (snapshot)->snapshot_type == SNAPSHOT_TOAST) && !XLogRecPtrIsInvalid((snapshot)->lsn) - && (!XLogIsNeeded() || PageGetLSN(page) > (snapshot)->lsn)) + && PageGetLSN(page) > (snapshot)->lsn) TestForOldSnapshot_impl(snapshot, relation); } diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f58d65cf28..35e53c8d74 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -618,8 +618,8 @@ typedef struct ViewOptions * decoding snapshot. */ #define RelationIsAccessibleInLogicalDecoding(relation) \ - (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + (XLogLogicalInfoActive() && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* -- 2.27.0 ----Next_Part(Thu_Jan_21_00_28_44_2021_003)---- ^ permalink raw reply [nested|flat] 24+ messages in thread
* [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. @ 2021-01-20 14:59 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 24+ messages in thread From: Kyotaro Horiguchi @ 2021-01-20 14:59 UTC (permalink / raw) WAL-skipping optimization omits bumping page LSN when ALTER TABLE SET TABLESPACE. Also heap_page_prune does the same. However, old_snapshot_threshold feature needs page LSN to be kept updated on these operations so that TestForOldSnapshot properly find identify whether a snapshot is invalidated. --- src/backend/access/heap/pruneheap.c | 14 ++++++++++++++ src/backend/catalog/storage.c | 8 ++++++++ src/include/storage/bufmgr.h | 3 ++- src/include/utils/rel.h | 4 ++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index e3a716a2a2..33c0841b36 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -70,6 +70,8 @@ static void heap_prune_record_redirect(PruneState *prstate, static void heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum); static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * Optionally prune and repair fragmentation in the specified page. @@ -331,6 +333,18 @@ heap_page_prune(Relation relation, Buffer buffer, PageSetLSN(BufferGetPage(buffer), recptr); } + else if (relation->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + { + XLogRecPtr currlsn = GetXLogInsertRecPtr(); + Page page = BufferGetPage(buffer); + + Assert(wal_level < WAL_LEVEL_REPLICA); + + /* we need to update page LSN to notify reader of pruning */ + if (PageGetLSN(page) == currlsn) + currlsn = gistXLogAssignLSN(); + PageSetLSN(page, currlsn); + } } else { diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index cba7a9ada0..488ac6f760 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -75,6 +75,8 @@ typedef struct PendingRelSync static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ HTAB *pendingSyncHash = NULL; +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * AddPendingSync @@ -414,6 +416,7 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, bool copying_initfork; BlockNumber nblocks; BlockNumber blkno; + XLogRecPtr fakepagelsn; page = (Page) buf.data; @@ -434,6 +437,9 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, use_wal = XLogIsNeeded() && (relpersistence == RELPERSISTENCE_PERMANENT || copying_initfork); + if (!use_wal) + fakepagelsn = gistXLogAssignLSN(); + nblocks = smgrnblocks(src, forkNum); for (blkno = 0; blkno < nblocks; blkno++) @@ -460,6 +466,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, */ if (use_wal) log_newpage(&dst->smgr_rnode.node, forkNum, blkno, page, false); + else + PageSetLSN(page, fakepagelsn); PageSetChecksumInplace(page, blkno); diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index e641174798..9ab9e7394c 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -19,6 +19,7 @@ #include "storage/buf.h" #include "storage/bufpage.h" #include "storage/relfilenode.h" +#include "utils/rel.h" #include "utils/relcache.h" #include "utils/snapmgr.h" @@ -289,7 +290,7 @@ TestForOldSnapshot(Snapshot snapshot, Relation relation, Page page) && ((snapshot)->snapshot_type == SNAPSHOT_MVCC || (snapshot)->snapshot_type == SNAPSHOT_TOAST) && !XLogRecPtrIsInvalid((snapshot)->lsn) - && (!XLogIsNeeded() || PageGetLSN(page) > (snapshot)->lsn)) + && PageGetLSN(page) > (snapshot)->lsn) TestForOldSnapshot_impl(snapshot, relation); } diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f58d65cf28..35e53c8d74 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -618,8 +618,8 @@ typedef struct ViewOptions * decoding snapshot. */ #define RelationIsAccessibleInLogicalDecoding(relation) \ - (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + (XLogLogicalInfoActive() && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* -- 2.27.0 ----Next_Part(Thu_Jan_21_00_28_44_2021_003)---- ^ permalink raw reply [nested|flat] 24+ messages in thread
* [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. @ 2021-01-20 14:59 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 24+ messages in thread From: Kyotaro Horiguchi @ 2021-01-20 14:59 UTC (permalink / raw) WAL-skipping optimization omits bumping page LSN when ALTER TABLE SET TABLESPACE. Also heap_page_prune does the same. However, old_snapshot_threshold feature needs page LSN to be kept updated on these operations so that TestForOldSnapshot properly find identify whether a snapshot is invalidated. --- src/backend/access/heap/pruneheap.c | 14 ++++++++++++++ src/backend/catalog/storage.c | 8 ++++++++ src/include/storage/bufmgr.h | 3 ++- src/include/utils/rel.h | 4 ++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index e3a716a2a2..33c0841b36 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -70,6 +70,8 @@ static void heap_prune_record_redirect(PruneState *prstate, static void heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum); static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * Optionally prune and repair fragmentation in the specified page. @@ -331,6 +333,18 @@ heap_page_prune(Relation relation, Buffer buffer, PageSetLSN(BufferGetPage(buffer), recptr); } + else if (relation->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + { + XLogRecPtr currlsn = GetXLogInsertRecPtr(); + Page page = BufferGetPage(buffer); + + Assert(wal_level < WAL_LEVEL_REPLICA); + + /* we need to update page LSN to notify reader of pruning */ + if (PageGetLSN(page) == currlsn) + currlsn = gistXLogAssignLSN(); + PageSetLSN(page, currlsn); + } } else { diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index cba7a9ada0..488ac6f760 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -75,6 +75,8 @@ typedef struct PendingRelSync static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ HTAB *pendingSyncHash = NULL; +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * AddPendingSync @@ -414,6 +416,7 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, bool copying_initfork; BlockNumber nblocks; BlockNumber blkno; + XLogRecPtr fakepagelsn; page = (Page) buf.data; @@ -434,6 +437,9 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, use_wal = XLogIsNeeded() && (relpersistence == RELPERSISTENCE_PERMANENT || copying_initfork); + if (!use_wal) + fakepagelsn = gistXLogAssignLSN(); + nblocks = smgrnblocks(src, forkNum); for (blkno = 0; blkno < nblocks; blkno++) @@ -460,6 +466,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, */ if (use_wal) log_newpage(&dst->smgr_rnode.node, forkNum, blkno, page, false); + else + PageSetLSN(page, fakepagelsn); PageSetChecksumInplace(page, blkno); diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index e641174798..9ab9e7394c 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -19,6 +19,7 @@ #include "storage/buf.h" #include "storage/bufpage.h" #include "storage/relfilenode.h" +#include "utils/rel.h" #include "utils/relcache.h" #include "utils/snapmgr.h" @@ -289,7 +290,7 @@ TestForOldSnapshot(Snapshot snapshot, Relation relation, Page page) && ((snapshot)->snapshot_type == SNAPSHOT_MVCC || (snapshot)->snapshot_type == SNAPSHOT_TOAST) && !XLogRecPtrIsInvalid((snapshot)->lsn) - && (!XLogIsNeeded() || PageGetLSN(page) > (snapshot)->lsn)) + && PageGetLSN(page) > (snapshot)->lsn) TestForOldSnapshot_impl(snapshot, relation); } diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f58d65cf28..35e53c8d74 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -618,8 +618,8 @@ typedef struct ViewOptions * decoding snapshot. */ #define RelationIsAccessibleInLogicalDecoding(relation) \ - (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + (XLogLogicalInfoActive() && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* -- 2.27.0 ----Next_Part(Thu_Jan_21_00_28_44_2021_003)---- ^ permalink raw reply [nested|flat] 24+ messages in thread
* [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. @ 2021-01-20 14:59 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 24+ messages in thread From: Kyotaro Horiguchi @ 2021-01-20 14:59 UTC (permalink / raw) WAL-skipping optimization omits bumping page LSN when ALTER TABLE SET TABLESPACE. Also heap_page_prune does the same. However, old_snapshot_threshold feature needs page LSN to be kept updated on these operations so that TestForOldSnapshot properly find identify whether a snapshot is invalidated. --- src/backend/access/heap/pruneheap.c | 14 ++++++++++++++ src/backend/catalog/storage.c | 8 ++++++++ src/include/storage/bufmgr.h | 3 ++- src/include/utils/rel.h | 4 ++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index e3a716a2a2..33c0841b36 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -70,6 +70,8 @@ static void heap_prune_record_redirect(PruneState *prstate, static void heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum); static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * Optionally prune and repair fragmentation in the specified page. @@ -331,6 +333,18 @@ heap_page_prune(Relation relation, Buffer buffer, PageSetLSN(BufferGetPage(buffer), recptr); } + else if (relation->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + { + XLogRecPtr currlsn = GetXLogInsertRecPtr(); + Page page = BufferGetPage(buffer); + + Assert(wal_level < WAL_LEVEL_REPLICA); + + /* we need to update page LSN to notify reader of pruning */ + if (PageGetLSN(page) == currlsn) + currlsn = gistXLogAssignLSN(); + PageSetLSN(page, currlsn); + } } else { diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index cba7a9ada0..488ac6f760 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -75,6 +75,8 @@ typedef struct PendingRelSync static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ HTAB *pendingSyncHash = NULL; +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * AddPendingSync @@ -414,6 +416,7 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, bool copying_initfork; BlockNumber nblocks; BlockNumber blkno; + XLogRecPtr fakepagelsn; page = (Page) buf.data; @@ -434,6 +437,9 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, use_wal = XLogIsNeeded() && (relpersistence == RELPERSISTENCE_PERMANENT || copying_initfork); + if (!use_wal) + fakepagelsn = gistXLogAssignLSN(); + nblocks = smgrnblocks(src, forkNum); for (blkno = 0; blkno < nblocks; blkno++) @@ -460,6 +466,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, */ if (use_wal) log_newpage(&dst->smgr_rnode.node, forkNum, blkno, page, false); + else + PageSetLSN(page, fakepagelsn); PageSetChecksumInplace(page, blkno); diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index e641174798..9ab9e7394c 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -19,6 +19,7 @@ #include "storage/buf.h" #include "storage/bufpage.h" #include "storage/relfilenode.h" +#include "utils/rel.h" #include "utils/relcache.h" #include "utils/snapmgr.h" @@ -289,7 +290,7 @@ TestForOldSnapshot(Snapshot snapshot, Relation relation, Page page) && ((snapshot)->snapshot_type == SNAPSHOT_MVCC || (snapshot)->snapshot_type == SNAPSHOT_TOAST) && !XLogRecPtrIsInvalid((snapshot)->lsn) - && (!XLogIsNeeded() || PageGetLSN(page) > (snapshot)->lsn)) + && PageGetLSN(page) > (snapshot)->lsn) TestForOldSnapshot_impl(snapshot, relation); } diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f58d65cf28..35e53c8d74 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -618,8 +618,8 @@ typedef struct ViewOptions * decoding snapshot. */ #define RelationIsAccessibleInLogicalDecoding(relation) \ - (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + (XLogLogicalInfoActive() && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* -- 2.27.0 ----Next_Part(Thu_Jan_21_00_28_44_2021_003)---- ^ permalink raw reply [nested|flat] 24+ messages in thread
* [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. @ 2021-01-20 14:59 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 24+ messages in thread From: Kyotaro Horiguchi @ 2021-01-20 14:59 UTC (permalink / raw) WAL-skipping optimization omits bumping page LSN when ALTER TABLE SET TABLESPACE. Also heap_page_prune does the same. However, old_snapshot_threshold feature needs page LSN to be kept updated on these operations so that TestForOldSnapshot properly find identify whether a snapshot is invalidated. --- src/backend/access/heap/pruneheap.c | 14 ++++++++++++++ src/backend/catalog/storage.c | 8 ++++++++ src/include/storage/bufmgr.h | 3 ++- src/include/utils/rel.h | 4 ++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index e3a716a2a2..33c0841b36 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -70,6 +70,8 @@ static void heap_prune_record_redirect(PruneState *prstate, static void heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum); static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * Optionally prune and repair fragmentation in the specified page. @@ -331,6 +333,18 @@ heap_page_prune(Relation relation, Buffer buffer, PageSetLSN(BufferGetPage(buffer), recptr); } + else if (relation->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + { + XLogRecPtr currlsn = GetXLogInsertRecPtr(); + Page page = BufferGetPage(buffer); + + Assert(wal_level < WAL_LEVEL_REPLICA); + + /* we need to update page LSN to notify reader of pruning */ + if (PageGetLSN(page) == currlsn) + currlsn = gistXLogAssignLSN(); + PageSetLSN(page, currlsn); + } } else { diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index cba7a9ada0..488ac6f760 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -75,6 +75,8 @@ typedef struct PendingRelSync static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ HTAB *pendingSyncHash = NULL; +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * AddPendingSync @@ -414,6 +416,7 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, bool copying_initfork; BlockNumber nblocks; BlockNumber blkno; + XLogRecPtr fakepagelsn; page = (Page) buf.data; @@ -434,6 +437,9 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, use_wal = XLogIsNeeded() && (relpersistence == RELPERSISTENCE_PERMANENT || copying_initfork); + if (!use_wal) + fakepagelsn = gistXLogAssignLSN(); + nblocks = smgrnblocks(src, forkNum); for (blkno = 0; blkno < nblocks; blkno++) @@ -460,6 +466,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, */ if (use_wal) log_newpage(&dst->smgr_rnode.node, forkNum, blkno, page, false); + else + PageSetLSN(page, fakepagelsn); PageSetChecksumInplace(page, blkno); diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index e641174798..9ab9e7394c 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -19,6 +19,7 @@ #include "storage/buf.h" #include "storage/bufpage.h" #include "storage/relfilenode.h" +#include "utils/rel.h" #include "utils/relcache.h" #include "utils/snapmgr.h" @@ -289,7 +290,7 @@ TestForOldSnapshot(Snapshot snapshot, Relation relation, Page page) && ((snapshot)->snapshot_type == SNAPSHOT_MVCC || (snapshot)->snapshot_type == SNAPSHOT_TOAST) && !XLogRecPtrIsInvalid((snapshot)->lsn) - && (!XLogIsNeeded() || PageGetLSN(page) > (snapshot)->lsn)) + && PageGetLSN(page) > (snapshot)->lsn) TestForOldSnapshot_impl(snapshot, relation); } diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f58d65cf28..35e53c8d74 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -618,8 +618,8 @@ typedef struct ViewOptions * decoding snapshot. */ #define RelationIsAccessibleInLogicalDecoding(relation) \ - (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + (XLogLogicalInfoActive() && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* -- 2.27.0 ----Next_Part(Thu_Jan_21_00_28_44_2021_003)---- ^ permalink raw reply [nested|flat] 24+ messages in thread
* [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. @ 2021-01-20 14:59 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 24+ messages in thread From: Kyotaro Horiguchi @ 2021-01-20 14:59 UTC (permalink / raw) WAL-skipping optimization omits bumping page LSN when ALTER TABLE SET TABLESPACE. Also heap_page_prune does the same. However, old_snapshot_threshold feature needs page LSN to be kept updated on these operations so that TestForOldSnapshot properly find identify whether a snapshot is invalidated. --- src/backend/access/heap/pruneheap.c | 14 ++++++++++++++ src/backend/catalog/storage.c | 8 ++++++++ src/include/storage/bufmgr.h | 3 ++- src/include/utils/rel.h | 4 ++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index e3a716a2a2..33c0841b36 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -70,6 +70,8 @@ static void heap_prune_record_redirect(PruneState *prstate, static void heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum); static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * Optionally prune and repair fragmentation in the specified page. @@ -331,6 +333,18 @@ heap_page_prune(Relation relation, Buffer buffer, PageSetLSN(BufferGetPage(buffer), recptr); } + else if (relation->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + { + XLogRecPtr currlsn = GetXLogInsertRecPtr(); + Page page = BufferGetPage(buffer); + + Assert(wal_level < WAL_LEVEL_REPLICA); + + /* we need to update page LSN to notify reader of pruning */ + if (PageGetLSN(page) == currlsn) + currlsn = gistXLogAssignLSN(); + PageSetLSN(page, currlsn); + } } else { diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index cba7a9ada0..488ac6f760 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -75,6 +75,8 @@ typedef struct PendingRelSync static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ HTAB *pendingSyncHash = NULL; +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * AddPendingSync @@ -414,6 +416,7 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, bool copying_initfork; BlockNumber nblocks; BlockNumber blkno; + XLogRecPtr fakepagelsn; page = (Page) buf.data; @@ -434,6 +437,9 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, use_wal = XLogIsNeeded() && (relpersistence == RELPERSISTENCE_PERMANENT || copying_initfork); + if (!use_wal) + fakepagelsn = gistXLogAssignLSN(); + nblocks = smgrnblocks(src, forkNum); for (blkno = 0; blkno < nblocks; blkno++) @@ -460,6 +466,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, */ if (use_wal) log_newpage(&dst->smgr_rnode.node, forkNum, blkno, page, false); + else + PageSetLSN(page, fakepagelsn); PageSetChecksumInplace(page, blkno); diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index e641174798..9ab9e7394c 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -19,6 +19,7 @@ #include "storage/buf.h" #include "storage/bufpage.h" #include "storage/relfilenode.h" +#include "utils/rel.h" #include "utils/relcache.h" #include "utils/snapmgr.h" @@ -289,7 +290,7 @@ TestForOldSnapshot(Snapshot snapshot, Relation relation, Page page) && ((snapshot)->snapshot_type == SNAPSHOT_MVCC || (snapshot)->snapshot_type == SNAPSHOT_TOAST) && !XLogRecPtrIsInvalid((snapshot)->lsn) - && (!XLogIsNeeded() || PageGetLSN(page) > (snapshot)->lsn)) + && PageGetLSN(page) > (snapshot)->lsn) TestForOldSnapshot_impl(snapshot, relation); } diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f58d65cf28..35e53c8d74 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -618,8 +618,8 @@ typedef struct ViewOptions * decoding snapshot. */ #define RelationIsAccessibleInLogicalDecoding(relation) \ - (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + (XLogLogicalInfoActive() && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* -- 2.27.0 ----Next_Part(Thu_Jan_21_00_28_44_2021_003)---- ^ permalink raw reply [nested|flat] 24+ messages in thread
* [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. @ 2021-01-20 14:59 Kyotaro Horiguchi <[email protected]> 0 siblings, 0 replies; 24+ messages in thread From: Kyotaro Horiguchi @ 2021-01-20 14:59 UTC (permalink / raw) WAL-skipping optimization omits bumping page LSN when ALTER TABLE SET TABLESPACE. Also heap_page_prune does the same. However, old_snapshot_threshold feature needs page LSN to be kept updated on these operations so that TestForOldSnapshot properly find identify whether a snapshot is invalidated. --- src/backend/access/heap/pruneheap.c | 14 ++++++++++++++ src/backend/catalog/storage.c | 8 ++++++++ src/include/storage/bufmgr.h | 3 ++- src/include/utils/rel.h | 4 ++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/backend/access/heap/pruneheap.c b/src/backend/access/heap/pruneheap.c index e3a716a2a2..33c0841b36 100644 --- a/src/backend/access/heap/pruneheap.c +++ b/src/backend/access/heap/pruneheap.c @@ -70,6 +70,8 @@ static void heap_prune_record_redirect(PruneState *prstate, static void heap_prune_record_dead(PruneState *prstate, OffsetNumber offnum); static void heap_prune_record_unused(PruneState *prstate, OffsetNumber offnum); +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * Optionally prune and repair fragmentation in the specified page. @@ -331,6 +333,18 @@ heap_page_prune(Relation relation, Buffer buffer, PageSetLSN(BufferGetPage(buffer), recptr); } + else if (relation->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT) + { + XLogRecPtr currlsn = GetXLogInsertRecPtr(); + Page page = BufferGetPage(buffer); + + Assert(wal_level < WAL_LEVEL_REPLICA); + + /* we need to update page LSN to notify reader of pruning */ + if (PageGetLSN(page) == currlsn) + currlsn = gistXLogAssignLSN(); + PageSetLSN(page, currlsn); + } } else { diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index cba7a9ada0..488ac6f760 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -75,6 +75,8 @@ typedef struct PendingRelSync static PendingRelDelete *pendingDeletes = NULL; /* head of linked list */ HTAB *pendingSyncHash = NULL; +/* XXXXXXXX tmporary modification */ +extern XLogRecPtr gistXLogAssignLSN(void); /* * AddPendingSync @@ -414,6 +416,7 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, bool copying_initfork; BlockNumber nblocks; BlockNumber blkno; + XLogRecPtr fakepagelsn; page = (Page) buf.data; @@ -434,6 +437,9 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, use_wal = XLogIsNeeded() && (relpersistence == RELPERSISTENCE_PERMANENT || copying_initfork); + if (!use_wal) + fakepagelsn = gistXLogAssignLSN(); + nblocks = smgrnblocks(src, forkNum); for (blkno = 0; blkno < nblocks; blkno++) @@ -460,6 +466,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst, */ if (use_wal) log_newpage(&dst->smgr_rnode.node, forkNum, blkno, page, false); + else + PageSetLSN(page, fakepagelsn); PageSetChecksumInplace(page, blkno); diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index e641174798..9ab9e7394c 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -19,6 +19,7 @@ #include "storage/buf.h" #include "storage/bufpage.h" #include "storage/relfilenode.h" +#include "utils/rel.h" #include "utils/relcache.h" #include "utils/snapmgr.h" @@ -289,7 +290,7 @@ TestForOldSnapshot(Snapshot snapshot, Relation relation, Page page) && ((snapshot)->snapshot_type == SNAPSHOT_MVCC || (snapshot)->snapshot_type == SNAPSHOT_TOAST) && !XLogRecPtrIsInvalid((snapshot)->lsn) - && (!XLogIsNeeded() || PageGetLSN(page) > (snapshot)->lsn)) + && PageGetLSN(page) > (snapshot)->lsn) TestForOldSnapshot_impl(snapshot, relation); } diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f58d65cf28..35e53c8d74 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -618,8 +618,8 @@ typedef struct ViewOptions * decoding snapshot. */ #define RelationIsAccessibleInLogicalDecoding(relation) \ - (XLogLogicalInfoActive() && \ - RelationNeedsWAL(relation) && \ + (XLogLogicalInfoActive() && \ + (relation)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT && \ (IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation))) /* -- 2.27.0 ----Next_Part(Thu_Jan_21_00_28_44_2021_003)---- ^ permalink raw reply [nested|flat] 24+ messages in thread
end of thread, other threads:[~2021-01-20 14:59 UTC | newest] Thread overview: 24+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2018-11-08 17:30 security release Pavel Stehule <[email protected]> 2018-11-08 17:39 ` Robert Haas <[email protected]> 2018-11-08 17:54 ` Pavel Stehule <[email protected]> 2021-01-20 14:59 [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. Kyotaro Horiguchi <[email protected]> 2021-01-20 14:59 [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. Kyotaro Horiguchi <[email protected]> 2021-01-20 14:59 [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. Kyotaro Horiguchi <[email protected]> 2021-01-20 14:59 [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. Kyotaro Horiguchi <[email protected]> 2021-01-20 14:59 [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. Kyotaro Horiguchi <[email protected]> 2021-01-20 14:59 [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. Kyotaro Horiguchi <[email protected]> 2021-01-20 14:59 [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. Kyotaro Horiguchi <[email protected]> 2021-01-20 14:59 [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. Kyotaro Horiguchi <[email protected]> 2021-01-20 14:59 [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. Kyotaro Horiguchi <[email protected]> 2021-01-20 14:59 [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. Kyotaro Horiguchi <[email protected]> 2021-01-20 14:59 [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. Kyotaro Horiguchi <[email protected]> 2021-01-20 14:59 [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. Kyotaro Horiguchi <[email protected]> 2021-01-20 14:59 [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. Kyotaro Horiguchi <[email protected]> 2021-01-20 14:59 [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. Kyotaro Horiguchi <[email protected]> 2021-01-20 14:59 [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. Kyotaro Horiguchi <[email protected]> 2021-01-20 14:59 [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. Kyotaro Horiguchi <[email protected]> 2021-01-20 14:59 [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. Kyotaro Horiguchi <[email protected]> 2021-01-20 14:59 [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. Kyotaro Horiguchi <[email protected]> 2021-01-20 14:59 [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. Kyotaro Horiguchi <[email protected]> 2021-01-20 14:59 [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. Kyotaro Horiguchi <[email protected]> 2021-01-20 14:59 [PATCH v5 3/3] Poc: Keep page-LSN updated while WAL-skipping. Kyotaro Horiguchi <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox