Обсуждение: Idea for better handling of cntxDirty

Поиск
Список
Период
Сортировка

Idea for better handling of cntxDirty

От
Tom Lane
Дата:
Vadim,

In LockBuffer() you wrote
   else if (mode == BUFFER_LOCK_EXCLUSIVE)   {       LWLockAcquire(buf->cntx_lock, LW_EXCLUSIVE);
       /*        * This is not the best place to set cntxDirty flag (eg indices do        * not always change buffer
theylock in excl mode). But please        * remember that it's critical to set cntxDirty *before* logging        *
changeswith XLogInsert() - see comments in BufferSync().        */       buf->cntxDirty = true;   }
 

The comments in BufferSynx are
       /*        * We can check bufHdr->cntxDirty here *without* holding any lock        * on buffer context as long as
weset this flag in access methods        * *before* logging changes with XLogInsert(): if someone will set        *
cntxDirtyjust after our check we don't worry because of our        * checkpoint.redo points before log record for
upcomingchanges        * and so we are not required to write such dirty buffer.        */
 

Wouldn't it work for cntxDirty to be set not by LockBuffer, but by
XLogInsert for each buffer that is included in its argument list?
This would avoid setting the flag for pages that are not modified
after being locked.  XLogInsert would of course set the flag before
doing the actual WAL insertion, so it seems to me that the condition
we want is met, and we still have only a single place that needs to
remember to set the flag.
        regards, tom lane


Re: Idea for better handling of cntxDirty

От
Tom Lane
Дата:
"Mikheev, Vadim" <VMIKHEEV@sectordata.com> writes:
>> Wouldn't it work for cntxDirty to be set not by LockBuffer, but by
>> XLogInsert for each buffer that is included in its argument list?

> I thought to add separate call to mark context dirty but above
> should work if all callers to XLogInsert always pass all
> modified buffers - please check.

AFAICT it is safe.  There are some places (in sequences and btree)
where not all the modified buffers are explicitly listed in XLogInsert's
arguments, but redo of those types of WAL records will always reinit the
affected pages anyway.  So we don't need to worry about forcing
checkpoint to write the pages early.

In general I don't think this adds any fragility to the system.  A WAL
record that is not set up to restore all buffers modified by the logged
operation would be broken by definition, no?
        regards, tom lane


Re: Idea for better handling of cntxDirty

От
"Mikheev, Vadim"
Дата:
> Wouldn't it work for cntxDirty to be set not by LockBuffer, but by
> XLogInsert for each buffer that is included in its argument list?

I thought to add separate call to mark context dirty but above
should work if all callers to XLogInsert always pass all
modified buffers - please check.

Vadim