Bug 1402935

Summary: [5.8] lock_counts fix has several issues
Product: Red Hat Satellite 5 Reporter: Grant Gainey <ggainey>
Component: ServerAssignee: Grant Gainey <ggainey>
Status: CLOSED CURRENTRELEASE QA Contact: Jan Hutaƙ <jhutar>
Severity: high Docs Contact:
Priority: urgent    
Version: 580CC: adujicek, ggainey, jhutar, mkorbel, satqe-list, shughes, tlestach, xdmoon
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: spacewalk-schema-2.5.1-26-sat, satellite-schema-5.8.0.18-1-sat Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 1402931 Environment:
Last Closed: 2017-06-21 12:18:52 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1402931    
Bug Blocks: 1340444, 1402933    

Description Grant Gainey 2016-12-08 16:34:45 UTC
+++ This bug was initially created as a clone of Bug #1402931 +++

Description of problem:

The Oracle version of lock_counts.pkb fails to lock the server-row 'for update', which kind of defeats the whole purpose iof the proc.  Fix this.

Comment 3 Grant Gainey 2016-12-16 21:22:58 UTC
There is a further hole in the erratum that released lock_counts - specifically, the unsubscribe_server path WAS NOT COVERED, in either postgresql or oracle.

This is fixed in rhn_channel.pkb in both dialects.

Comment 5 Ales Dujicek 2016-12-22 08:06:11 UTC
There is diff between new 5.8 schema and 5.7 or older schema upgraded to 5.8 (both postgres an oracle)



Sources in [rhnuser@DBNAME=RHNSCHEMA] and [rhnuser@DBNAME=SPACESCHEMA_BPZS9A]
--- procedure_rhn_channel_subscribe_server_server_id_in_numeric_channel_id_in_numeric_immediate_in_numeric_DEFAULT_1_user_id_in_numeric_DEFAULT_NULL_numeric_recalcfamily_in_numeric_DEFAULT_1_returns_void.1	2016-12-21 12:57:24.143602374 -0500
+++ procedure_rhn_channel_subscribe_server_server_id_in_numeric_channel_id_in_numeric_immediate_in_numeric_DEFAULT_1_user_id_in_numeric_DEFAULT_NULL_numeric_recalcfamily_in_numeric_DEFAULT_1_returns_void.2	2016-12-21 12:57:24.143602374 -0500
@@ -15,8 +15,6 @@
         allowed                 numeric;
         is_fve_char             char(1) := 'N';
     BEGIN
-        perform lock_counts(server_id_in);
-
         if user_id_in is not null then
             allowed := rhn_channel.user_role_check(channel_id_in, user_id_in, 'subscribe');
         else
@@ -59,6 +57,7 @@
         THEN
             perform rhn_exception.raise_exception('channel_subscribe_no_family');
         END IF;
+        perform lock_counts(server_id_in);
         SELECT COALESCE(org_id, (SELECT org_id FROM rhnServer WHERE id = server_id_in))
           INTO server_org_id_val
           FROM rhnChannel
--- procedure_rhn_channel_unsubscribe_server_server_id_in_numeric_channel_id_in_numeric_immediate_in_numeric_DEFAULT_1_unsubscribe_children_in_numeric_DEFAULT_0_deleting_server_numeric_DEFAULT_0_update_family_countsyn_numeric_DEFAULT_1_returns_void.1	2016-12-21 12:57:24.150602279 -0500
+++ procedure_rhn_channel_unsubscribe_server_server_id_in_numeric_channel_id_in_numeric_immediate_in_numeric_DEFAULT_1_unsubscribe_children_in_numeric_DEFAULT_0_deleting_server_numeric_DEFAULT_0_update_family_countsyn_numeric_DEFAULT_1_returns_void.2	2016-12-21 12:57:24.150602279 -0500
@@ -19,7 +19,6 @@
                     and label = 'rhn-satellite';
         child record;
     BEGIN
-        perform lock_counts(server_id_in);
         FOR child IN select  c.id
                 from    rhnChannel                      c,
                                 rhnServerChannel        sc



Because change in

satellite-schema-5.7-to-satellite-schema-5.8/001-rhn_channel-deadlock-fix.sql.postgresql

is later overwritten by

satellite-schema-5.7-to-satellite-schema-5.8/007-rhn_channel-update_needed_cache-async.sql.postgresql

so it is not applied in upgraded schema.