Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc4c5154

Browse files
committed
Still more code review for single-page hash vacuuming.
Most seriously, fix use of incorrect block ID, per a report fromJeff Janes that it causes a crash and a diagnosis from Amit Kapila.Improve consistency between the hash and btree versions of thiscode by adding back a PANIC that btree has, and by registeringdata in the xlog record in the same way, per complaints fromJeff Janes and Amit Kapila.Tidy up some minor cosmetic points, per complaints from AmitKapila.Patch by Ashutosh Sharma, reviewed by Amit Kapila, and tested byJeff Janes.Discussion:http://postgr.es/m/CAMkU=1w-9Qe=Ff1o6bSaXpNO9wqpo7_9GL8_CVhw4BoVVHasqg@mail.gmail.com
1 parent1b02be2 commitc4c5154

File tree

4 files changed

+27
-28
lines changed

4 files changed

+27
-28
lines changed

‎src/backend/access/hash/hash_xlog.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -957,8 +957,6 @@ hash_xlog_vacuum_get_latestRemovedXid(XLogReaderState *record)
957957
OffsetNumberhoffnum;
958958
TransactionIdlatestRemovedXid=InvalidTransactionId;
959959
inti;
960-
char*ptr;
961-
Sizelen;
962960

963961
xlrec= (xl_hash_vacuum_one_page*)XLogRecGetData(record);
964962

@@ -976,13 +974,21 @@ hash_xlog_vacuum_get_latestRemovedXid(XLogReaderState *record)
976974
if (CountDBBackends(InvalidOid)==0)
977975
returnlatestRemovedXid;
978976

977+
/*
978+
* Check if WAL replay has reached a consistent database state. If not,
979+
* we must PANIC. See the definition of btree_xlog_delete_get_latestRemovedXid
980+
* for more details.
981+
*/
982+
if (!reachedConsistency)
983+
elog(PANIC,"hash_xlog_vacuum_get_latestRemovedXid: cannot operate with inconsistent data");
984+
979985
/*
980986
* Get index page. If the DB is consistent, this should not fail, nor
981987
* should any of the heap page fetches below. If one does, we return
982988
* InvalidTransactionId to cancel all HS transactions. That's probably
983989
* overkill, but it's safe, and certainly better than panicking here.
984990
*/
985-
XLogRecGetBlockTag(record,1,&rnode,NULL,&blkno);
991+
XLogRecGetBlockTag(record,0,&rnode,NULL,&blkno);
986992
ibuffer=XLogReadBufferExtended(rnode,MAIN_FORKNUM,blkno,RBM_NORMAL);
987993

988994
if (!BufferIsValid(ibuffer))
@@ -994,9 +1000,7 @@ hash_xlog_vacuum_get_latestRemovedXid(XLogReaderState *record)
9941000
* Loop through the deleted index items to obtain the TransactionId from
9951001
* the heap items they point to.
9961002
*/
997-
ptr=XLogRecGetBlockData(record,1,&len);
998-
999-
unused= (OffsetNumber*)ptr;
1003+
unused= (OffsetNumber*) ((char*)xlrec+SizeOfHashVacuumOnePage);
10001004

10011005
for (i=0;i<xlrec->ntuples;i++)
10021006
{
@@ -1121,23 +1125,15 @@ hash_xlog_vacuum_one_page(XLogReaderState *record)
11211125

11221126
if (action==BLK_NEEDS_REDO)
11231127
{
1124-
char*ptr;
1125-
Sizelen;
1126-
1127-
ptr=XLogRecGetBlockData(record,0,&len);
1128-
11291128
page= (Page)BufferGetPage(buffer);
11301129

1131-
if (len>0)
1130+
if (XLogRecGetDataLen(record)>SizeOfHashVacuumOnePage)
11321131
{
11331132
OffsetNumber*unused;
1134-
OffsetNumber*unend;
11351133

1136-
unused= (OffsetNumber*)ptr;
1137-
unend= (OffsetNumber*) ((char*)ptr+len);
1134+
unused= (OffsetNumber*) ((char*)xldata+SizeOfHashVacuumOnePage);
11381135

1139-
if ((unend-unused)>0)
1140-
PageIndexMultiDelete(page,unused,unend-unused);
1136+
PageIndexMultiDelete(page,unused,xldata->ntuples);
11411137
}
11421138

11431139
/*

‎src/backend/access/hash/hashinsert.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,6 @@ _hash_vacuum_one_page(Relation rel, Buffer metabuf, Buffer buf,
344344
Pagepage=BufferGetPage(buf);
345345
HashPageOpaquepageopaque;
346346
HashMetaPagemetap;
347-
doubletuples_removed=0;
348347

349348
/* Scan each tuple in page to see if it is marked as LP_DEAD */
350349
maxoff=PageGetMaxOffsetNumber(page);
@@ -355,10 +354,7 @@ _hash_vacuum_one_page(Relation rel, Buffer metabuf, Buffer buf,
355354
ItemIditemId=PageGetItemId(page,offnum);
356355

357356
if (ItemIdIsDead(itemId))
358-
{
359357
deletable[ndeletable++]=offnum;
360-
tuples_removed+=1;
361-
}
362358
}
363359

364360
if (ndeletable>0)
@@ -386,7 +382,7 @@ _hash_vacuum_one_page(Relation rel, Buffer metabuf, Buffer buf,
386382
pageopaque->hasho_flag &= ~LH_PAGE_HAS_DEAD_TUPLES;
387383

388384
metap=HashPageGetMeta(BufferGetPage(metabuf));
389-
metap->hashm_ntuples-=tuples_removed;
385+
metap->hashm_ntuples-=ndeletable;
390386

391387
MarkBufferDirty(buf);
392388
MarkBufferDirty(metabuf);
@@ -398,13 +394,18 @@ _hash_vacuum_one_page(Relation rel, Buffer metabuf, Buffer buf,
398394
XLogRecPtrrecptr;
399395

400396
xlrec.hnode=hnode;
401-
xlrec.ntuples=tuples_removed;
397+
xlrec.ntuples=ndeletable;
402398

403399
XLogBeginInsert();
400+
XLogRegisterBuffer(0,buf,REGBUF_STANDARD);
404401
XLogRegisterData((char*)&xlrec,SizeOfHashVacuumOnePage);
405402

406-
XLogRegisterBuffer(0,buf,REGBUF_STANDARD);
407-
XLogRegisterBufData(0, (char*)deletable,
403+
/*
404+
* We need the target-offsets array whether or not we store the whole
405+
* buffer, to allow us to find the latestRemovedXid on a standby
406+
* server.
407+
*/
408+
XLogRegisterData((char*)deletable,
408409
ndeletable*sizeof(OffsetNumber));
409410

410411
XLogRegisterBuffer(1,metabuf,REGBUF_STANDARD);

‎src/backend/access/rmgrdesc/hashdesc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ hash_desc(StringInfo buf, XLogReaderState *record)
113113
{
114114
xl_hash_vacuum_one_page*xlrec= (xl_hash_vacuum_one_page*)rec;
115115

116-
appendStringInfo(buf,"ntuples %g",
116+
appendStringInfo(buf,"ntuples %d",
117117
xlrec->ntuples);
118118
break;
119119
}

‎src/include/access/hash_xlog.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,13 @@ typedef struct xl_hash_init_bitmap_page
265265
typedefstructxl_hash_vacuum_one_page
266266
{
267267
RelFileNodehnode;
268-
doublentuples;
268+
intntuples;
269+
270+
/* TARGET OFFSET NUMBERS FOLLOW AT THE END */
269271
}xl_hash_vacuum_one_page;
270272

271273
#defineSizeOfHashVacuumOnePage\
272-
(offsetof(xl_hash_vacuum_one_page, ntuples) + sizeof(double))
274+
(offsetof(xl_hash_vacuum_one_page, ntuples) + sizeof(int))
273275

274276
externvoidhash_redo(XLogReaderState*record);
275277
externvoidhash_desc(StringInfobuf,XLogReaderState*record);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp