Skip to content

Commit

Permalink
Recalc subscriptions (AcademySoftwareFoundation#1380)
Browse files Browse the repository at this point in the history
* Update recalculate_subs pgsql function

This function is responsible for calculating subscription usage for each show and it's previous version had a bug that could lead to negative values.
  • Loading branch information
DiegoTavares authored Jun 17, 2024
1 parent 184961c commit f5f0110
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion VERSION.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.27
0.28
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
CREATE OR REPLACE FUNCTION public.recalculate_subs(
)
RETURNS void
LANGUAGE 'plpgsql'

COST 100
VOLATILE
AS $BODY$
DECLARE
r RECORD;
cur_burst bigint;
BEGIN
--
-- concatenates all tags in host_tag and sets host.str_tags
--
UPDATE subscription SET int_cores = 0;
FOR r IN (select show.str_name as show_name, proc.pk_show, alloc.pk_alloc, alloc.str_name as alloc_name, sum(proc.int_cores_reserved) as c
from show, proc, host, alloc
where show.pk_show = proc.pk_show and proc.pk_host = host.pk_host AND host.pk_alloc = alloc.pk_alloc AND proc.b_local = false
group by show.str_name, proc.pk_show, alloc.pk_alloc, alloc.str_name)
LOOP
BEGIN
SELECT int_burst INTO cur_burst FROM subscription WHERE pk_alloc=r.pk_alloc AND pk_show=r.pk_show;
-- Also changing int_burst here to bypass VERIFY_SUBSCRIPTION trigger
UPDATE subscription SET int_cores = r.c, int_burst = r.c WHERE pk_alloc=r.pk_alloc AND pk_show=r.pk_show;
-- Put original int_burst back.
UPDATE subscription SET int_burst = cur_burst WHERE pk_alloc=r.pk_alloc AND pk_show=r.pk_show;
EXCEPTION
WHEN NO_DATA_FOUND THEN
-- ignore
NULL;
WHEN DATA_EXCEPTION THEN
RAISE DATA_EXCEPTION USING MESSAGE = r.show||' '||r.alloc_name|| ' could not be fixed (over burst)';
END;
END LOOP;
END;
$BODY$;

0 comments on commit f5f0110

Please sign in to comment.