Skip to content

Commit

Permalink
filterx: skip FilterXScope sync if possible
Browse files Browse the repository at this point in the history
Signed-off-by: Balazs Scheidler <[email protected]>
  • Loading branch information
bazsi committed May 13, 2024
1 parent 79b2597 commit b7a3754
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions lib/filterx/filterx-scope.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ struct _FilterXScope
{
GAtomicCounter ref_cnt;
GArray *variables;
gboolean write_protected;
gboolean dirty;
gint generation;
guint32 generation:20, write_protected, dirty, syncable;
};

static gboolean
Expand Down Expand Up @@ -215,6 +213,10 @@ filterx_scope_register_variable(FilterXScope *self,
FilterXVariable *v = _register_variable(self, handle, initial_value);
v->declared = FALSE;

/* the scope needs to be synced with the message if it holds a
* message-tied variable (e.g. $MSG) */
if (!filterx_variable_handle_is_floating(handle))
self->syncable = TRUE;
return v;
}

Expand Down Expand Up @@ -245,6 +247,13 @@ filterx_scope_sync(FilterXScope *self, LogMessage *msg)
evt_tag_printf("scope", "%p", self));
return;
}
if (!self->syncable)
{
msg_trace("Filterx sync: not syncing as there are no variables to sync",
evt_tag_printf("scope", "%p", self));
self->dirty = FALSE;
return;
}

GString *buffer = scratch_buffers_alloc();

Expand All @@ -262,17 +271,16 @@ filterx_scope_sync(FilterXScope *self, LogMessage *msg)
*/
if (filterx_variable_is_floating(v))
{
if (!v->declared)
{
msg_trace("Filterx sync: undeclared floating variable, unsetting",
evt_tag_str("variable", log_msg_get_value_name(filterx_variable_get_nv_handle(v), NULL)));
filterx_variable_set_value(v, NULL);
}
else
{
msg_trace("Filterx sync: declared floating variable, keeping it",
evt_tag_str("variable", log_msg_get_value_name(filterx_variable_get_nv_handle(v), NULL)));
}
/* we could unset undeclared, floating values here as we are
* transitioning to the next filterx block. But this is also
* addressed by the variable generation counter mechanism. This
* means that we will unset those if some expr actually refers to
* it. Also, we skip the entire sync exercise, unless we have
* message tied values, so we need to work even if floating
* variables are not synced.
*
* With that said, let's not clear these.
*/
}
else if (v->value == NULL)
{
Expand Down Expand Up @@ -343,10 +351,12 @@ filterx_scope_clone(FilterXScope *other)

if (other->variables->len > 0)
self->dirty = other->dirty;
self->syncable = other->syncable;
msg_trace("Filterx clone finished",
evt_tag_printf("scope", "%p", self),
evt_tag_printf("other", "%p", other),
evt_tag_int("dirty", self->dirty),
evt_tag_int("syncable", self->syncable),
evt_tag_int("write_protected", self->write_protected));
/* NOTE: we don't clone weak references, those only relate to mutable
* objects, which we are cloning anyway */
Expand Down

0 comments on commit b7a3754

Please sign in to comment.