forked from AcademySoftwareFoundation/OpenCue
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Recalc subscriptions (AcademySoftwareFoundation#1380)
* 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
1 parent
184961c
commit f5f0110
Showing
2 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.27 | ||
0.28 |
37 changes: 37 additions & 0 deletions
37
cuebot/src/main/resources/conf/ddl/postgres/migrations/V19__recalculate_subs.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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$; |