Allow a condition string in an injection point
Allow a condition string in an injection point
A follow-up to the discussion here [0], here is a patch that allows
for an arbitrary string in injection points to be able to apply more
granular filters for running an injection point. This will be useful
for autovacuum testing as discussed in the referenced thread,
and perhaps in some other places.
The string is capped at 256 bytes which seems like a reasonable
value. I considered using a flexible_array_member and to track
the length, but that hardly seemed worth it at this stage.
A case I envision, and there could be more is only run
the injection point for a specific rel.
```
SELECT injection_points_attach('my-inj-pt', 'wait', 'tab1');
```
```
#ifdef USE_INJECTION_POINTS
INJECTION_POINT("my-inj-pt", RelationGetRelationName(rel));
#endif
```
Worth noting, the condition types were changed to bit flags since
we may need to combine conditions such as local injection point
and string.
typedef enum InjectionPointConditionType
{
- INJ_CONDITION_ALWAYS = 0, /* always run */
- INJ_CONDITION_PID, /* PID restriction */
+ INJ_CONDITION_PID = 1 << 0, /* PID restriction */
+ INJ_CONDITION_STRING = 1 << 1, /* generic string match against arg */
} InjectionPointConditionType;
--
Sami
[0] https://www.postgresql.org/message-id/adWcVrX3jrHPoCmD%40paquier.xyz
Re: Allow a condition string in an injection point
On Thu, Apr 09, 2026 at 01:02:37PM -0500, Sami Imseih wrote:
> A follow-up to the discussion here [0], here is a patch that allows
> for an arbitrary string in injection points to be able to apply more
> granular filters for running an injection point. This will be useful
> for autovacuum testing as discussed in the referenced thread,
> and perhaps in some other places.
Are the patches under discussion required for v19 or is that something
that can wait before v20 opens for business? We have always required
a use-case in core before adding a new API in this module, to justify
its existence.
> The string is capped at 256 bytes which seems like a reasonable
> value. I considered using a flexible_array_member and to track
> the length, but that hardly seemed worth it at this stage.
This change is local to the module injection_points. That can be
changed at will even in the back-branches.
> A case I envision, and there could be more is only run
> the injection point for a specific rel.
>
> SELECT injection_points_attach('my-inj-pt', 'wait', 'tab1');
We may be able to simplify a couple more places that rely on multiple
INJECTION_POINT currently, with slightly different names. I doubt
these currently in the tree are worth changing. That would make
backpatches more invasive for the tests, which is more noise, so
most likely no.
> #ifdef USE_INJECTION_POINTS
> INJECTION_POINT("my-inj-pt", RelationGetRelationName(rel));
> #endif
Ahah, nice. You'd probably want to schema-qualify or database-quality
that anyway.
> Worth noting, the condition types were changed to bit flags since
> we may need to combine conditions such as local injection point
> and string.
It's definitely more useful to allow combinations of them in an AND
fashion (if two conditions are defined then check both, and allow the
point to run if both conditions pass). Just to say that what you are
doing looks sensible for me. And I find that pretty cool for its
simplicity and what it could provide for future tests.
@@ -322,6 +322,7 @@ InjectionPointAttach(const char *name,
strlcpy(entry->name, name, sizeof(entry->name));
strlcpy(entry->library, library, sizeof(entry->library));
strlcpy(entry->function, function, sizeof(entry->function));
+ memset(entry->private_data, 0, INJ_PRIVATE_MAXLEN);
if (private_data != NULL)
memcpy(entry->private_data, private_data, private_data_size);
Hmm, this could be qualified as a bug, and surely it's a good practice
to clean things on attach. I'll go backpatch that.
--
Michael
Re: Allow a condition string in an injection point
От:
Sami Imseih <samimseih@gmail.com>
Дата:
> > A follow-up to the discussion here [0], here is a patch that allows > > for an arbitrary string in injection points to be able to apply more > > granular filters for running an injection point. This will be useful > > for autovacuum testing as discussed in the referenced thread, > > and perhaps in some other places. > > Are the patches under discussion required for v19 or is that something > that can wait before v20 opens for business? We have always required > a use-case in core before adding a new API in this module, to justify > its existence. This is v20. One of the use-case is discussed here [1]. When testing of autovacuum for a specific table, we need a way to run the injection point for that table only, else we end up running the point it for all tables. This is especially true for check-world where other non-related tables are being autovacuumed. So this gives more granular control. > > Worth noting, the condition types were changed to bit flags since > > we may need to combine conditions such as local injection point > > and string. > > It's definitely more useful to allow combinations of them in an AND > fashion (if two conditions are defined then check both, and allow the > point to run if both conditions pass). Just to say that what you are > doing looks sensible for me. And I find that pretty cool for its > simplicity and what it could provide for future tests. yes, I did test with some other new hypothetical condition in the future and it was simple to plug it in to the code at that point. > @@ -322,6 +322,7 @@ InjectionPointAttach(const char *name, > strlcpy(entry->name, name, sizeof(entry->name)); > strlcpy(entry->library, library, sizeof(entry->library)); > strlcpy(entry->function, function, sizeof(entry->function)); > + memset(entry->private_data, 0, INJ_PRIVATE_MAXLEN); > if (private_data != NULL) > memcpy(entry->private_data, private_data, private_data_size); > > Hmm, this could be qualified as a bug, and surely it's a good practice > to clean things on attach. I'll go backpatch that. It did not matter before this new condition type since the private_data was never NULL. Not the case with this patch, as it caused inection_points test regressions with this change. So, yeah, it's a latent bug. -- Sami [1] [https://www.postgresql.org/message-id/CAA5RZ0tExiffcu7qvrUbpq_qqz%3DzCD2aJ5_Qigo6eP2kgTx3eQ%40mail.gmail.com]
Re: Allow a condition string in an injection point
> On 3 Aug 2026, at 13:16, Michael Paquier wrote: FWIW, I like the idea proposed in this patch. > While looking at this patch, I'd like to have at least one valid test > using it. +1, a test using the new facility seems like a requirement for this. At some point we should probably consider documenting this module with a README, but that's for another patch. -- Daniel Gustafsson
Re: Allow a condition string in an injection point
Hi, Thanks all for the reviews/comments. v2- attached addresses Bertrand's points. Fixed all. I also included some additional tests for injection_points_attach() since this function is no longer STRICT. On Mon, Aug 3, 2026 at 9:09 AM Daniel Gustafsson wrote: > > > On 3 Aug 2026, at 13:16, Michael Paquier wrote: > > FWIW, I like the idea proposed in this patch. > > > While looking at this patch, I'd like to have at least one valid test > > using it. > > +1, a test using the new facility seems like a requirement for this. At some > point we should probably consider documenting this module with a README, but > that's for another patch. > > -- > Daniel Gustafsson The facilities that this will be useful for are those in which the injection_point_set_local() cannot be used and thus we cannot clearly determine if the injection point is reached at the correct condition. [0] was one example, which led to this thread, but we dealt with this by using wait_for_log to ensure that we reached the correct code path. Looking at [1], if we want to test toast reloptions for autovacuum, we will need some type of way to ensure that we are inspecting the correct relations for the test. Since autovacuum cannot rely on injection_point_set_local because workers will not set the local injection point, we can use string conditions to ensure we reached the correct table. the nocfbot test attached shows how we can build such tests for autovacuum. The test fails without the latest patchset in [1]. CCing Nathan as his patch is being discussed. Without this condition string, to implement such a test, we will need a NOTICE to log and we will need to use regexp to examine the log to make sure our toast table fired at the correct injection point. With the condition string, we can simply just use wait_for_event since we know which table the injection point will fire on. This feature could enable further autovacuum tests as well. [0] https://www.postgresql.org/message-id/adWcVrX3jrHPoCmD%40paquier.xyz [1] https://www.postgresql.org/message-id/aFrUkYVyATVk2nsD%40nathan -- Sami Imseih Amazon Web Services (AWS)
Re: Allow a condition string in an injection point
On Thu, Aug 13, 2026 at 04:53:29PM -0500, Sami Imseih wrote: > Yeah, you're right, local vs shared injection points tests don't > really make a difference > here. With that said, just because shared points are the more common > case, I kept > those instead. Okay, that works here. My previous point feels a bit moot due to TestInjectionNoticeFunc, but that would be my fault. > I do like the 051 test you mention and I think we should add a string > to the "sync_slot" as well. This is good for demo. > See attached 0002 for this. > > With that said, I think the stronger case for injection points string filters > are tests in which we can't use set_local and we can do wait_for_event > which is more robust that using regexp. If others would like to be fancier, that could always happen later. It does not change the fact that this stuff has merit in the long run. Edited a couple of things, like comments, some ereport() vs elog(). And then applied both things. -- Michael