Bug 526864 - Number of affected systems is not calculated right in SSM -> package removal
Summary: Number of affected systems is not calculated right in SSM -> package removal
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Satellite 5
Classification: Red Hat
Component: WebUI
Version: 530
Hardware: All
OS: Linux
medium
low
Target Milestone: ---
Assignee: Tomas Lestach
QA Contact: Dimitar Yordanov
URL:
Whiteboard:
Depends On:
Blocks: sat531-triage
TreeView+ depends on / blocked
 
Reported: 2009-10-02 07:43 UTC by Xixi
Modified: 2018-11-14 20:30 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Cause: underlying query returned more than one row for a server. Consequence: duplicated rows made number of affected systems higher than is should be. Fix: don't allow duplicated rows Result: number of systems is ok
Clone Of:
Environment:
Last Closed: 2011-02-01 10:32:30 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2011:0189 0 normal SHIPPED_LIVE Red Hat Network Satellite bug fix update 2011-02-01 10:31:45 UTC

Description Xixi 2009-10-02 07:43:12 UTC
Description of problem:
When customer uses a system set of 500 systems and chooses package removal the number of systems which have installed a package in the package list contains many entries > 500. For 5.000 systems one of the the calculated affected systems count was 5.004. So the calculation seems to be wrong.

Version-Release number of selected component (if applicable):
Red Hat Network (RHN) Satellite 5.3.0

System architecture(s):
arch=x86_64
release=5
flavor=server
base=rhel-x86_64-server-5

How reproducible:
Always.

Steps to Reproduce:
1. Have a satellite with a number of systems registered and some RHEL base channels sync'd (customer db dump is available).
2. Select a number of Systems for use in SSM (e.g., 500, doesn't matter though)
3. Click on https://SATELLITEFQDN/rhn/ssm/PackageRemove.do (go to SSM, choose "Package removal")
4. The column on the right shows the number of systems (of the selected system set) which have the package installed. So this cannot be more systems than in the SSM. However some packages lists 505 effected systems. 
5. Choose one of these packages to remove, and the following page lists all of the affected systems, but the number goes from 505 to 496. So at least one of the calculations seems to be wrong. It appears to be a cosmetic issue as the 2nd page (confirmation page) has the more reasonable count.

Actual results:
Wrong calculation of affected systems if you use SSM. See 4 above.

Expected results:
Correct calculation of affected systems if you use SSM. Accurate and consistent # of affected systems in the 2 pages (4 and 5 above).  The 1st page's counts definitely look wrong.

Additional info:
Looks like the problematic query is "packages_from_server_set" from src/com/redhat/rhn/common/db/datasource/xml/Package_queries.xml (see next update).

Comment 2 Xixi 2009-10-02 07:53:25 UTC
Looks like the problematic query is "packages_from_server_set" from src/com/redhat/rhn/common/db/datasource/xml/Package_queries.xml - basically the server count can go over # of systems in the SSM b/c the server_id selected on rhnServerPackage may not be unique, and adding a UNIQUE to the query gave better results.

In my test on the internal reproducer, the user_id is 1 (satadm user), rhnSet.label='system_list' (500 systems selected in the SSM), and package removal page under SSM shows many entries with more than 500 affected systems in the UI, as well as from db by substituting the above params into the packages_from_server_set query:

SELECT   PN.ID || '|' || PE.ID || '|' || PA.ID AS id_combo,
        PN.name || '-' || PE.evr.as_vre_simple() || '.' || PA.label nvre,
        PA.label AS arch,
        X.num_systems AS num_systems
   FROM rhnPackageName PN,
        rhnPackageEVR PE,
        rhnPackageArch PA,
        (SELECT   SP.name_id,
                  SP.evr_id,
                  SP.package_arch_id,
                  COUNT (SP.server_id) num_systems
             FROM rhnServerPackage SP,
                  rhnSet S
            WHERE s.user_id = 1
              AND s.label = 'system_list'
              AND s.ELEMENT = SP.server_id
         GROUP BY SP.name_id,
                  SP.evr_id,
                  SP.package_arch_id) X
  WHERE PE.ID = X.evr_id
    AND PN.ID = X.name_id
    AND PA.ID = X.package_arch_id
ORDER BY UPPER (PN.NAME);

Narrowing it down to the subquery which gives us X, where COUNT (SP.server_id) num_systems gives more than the total # of systems in the SSM -
"SELECT   SP.name_id,
                  SP.evr_id,
                  SP.package_arch_id,
                  COUNT (SP.server_id) num_systems
             FROM rhnServerPackage SP,
                  rhnSet S
            WHERE s.user_id = 1
              AND s.label = 'system_list'
              AND s.ELEMENT = SP.server_id
         GROUP BY SP.name_id,
                  SP.evr_id,
                  SP.package_arch_id;"

gives:
  NAME_ID     EVR_ID PACKAGE_ARCH_ID NUM_SYSTEMS
---------- ---------- --------------- -----------
     4612       5819             100         390
     1461       7554             100         428
     1696       7555             101         503
...
with NUM_SYSTEMS can be more than # of systems in the SSM.

Suspecting the server_id is not unique, if I add in a UNIQUE on rhnServerPackage.server_id -
"SELECT   SP.name_id,
                  SP.evr_id,
                  SP.package_arch_id,
                  COUNT (UNIQUE (SP.server_id)) num_systems
             FROM rhnServerPackage SP,
                  rhnSet S
            WHERE s.user_id = 1
              AND s.label = 'system_list'
              AND s.ELEMENT = SP.server_id
         GROUP BY SP.name_id,
                  SP.evr_id,
                  SP.package_arch_id;"

gives:
  NAME_ID     EVR_ID PACKAGE_ARCH_ID NUM_SYSTEMS
---------- ---------- --------------- -----------
       16       5839             101         500
       23       7245             101           1
       23      10165             101         499
...

with NUM_SYSTEMS always <= # of systems in the SSM.

There're no uniqueness constraints on the rhnServerPackage table, but in this case, we only care about packages on a per-server basis, so adding a UNIQUE may be the fix, although I need to check what the "duplicate" entries in rhnServerPackage would be.

/etc/sysconfig/rhn/universe.deploy.sql -
...
create table
rhnServerPackage
(
       server_id       number,
       name_id         number,
       evr_id          number ,
       package_arch_id number
)
       tablespace DATA_TBS
       enable row movement
 ;
create sequence rhn_server_package_id_seq;
...

Comment 7 Florian Nadge 2011-01-17 13:52:46 UTC
Please be so kind and add a few key words to the Technical Notes of this
Bugzilla entry using the following structure:

Cause:

Consequence:

Fix:

Result:

For details, see:

https://bugzilla.redhat.com/page.cgi?id=fields.html#cf_release_notes

Thanks

Comment 8 Florian Nadge 2011-01-17 13:52:47 UTC
    Technical note added. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    New Contents:
Cause:

Consequence:

Fix:

Result:

Comment 10 Michael Mráka 2011-01-17 14:52:29 UTC
    Technical note updated. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    Diffed Contents:
@@ -1,7 +1,7 @@
-Cause:
+Cause: underlying query returned more than one row for a server.
 
-Consequence:
+Consequence: duplicated rows made number of affected systems higher than is should be.
 
-Fix:
+Fix: don't allow duplicated rows
 
-Result:+Result: number of systems is ok

Comment 12 Julio Entrena Perez 2011-01-28 14:42:49 UTC
Dimitar, could you please tell me which errata contains the fix fir this issue?

Comment 13 Julio Entrena Perez 2011-01-28 14:46:20 UTC
Please, ignore my previous comment.

Comment 14 errata-xmlrpc 2011-02-01 10:32:30 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2011-0189.html


Note You need to log in before you can comment on or make changes to this bug.