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

Commitd5be107

Browse files
committed
Revert "WAL-log inplace update before revealing it to other sessions."
This reverts commitbfd5c6e (v17) andcounterparts in each other non-master branch. This unblocks reverting acommit on which it depends.Discussion:https://postgr.es/m/10ec0bc3-5933-1189-6bb8-5dec4114558e@gmail.com
1 parent098f234 commitd5be107

File tree

2 files changed

+16
-46
lines changed

2 files changed

+16
-46
lines changed

‎src/backend/access/heap/README.tuplock

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,6 @@ Inplace updates create an exception to the rule that tuple data won't change
203203
under a reader holding a pin. A reader of a heap_fetch() result tuple may
204204
witness a torn read. Current inplace-updated fields are aligned and are no
205205
wider than four bytes, and current readers don't need consistency across
206-
fields. Hence, they get by with just fetching each field once.
206+
fields. Hence, they get by with just fetching each field once. XXX such a
207+
caller may also read a value that has not reached WAL; see
208+
systable_inplace_update_finish().

‎src/backend/access/heap/heapam.c

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6188,18 +6188,13 @@ heap_inplace_update_and_unlock(Relation relation,
61886188
HeapTupleHeaderhtup=oldtup->t_data;
61896189
uint32oldlen;
61906190
uint32newlen;
6191-
char*dst;
6192-
char*src;
61936191

61946192
Assert(ItemPointerEquals(&oldtup->t_self,&tuple->t_self));
61956193
oldlen=oldtup->t_len-htup->t_hoff;
61966194
newlen=tuple->t_len-tuple->t_data->t_hoff;
61976195
if (oldlen!=newlen||htup->t_hoff!=tuple->t_data->t_hoff)
61986196
elog(ERROR,"wrong tuple length");
61996197

6200-
dst= (char*)htup+htup->t_hoff;
6201-
src= (char*)tuple->t_data+tuple->t_data->t_hoff;
6202-
62036198
/*
62046199
* Construct shared cache inval if necessary. Note that because we only
62056200
* pass the new version of the tuple, this mustn't be used for any
@@ -6218,15 +6213,15 @@ heap_inplace_update_and_unlock(Relation relation,
62186213
*/
62196214
PreInplace_Inval();
62206215

6216+
/* NO EREPORT(ERROR) from here till changes are logged */
6217+
START_CRIT_SECTION();
6218+
6219+
memcpy((char*)htup+htup->t_hoff,
6220+
(char*)tuple->t_data+tuple->t_data->t_hoff,
6221+
newlen);
6222+
62216223
/*----------
6222-
* NO EREPORT(ERROR) from here till changes are complete
6223-
*
6224-
* Our buffer lock won't stop a reader having already pinned and checked
6225-
* visibility for this tuple. Hence, we write WAL first, then mutate the
6226-
* buffer. Like in MarkBufferDirtyHint() or RecordTransactionCommit(),
6227-
* checkpoint delay makes that acceptable. With the usual order of
6228-
* changes, a crash after memcpy() and before XLogInsert() could allow
6229-
* datfrozenxid to overtake relfrozenxid:
6224+
* XXX A crash here can allow datfrozenxid() to get ahead of relfrozenxid:
62306225
*
62316226
* ["D" is a VACUUM (ONLY_DATABASE_STATS)]
62326227
* ["R" is a VACUUM tbl]
@@ -6236,57 +6231,31 @@ heap_inplace_update_and_unlock(Relation relation,
62366231
* D: raise pg_database.datfrozenxid, XLogInsert(), finish
62376232
* [crash]
62386233
* [recovery restores datfrozenxid w/o relfrozenxid]
6239-
*
6240-
* Like in MarkBufferDirtyHint() subroutine XLogSaveBufferForHint(), copy
6241-
* the buffer to the stack before logging. Here, that facilitates a FPI
6242-
* of the post-mutation block before we accept other sessions seeing it.
62436234
*/
6244-
Assert((MyProc->delayChkptFlags&DELAY_CHKPT_START)==0);
6245-
START_CRIT_SECTION();
6246-
MyProc->delayChkptFlags |=DELAY_CHKPT_START;
6235+
6236+
MarkBufferDirty(buffer);
62476237

62486238
/* XLOG stuff */
62496239
if (RelationNeedsWAL(relation))
62506240
{
62516241
xl_heap_inplacexlrec;
6252-
PGAlignedBlockcopied_buffer;
6253-
char*origdata= (char*)BufferGetBlock(buffer);
6254-
Pagepage=BufferGetPage(buffer);
6255-
uint16lower= ((PageHeader)page)->pd_lower;
6256-
uint16upper= ((PageHeader)page)->pd_upper;
6257-
uintptr_tdst_offset_in_block;
6258-
RelFileLocatorrlocator;
6259-
ForkNumberforkno;
6260-
BlockNumberblkno;
62616242
XLogRecPtrrecptr;
62626243

62636244
xlrec.offnum=ItemPointerGetOffsetNumber(&tuple->t_self);
62646245

62656246
XLogBeginInsert();
62666247
XLogRegisterData((char*)&xlrec,SizeOfHeapInplace);
62676248

6268-
/* register block matching what buffer will look like after changes */
6269-
memcpy(copied_buffer.data,origdata,lower);
6270-
memcpy(copied_buffer.data+upper,origdata+upper,BLCKSZ-upper);
6271-
dst_offset_in_block=dst-origdata;
6272-
memcpy(copied_buffer.data+dst_offset_in_block,src,newlen);
6273-
BufferGetTag(buffer,&rlocator,&forkno,&blkno);
6274-
Assert(forkno==MAIN_FORKNUM);
6275-
XLogRegisterBlock(0,&rlocator,forkno,blkno,copied_buffer.data,
6276-
REGBUF_STANDARD);
6277-
XLogRegisterBufData(0,src,newlen);
6249+
XLogRegisterBuffer(0,buffer,REGBUF_STANDARD);
6250+
XLogRegisterBufData(0, (char*)htup+htup->t_hoff,newlen);
62786251

62796252
/* inplace updates aren't decoded atm, don't log the origin */
62806253

62816254
recptr=XLogInsert(RM_HEAP_ID,XLOG_HEAP_INPLACE);
62826255

6283-
PageSetLSN(page,recptr);
6256+
PageSetLSN(BufferGetPage(buffer),recptr);
62846257
}
62856258

6286-
memcpy(dst,src,newlen);
6287-
6288-
MarkBufferDirty(buffer);
6289-
62906259
LockBuffer(buffer,BUFFER_LOCK_UNLOCK);
62916260

62926261
/*
@@ -6299,7 +6268,6 @@ heap_inplace_update_and_unlock(Relation relation,
62996268
*/
63006269
AtInplace_Inval();
63016270

6302-
MyProc->delayChkptFlags &= ~DELAY_CHKPT_START;
63036271
END_CRIT_SECTION();
63046272
UnlockTuple(relation,&tuple->t_self,InplaceUpdateTupleLock);
63056273

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp