[pmg-devel] [PATCH pmg-api] rulecache: sort rules additionally by id

Dominik Csapak d.csapak at proxmox.com
Thu Dec 15 12:10:01 CET 2022


On 11/30/22 14:20, Stoiko Ivanov wrote:
> When more rules have the same priority currently their order is not
> stable - postgres returns them in a stable way, based on their last
> changetime - e.g. disabling and reenabling a rule puts it in the front
> of evaluation. Sortin by id (the primary key) in addition should make
> rule evaluation robust to such updates
> 
> While there is no guarantee of ordering (within the same priority)
> unexpected changes in which rule fires can cause confusion (at least
> it confused me quite a bit).
> 
> Reported-by: Mira Limbeck <m.limbeck at proxmox.com>
> Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
> ---
> With this applied I got stable ruleaction executions across rule-changes and
> pmg-smtp-filter restarts, but would appreciate some additional test
> 
>   src/PMG/RuleCache.pm | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/PMG/RuleCache.pm b/src/PMG/RuleCache.pm
> index d35e9c1..ebce98e 100644
> --- a/src/PMG/RuleCache.pm
> +++ b/src/PMG/RuleCache.pm
> @@ -37,7 +37,7 @@ sub new {
>   	my $sth = $dbh->prepare(
>   	    "SELECT ID, Name, Priority, Active, Direction FROM Rule " .
>   	    "where Active > 0 " .
> -	    "ORDER BY Priority DESC");
> +	    "ORDER BY Priority, ID DESC");

this sadly loses the 'DESC' ordering for the priority and all
rules are now loaded in the reverse order 🙃

>   
>   	$sth->execute();
>   






More information about the pmg-devel mailing list