Re: [HACKERS] Support for pg_receivexlog --format=plain|tar

Поиск
Список
Период
Сортировка
От Magnus Hagander
Тема Re: [HACKERS] Support for pg_receivexlog --format=plain|tar
Дата
Msg-id CABUevEy3X8nLhd+zSp1_B2G4qvkm4iFVmTt-amZuBR=i6OkP4Q@mail.gmail.com
обсуждение исходный текст
Ответ на Re: [HACKERS] Support for pg_receivexlog --format=plain|tar  (Michael Paquier <michael.paquier@gmail.com>)
Ответы Re: [HACKERS] Support for pg_receivexlog --format=plain|tar  (Michael Paquier <michael.paquier@gmail.com>)
Список pgsql-hackers


On Tue, Jan 10, 2017 at 3:01 AM, Michael Paquier <michael.paquier@gmail.com> wrote:
On Sat, Jan 7, 2017 at 8:19 PM, Magnus Hagander <magnus@hagander.net> wrote:
> On Sat, Jan 7, 2017 at 12:31 AM, Michael Paquier <michael.paquier@gmail.com>
> wrote:
>> There is something I forgot. With this patch,
>> FindStreamingStart()@pg_receivexlog.c is actually broken. In short it
>> forgets to consider files that have been compressed at the last run of
>> pg_receivexlog and will try to stream changes from the beginning. I
>> can see that gzip -l provides this information... But I have yet to
>> find something in zlib that allows a cheap lookup as startup of
>> streaming should be fast. Looking at how gzip -l does it may be faster
>> than looking at the docs.
>
> Do we really care though? As in, does startup of streaming have to be *that*
> fast? Even gunziping 16Mb (worst case) doesn't exactly take a long time. If
> your pg_receivexlog is restarting so often that it becomes a problem, I
> think you already have another and much bigger problem on your hands.

Based on some analysis, it is enough to look at the last 4 bytes of
the compressed file to get the size output data with a single call to
lseek() and then read(). So as there is a simple way to do things and
that's far cheaper than decompressing perhaps hundred of segments I'd
rather do it this way. Attached is the implementation. This code is
using 2 booleans for 4 states of the file names: full non-compressed,
partial non-compressed, full compressed and partial compressed. This
keeps the last check of FindStreamingStart() more simple, but that's
quite fancy lately to have an enum for such things :D

I think you need to document that analysis at least in a code comment. I assume this is in reference to the ISIZE member of the gzip format?

I was going to say what happens if the file is corrupt and we get random junk data there, but as we only compare it to XlogSegSize that should be safe. But we might want to put a note in about that too?

Finally, I think we should make the error message clearly say "compressed segment file" - just to make things extra clear.
 
> I found another problem with it -- it is completely broken in sync mode. You
> need to either forbid sync mode together with compression, or teach
> dir_sync() about it. The later would sound better, but I wonder how much
> that's going to kill compression due to the small blocks? Is it a reasonable
> use-case?

Hm. Looking at the docs I think that --compress defined with
--synchronous maps to the use of Z_SYNC_FLUSH with gzflush(). FWIW I
don't have a direct use case for it, but it is not a major effort to
add it, so done. There is no actual reason to forbid this combinations
of options either.

It is enough to just gzflush(), don't we also need to still fsync()? I can't see any documentation that gzflush() does that, and a quick look at the code of zlib indicates it doesn't (but I didn't check in detail, so if you did please point me to it).


--

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Magnus Hagander
Дата:
Сообщение: Re: [HACKERS] Replication/backup defaults
Следующее
От: Mithun Cy
Дата:
Сообщение: Re: [HACKERS] pageinspect: Hash index support