diff options
author | Robert Haas <rhaas@postgresql.org> | 2017-04-05 14:17:23 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2017-04-05 14:18:15 -0400 |
commit | 633e15ea0f1bf2e1d70441fe9da8781befebd6e9 (patch) | |
tree | 0dd846cb2e2418e82b2e90bcd8fa88e2c64be55d /src/backend/access/hash | |
parent | 6785fbd60ffd82ef825baf6db34bd944f3c7b121 (diff) | |
download | postgresql-633e15ea0f1bf2e1d70441fe9da8781befebd6e9.tar.gz |
Fix pageinspect failures on hash indexes.
Make every page in a hash index which isn't all-zeroes have a valid
special space, so that tools like pageinspect don't error out.
Also, make pageinspect cope with all-zeroes pages, because
_hash_alloc_buckets can leave behind large numbers of those until
they're consumed by splits.
Ashutosh Sharma and Robert Haas, reviewed by Amit Kapila.
Original trouble report from Jeff Janes.
Discussion: http://postgr.es/m/CAMkU=1y6NjKmqbJ8wLMhr=F74WzcMALYWcVFhEpm7i=mV=XsOg@mail.gmail.com
Diffstat (limited to 'src/backend/access/hash')
-rw-r--r-- | src/backend/access/hash/hash_xlog.c | 9 | ||||
-rw-r--r-- | src/backend/access/hash/hashovfl.c | 17 | ||||
-rw-r--r-- | src/backend/access/hash/hashpage.c | 12 |
3 files changed, 34 insertions, 4 deletions
diff --git a/src/backend/access/hash/hash_xlog.c b/src/backend/access/hash/hash_xlog.c index d9ac42c394..2ccaf469e7 100644 --- a/src/backend/access/hash/hash_xlog.c +++ b/src/backend/access/hash/hash_xlog.c @@ -697,11 +697,20 @@ hash_xlog_squeeze_page(XLogReaderState *record) if (XLogReadBufferForRedo(record, 2, &ovflbuf) == BLK_NEEDS_REDO) { Page ovflpage; + HashPageOpaque ovflopaque; ovflpage = BufferGetPage(ovflbuf); _hash_pageinit(ovflpage, BufferGetPageSize(ovflbuf)); + ovflopaque = (HashPageOpaque) PageGetSpecialPointer(ovflpage); + + ovflopaque->hasho_prevblkno = InvalidBlockNumber; + ovflopaque->hasho_nextblkno = InvalidBlockNumber; + ovflopaque->hasho_bucket = -1; + ovflopaque->hasho_flag = LH_UNUSED_PAGE; + ovflopaque->hasho_page_id = HASHO_PAGE_ID; + PageSetLSN(ovflpage, lsn); MarkBufferDirty(ovflbuf); } diff --git a/src/backend/access/hash/hashovfl.c b/src/backend/access/hash/hashovfl.c index 41ef654862..d5f5023068 100644 --- a/src/backend/access/hash/hashovfl.c +++ b/src/backend/access/hash/hashovfl.c @@ -590,11 +590,22 @@ _hash_freeovflpage(Relation rel, Buffer bucketbuf, Buffer ovflbuf, } /* - * Initialize the freed overflow page. Just zeroing the page won't work, - * because WAL replay routines expect pages to be initialized. See - * explanation of RBM_NORMAL mode atop XLogReadBufferExtended. + * Reinitialize the freed overflow page. Just zeroing the page won't + * work, because WAL replay routines expect pages to be initialized. See + * explanation of RBM_NORMAL mode atop XLogReadBufferExtended. We are + * careful to make the special space valid here so that tools like + * pageinspect won't get confused. */ _hash_pageinit(ovflpage, BufferGetPageSize(ovflbuf)); + + ovflopaque = (HashPageOpaque) PageGetSpecialPointer(ovflpage); + + ovflopaque->hasho_prevblkno = InvalidBlockNumber; + ovflopaque->hasho_nextblkno = InvalidBlockNumber; + ovflopaque->hasho_bucket = -1; + ovflopaque->hasho_flag = LH_UNUSED_PAGE; + ovflopaque->hasho_page_id = HASHO_PAGE_ID; + MarkBufferDirty(ovflbuf); if (BufferIsValid(prevbuf)) diff --git a/src/backend/access/hash/hashpage.c b/src/backend/access/hash/hashpage.c index b5a1c7ed28..3cd4daa325 100644 --- a/src/backend/access/hash/hashpage.c +++ b/src/backend/access/hash/hashpage.c @@ -993,6 +993,7 @@ _hash_alloc_buckets(Relation rel, BlockNumber firstblock, uint32 nblocks) BlockNumber lastblock; char zerobuf[BLCKSZ]; Page page; + HashPageOpaque ovflopaque; lastblock = firstblock + nblocks - 1; @@ -1007,10 +1008,19 @@ _hash_alloc_buckets(Relation rel, BlockNumber firstblock, uint32 nblocks) /* * Initialize the page. Just zeroing the page won't work; see - * _hash_freeovflpage for similar usage. + * _hash_freeovflpage for similar usage. We take care to make the + * special space valid for the benefit of tools such as pageinspect. */ _hash_pageinit(page, BLCKSZ); + ovflopaque = (HashPageOpaque) PageGetSpecialPointer(page); + + ovflopaque->hasho_prevblkno = InvalidBlockNumber; + ovflopaque->hasho_nextblkno = InvalidBlockNumber; + ovflopaque->hasho_bucket = -1; + ovflopaque->hasho_flag = LH_UNUSED_PAGE; + ovflopaque->hasho_page_id = HASHO_PAGE_ID; + if (RelationNeedsWAL(rel)) log_newpage(&rel->rd_node, MAIN_FORKNUM, |