Re: memory leak when serializing TRUNCATE in reorderbuffer

Поиск
Список
Период
Сортировка
От Tomas Vondra
Тема Re: memory leak when serializing TRUNCATE in reorderbuffer
Дата
Msg-id 9b17d019-7261-a5b0-1d65-caf30f69a891@2ndquadrant.com
обсуждение исходный текст
Ответ на Re: memory leak when serializing TRUNCATE in reorderbuffer  (Tomas Vondra <tomas.vondra@2ndquadrant.com>)
Ответы Re: memory leak when serializing TRUNCATE in reorderbuffer
Список pgsql-hackers
On 08/08/2018 09:47 PM, Tomas Vondra wrote:
> 
> IMHO the cleanest way is to add a method like
> ReorderBufferGetChange, which does the allocation internally. That
> way the memory context choice is up to reorderbuffer, not decode.c.
> That's at least consistent with what the rest of decode.c does.
> 

OK, attached is a patch doing it along these lines. It introduces
ReorderBufferGetRelids and ReorderBufferReturnRelids, which make the
decision which context to use (so it's contained in reorderbuffer.c).
Currently the main reorderbuffer context is used - we can't use the SLAB
contexts, and the tup_context is meant for something else.

I've considered adding yet another special-purpose context into
reorderbuffer, but it seems like an overkill considering that TRUNCATE
usually is not particularly common operation. So using the main context
seems OK.

I plan to commit this over the next couple of days, and backpatch it to
pg11 where TRUNCATE decoding was introduced. It's clearly a memory leak,
and there is no behavior change.

Two more things I noticed while working on this:

1) We're using very different data types for nrelids on various places
in the decoding. xl_heap_truncate uses uint32, logicalrep_write_truncate
uses int and ReorderBufferChange uses Size. That seems somewhat strange,
although it's unlikely to overflow (Who would truncate that many rels at
the same time?).

2) The tup_context is allocated like this:

  buffer->tup_context = GenerationContextCreate(new_ctx,
                                                "Tuples",
                                                SLAB_LARGE_BLOCK_SIZE);

Using SLAB_ constant for GenerationContextCreate is not a bug, but it's
a bit confusing.


regards

-- 
Tomas Vondra                  http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Вложения

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

Предыдущее
От: Michael Paquier
Дата:
Сообщение: Re: Fix help option of contrib/oid2name
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: C99 compliance for src/port/snprintf.c