pgsql: Give SMgrRelation pointers a well-defined lifetime.

Поиск
Список
Период
Сортировка
От Heikki Linnakangas
Тема pgsql: Give SMgrRelation pointers a well-defined lifetime.
Дата
Msg-id E1rV8MJ-003yw6-5E@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Give SMgrRelation pointers a well-defined lifetime.

After calling smgropen(), it was not clear how long you could continue
to use the result, because various code paths including cache
invalidation could call smgrclose(), which freed the memory.

Guarantee that the object won't be destroyed until the end of the
current transaction, or in recovery, the commit/abort record that
destroys the underlying storage.

smgrclose() is now just an alias for smgrrelease(). It closes files
and forgets all state except the rlocator, but keeps the SMgrRelation
object valid.

A new smgrdestroy() function is used by rare places that know there
should be no other references to the SMgrRelation.

The short version:

 * smgrclose() is now just an alias for smgrrelease(). It releases
   resources, but doesn't destroy until EOX
 * smgrdestroy() now frees memory, and should rarely be used.

Existing code should be unaffected, but it is now possible for code that
has an SMgrRelation object to use it repeatedly during a transaction as
long as the storage hasn't been physically dropped.  Such code would
normally hold a lock on the relation.

This also replaces the "ownership" mechanism of SMgrRelations with a
pin counter.  An SMgrRelation can now be "pinned", which prevents it
from being destroyed at end of transaction.  There can be multiple pins
on the same SMgrRelation.  In practice, the pin mechanism is only used
by the relcache, so there cannot be more than one pin on the same
SMgrRelation.  Except with swap_relation_files XXX

Author: Thomas Munro, Heikki Linnakangas
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Discussion: https://www.postgresql.org/message-id/CA%2BhUKGJ8NTvqLHz6dqbQnt2c8XCki4r2QvXjBQcXpVwxTY_pvA@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/21d9c3ee4ef74e2229341d39811c97f85071c90a

Modified Files
--------------
src/backend/access/transam/xlogutils.c    |  15 +-
src/backend/commands/cluster.c            |  19 ---
src/backend/postmaster/bgwriter.c         |   8 +-
src/backend/postmaster/checkpointer.c     |  15 +-
src/backend/storage/buffer/bufmgr.c       |  32 ++--
src/backend/storage/freespace/freespace.c |   9 +-
src/backend/storage/smgr/smgr.c           | 233 ++++++++++++++++--------------
src/backend/utils/cache/inval.c           |   2 +-
src/backend/utils/cache/relcache.c        |  21 +--
src/include/storage/smgr.h                |  36 ++---
src/include/utils/rel.h                   |  18 +--
src/include/utils/relcache.h              |   2 -
12 files changed, 183 insertions(+), 227 deletions(-)


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

Предыдущее
От: Michael Paquier
Дата:
Сообщение: pgsql: Add .gitignore to src/test/modules/gin/
Следующее
От: Peter Eisentraut
Дата:
Сообщение: pgsql: doc: Document more that relations share a namespace