pgsql: Store GUC data in a memory context, instead of using malloc().

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Store GUC data in a memory context, instead of using malloc().
Дата
Msg-id E1ojNff-002MLw-Og@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Store GUC data in a memory context, instead of using malloc().

The only real argument for using malloc directly was that we needed
the ability to not throw error on OOM; but mcxt.c grew that feature
awhile ago.

Keeping the data in a memory context improves accountability and
debuggability --- for example, without this it's almost impossible
to detect memory leaks in the GUC code with anything less costly
than valgrind.  Moreover, the next patch in this series will add a
hash table for GUC lookup, and it'd be pretty silly to be using
palloc-dependent hash facilities alongside malloc'd storage of the
underlying data.

This is a bit invasive though, in particular causing an API break
for GUC check hooks that want to modify the GUC's value or use an
"extra" data structure.  They must now use guc_malloc() and
guc_free() instead of malloc() and free().  Failure to change
affected code will result in assertion failures or worse; but
thanks to recent effort in the mcxt infrastructure, it shouldn't
be too hard to diagnose such oversights (at least in assert-enabled
builds).

One note is that this changes ParseLongOption() to return short-lived
palloc'd not malloc'd data.  There wasn't any caller for which the
previous definition was better.

Discussion: https://postgr.es/m/2982579.1662416866@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/407b50f2d421bca5b134a0033176ea8f8c68dc6b

Modified Files
--------------
src/backend/bootstrap/bootstrap.c   |   4 +-
src/backend/commands/tablespace.c   |   4 +-
src/backend/commands/variable.c     |  34 +++---
src/backend/postmaster/postmaster.c |   4 +-
src/backend/replication/syncrep.c   |   4 +-
src/backend/tcop/postgres.c         |   4 +-
src/backend/utils/adt/datetime.c    |   7 +-
src/backend/utils/cache/ts_cache.c  |   6 +-
src/backend/utils/misc/README       |  15 ++-
src/backend/utils/misc/guc.c        | 225 ++++++++++++++++++++++--------------
src/backend/utils/misc/tzparser.c   |   2 +-
src/include/utils/guc.h             |   1 +
src/pl/plpgsql/src/pl_handler.c     |   2 +-
13 files changed, 185 insertions(+), 127 deletions(-)


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

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: pgsql: doc: Correct type of bgw_notify_pid
Следующее
От: Alvaro Herrera
Дата:
Сообщение: pgsql: libpq: Reset singlerow flag correctly in pipeline mode