postgresql/src/test/modules
Heikki Linnakangas b8bff07daa Make ResourceOwners more easily extensible.
Instead of having a separate array/hash for each resource kind, use a
single array and hash to hold all kinds of resources. This makes it
possible to introduce new resource "kinds" without having to modify
the ResourceOwnerData struct. In particular, this makes it possible
for extensions to register custom resource kinds.

The old approach was to have a small array of resources of each kind,
and if it fills up, switch to a hash table. The new approach also uses
an array and a hash, but now the array and the hash are used at the
same time. The array is used to hold the recently added resources, and
when it fills up, they are moved to the hash. This keeps the access to
recent entries fast, even when there are a lot of long-held resources.

All the resource-specific ResourceOwnerEnlarge*(),
ResourceOwnerRemember*(), and ResourceOwnerForget*() functions have
been replaced with three generic functions that take resource kind as
argument. For convenience, we still define resource-specific wrapper
macros around the generic functions with the old names, but they are
now defined in the source files that use those resource kinds.

The release callback no longer needs to call ResourceOwnerForget on
the resource being released. ResourceOwnerRelease unregisters the
resource from the owner before calling the callback. That needed some
changes in bufmgr.c and some other files, where releasing the
resources previously always called ResourceOwnerForget.

Each resource kind specifies a release priority, and
ResourceOwnerReleaseAll releases the resources in priority order. To
make that possible, we have to restrict what you can do between
phases. After calling ResourceOwnerRelease(), you are no longer
allowed to remember any more resources in it or to forget any
previously remembered resources by calling ResourceOwnerForget.  There
was one case where that was done previously. At subtransaction commit,
AtEOSubXact_Inval() would handle the invalidation messages and call
RelationFlushRelation(), which temporarily increased the reference
count on the relation being flushed. We now switch to the parent
subtransaction's resource owner before calling AtEOSubXact_Inval(), so
that there is a valid ResourceOwner to temporarily hold that relcache
reference.

Other end-of-xact routines make similar calls to AtEOXact_Inval()
between release phases, but I didn't see any regression test failures
from those, so I'm not sure if they could reach a codepath that needs
remembering extra resources.

There were two exceptions to how the resource leak WARNINGs on commit
were printed previously: llvmjit silently released the context without
printing the warning, and a leaked buffer io triggered a PANIC. Now
everything prints a WARNING, including those cases.

Add tests in src/test/modules/test_resowner.

Reviewed-by: Aleksander Alekseev, Michael Paquier, Julien Rouhaud
Reviewed-by: Kyotaro Horiguchi, Hayato Kuroda, Álvaro Herrera, Zhihong Yu
Reviewed-by: Peter Eisentraut, Andres Freund
Discussion: https://www.postgresql.org/message-id/cbfabeb0-cd3c-e951-a572-19b365ed314d%40iki.fi
2023-11-08 13:30:50 +02:00
..
brin Show empty BRIN ranges in brin_page_items 2023-05-19 02:00:21 +02:00
commit_ts Pre-beta mechanical code beautification. 2023-05-19 17:24:48 -04:00
delay_execution meson: Prevent installation of test files during main install 2023-03-03 07:45:52 +01:00
dummy_index_am Add trailing commas to enum definitions 2023-10-26 09:20:54 +02:00
dummy_seclabel Improve several permission-related error messages. 2023-03-17 10:33:09 +01:00
ldap_password_func Don't install ldap_password_func in meson 2023-11-08 11:27:28 +01:00
libpq_pipeline Add trailing commas to enum definitions 2023-10-26 09:20:54 +02:00
plsample meson: Prevent installation of test files during main install 2023-03-03 07:45:52 +01:00
spgist_name_ops meson: Prevent installation of test files during main install 2023-03-03 07:45:52 +01:00
ssl_passphrase_callback Convert encrypted SSL test keys to PKCS#8 format 2023-08-28 07:37:43 +02:00
test_bloomfilter meson: Prevent installation of test files during main install 2023-03-03 07:45:52 +01:00
test_copy_callbacks meson: Prevent installation of test files during main install 2023-03-03 07:45:52 +01:00
test_custom_rmgrs Pre-beta mechanical code beautification. 2023-05-19 17:24:48 -04:00
test_ddl_deparse Catalog not-null constraints 2023-08-25 13:31:24 +02:00
test_extensions Reject substituting extension schemas or owners matching ["$'\]. 2023-08-07 06:05:56 -07:00
test_ginpostinglist meson: Prevent installation of test files during main install 2023-03-03 07:45:52 +01:00
test_integerset meson: Prevent installation of test files during main install 2023-03-03 07:45:52 +01:00
test_lfind meson: Prevent installation of test files during main install 2023-03-03 07:45:52 +01:00
test_misc Fix 003_check_guc.pl when loading modules with custom GUCs 2023-11-02 12:38:05 +09:00
test_oat_hooks Add OAT hook calls for more subcommands of ALTER TABLE 2023-08-17 08:54:17 +09:00
test_parser meson: Prevent installation of test files during main install 2023-03-03 07:45:52 +01:00
test_pg_dump Pre-beta mechanical code beautification. 2023-05-19 17:24:48 -04:00
test_predtest meson: Prevent installation of test files during main install 2023-03-03 07:45:52 +01:00
test_rbtree meson: Prevent installation of test files during main install 2023-03-03 07:45:52 +01:00
test_regex Redesign interrupt/cancel API for regex engine. 2023-04-08 22:10:39 +12:00
test_resowner Make ResourceOwners more easily extensible. 2023-11-08 13:30:50 +02:00
test_rls_hooks meson: Prevent installation of test files during main install 2023-03-03 07:45:52 +01:00
test_shm_mq test_shm_mq: Replace WAIT_EVENT_EXTENSION with custom wait events 2023-10-04 17:12:25 +09:00
test_slru Remove unused global variable 2023-04-21 11:41:58 +12:00
unsafe_tests Allow ALTER SYSTEM to set unrecognized custom GUCs. 2023-10-21 13:35:19 -04:00
worker_spi worker_spi: Fix test failure with BGWORKER_BYPASS_ROLELOGINCHECK 2023-10-16 13:45:39 +09:00
Makefile Make ResourceOwners more easily extensible. 2023-11-08 13:30:50 +02:00
README Add an enforcement mechanism for global object names in regression tests. 2019-06-29 11:34:00 -04:00
meson.build Make ResourceOwners more easily extensible. 2023-11-08 13:30:50 +02:00

README

Test extensions and libraries
=============================

src/test/modules contains PostgreSQL extensions that are primarily or entirely
intended for testing PostgreSQL and/or to serve as example code. The extensions
here aren't intended to be installed in a production server and aren't suitable
for "real work".

Furthermore, while you can do "make install" and "make installcheck" in
this directory or its children, it is NOT ADVISABLE to do so with a server
containing valuable data.  Some of these tests may have undesirable
side-effects on roles or other global objects within the tested server.
"make installcheck-world" at the top level does not recurse into this
directory.

Most extensions have their own pg_regress tests or isolationtester specs. Some
are also used by tests elsewhere in the tree.

If you're adding new hooks or other functionality exposed as C-level API this
is where to add the tests for it.