Rework new SLRU test with injection points
authorMichael Paquier <[email protected]>
Fri, 23 Aug 2024 03:11:36 +0000 (12:11 +0900)
committerMichael Paquier <[email protected]>
Fri, 23 Aug 2024 03:11:36 +0000 (12:11 +0900)
Rather than the SQL injection_points_load(), this commit changes the
injection point test introduced in 768a9fd5535f to rely on the two
macros INJECTION_POINT_LOAD() and INJECTION_POINT_CACHED(), that have
been originally introduced for the sake of this test.

This runs the test as a two-step process: load the injection point, then
run its callback directly from the local cache loaded.  What the test
did originally was also fine, but the point here is to have an example
in core of how to use these new macros.

While on it, fix the header ordering in multixact.c, as pointed out by
Alexander Korotkov.  This was an oversight in 768a9fd5535f.

Per discussion with Álvaro Herrera.

Author: Michael Paquier
Discussion: https://postgr.es/m/[email protected]
Discussion: https://postgr.es/m/CAPpHfduzaBz7KMhwuVOZMTpG=JniPG4aUosXPZCxZydmzq_oEQ@mail.gmail.com

src/backend/access/transam/multixact.c
src/test/modules/test_slru/t/001_multixact.pl

index 14c2b929e2c82c97e23636c6023d0e92bab97ee4..a03d56541d0c8d10aea2b5101da334371a4dabf5 100644 (file)
@@ -88,8 +88,8 @@
 #include "storage/proc.h"
 #include "storage/procarray.h"
 #include "utils/fmgrprotos.h"
-#include "utils/injection_point.h"
 #include "utils/guc_hooks.h"
+#include "utils/injection_point.h"
 #include "utils/memutils.h"
 
 
@@ -855,6 +855,9 @@ MultiXactIdCreateFromMembers(int nmembers, MultiXactMember *members)
        }
    }
 
+   /* Load the injection point before entering the critical section */
+   INJECTION_POINT_LOAD("multixact-create-from-members");
+
    /*
     * Assign the MXID and offsets range to use, and make sure there is space
     * in the OFFSETs and MEMBERs files.  NB: this routine does
@@ -869,7 +872,7 @@ MultiXactIdCreateFromMembers(int nmembers, MultiXactMember *members)
     */
    multi = GetNewMultiXactId(nmembers, &offset);
 
-   INJECTION_POINT("multixact-create-from-members");
+   INJECTION_POINT_CACHED("multixact-create-from-members");
 
    /* Make an XLOG entry describing the new MXID. */
    xlrec.mid = multi;
index f07406bf9d6a78e23e9a97a3710aea64b2cd1b10..882de7cd20b544155cd541b476d8e4f4a3ad677b 100644 (file)
@@ -24,7 +24,7 @@ my ($node, $result);
 $node = PostgreSQL::Test::Cluster->new('mike');
 $node->init;
 $node->append_conf('postgresql.conf',
-   "shared_preload_libraries = 'test_slru'");
+   "shared_preload_libraries = 'test_slru,injection_points'");
 $node->start;
 $node->safe_psql('postgres', q(CREATE EXTENSION injection_points));
 $node->safe_psql('postgres', q(CREATE EXTENSION test_slru));
@@ -64,7 +64,6 @@ $node->safe_psql('postgres',
 $creator->query_until(
    qr/start/, q{
    \echo start
-   SELECT injection_points_load('multixact-create-from-members');
    SELECT test_create_multixact();
 });