Bug 1619752 - cp_pool.quantity_consumed can mis-match against the actual consumed total
Summary: cp_pool.quantity_consumed can mis-match against the actual consumed total
Alias: None
Product: Candlepin
Classification: Community
Component: candlepin
Version: 2.3
Hardware: Unspecified
OS: Unspecified
Target Milestone: ---
: 2.3
Assignee: Chris "Ceiu" Rog
QA Contact: Katello QA List
Depends On: 1565810
TreeView+ depends on / blocked
Reported: 2018-08-21 16:14 UTC by Chris "Ceiu" Rog
Modified: 2018-09-25 20:41 UTC (History)
6 users (show)

Fixed In Version: candlepin-2.3.10-1
Doc Type: If docs needed, set a value
Doc Text:
Clone Of: 1565810
Last Closed: 2018-09-25 20:41:32 UTC

Attachments (Terms of Use)

System ID Private Priority Status Summary Last Updated
Github candlepin candlepin pull 2084 0 None None None 2018-08-21 16:18:49 UTC

Description Chris "Ceiu" Rog 2018-08-21 16:14:56 UTC
+++ This bug was initially created as a clone of Bug #1565810 +++

Description of problem:
It is possible for the cp_pool.quantity_consumed value to be a different value compared to the sum of all the entitlement consumed values for that pool. This remains even after a refresh.

In prod, we encountered this error when a customer couldn't attach to a pool because the limit was reached, even though the customer knew that couldn't be the case. Double-checking showed this to be the case: quantity_consumed = 3, but the actual consumed value was 2.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. Can't reproduce it yet, but it is possible to find cases where this has already happened. Query: 

SELECT calc.owner_id,
FROM  (SELECT p.id                AS owner_id,
              p.quantity          AS quantity,
              p.quantity_consumed AS stated_consumed,
              c.actual_consumed   AS actual_consumed
       FROM   cp_pool p
              JOIN (SELECT pool_id,
                           COALESCE(Sum(e.quantity), 0) actual_consumed
                    FROM   cp_entitlement e
                    WHERE  e.owner_id IN (SELECT id
                                          FROM   cp_owner)
                    GROUP  BY pool_id) c
                ON p.id = c.pool_id
       WHERE  p.owner_id IN (SELECT id
                             FROM   cp_owner)) calc
WHERE  calc.stated_consumed <> calc.actual_consumed; 

Actual results:
Some pools state they are consuming a value different than what they are actually consuming.

Expected results:
cp_pool.quantity_consumed equals the sum of all the entitlements consumed amounts for that pool.

Additional info:

Research from the Candlepin team has found that the calculation for this field is lost due to lack of @Transactional annotation.

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