Bug 517173

Summary: ISS throws oracle unique constraint violation error when trying to sync a channel to org1 using channel-dump from other org from same satellite
Product: Red Hat Satellite 5 Reporter: Sayli Karmarkar <skarmark>
Component: Satellite SynchronizationAssignee: Michael Mráka <mmraka>
Status: CLOSED ERRATA QA Contact: Jan Hutař <jhutar>
Severity: high Docs Contact:
Priority: high    
Version: 530CC: cperry, jfenal, jhutar, jkastner, marcus, mmraka, tscherf, xdmoon
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: spacewalk-backend-1.2.13-56 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-11-21 09:44:33 UTC Type: ---
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:    
Bug Blocks: 715348    

Description Sayli Karmarkar 2009-08-12 20:09:04 UTC
Description of problem:

Steps to Reproduce:
1. Create an org on satellite. There is no need to give entitlement as of now.  
2. Create a custom channel in that org and push a couple of packages. 
3. Create a channel dump of org-channel. 
   rhn-satellite-exporter -d /channel-dump -c org-channel
4. Sync it to default org  (org1)
   satellite-sync -c org-channel /channel-dump

  
Actual results:

SYNC ERROR: unhandled exception occurred:

(Check logs/email for potentially more detail)

<rhnFault class (code = 23, text = 'ORA-00001: unique constraint (JWMSTAGEUP.RHN_CNP_CID_NID_UQ) violated
ORA-06512: at "JWMSTAGEUP.RHN_CHANNEL", line 1131
ORA-06512: at line 1
')>
(23, 'ORA-00001: unique constraint (JWMSTAGEUP.RHN_CNP_CID_NID_UQ) violated\nORA-06512: at "JWMSTAGEUP.RHN_CHANNEL", line 1131\nORA-06512: at line 1\n', 'Could not update database entry.')



Expected results:
No error and sync should be successful / proper error (whatever is appropriate according to ISS design)

Comment 1 Pradeep Kilambi 2009-08-12 20:35:41 UTC
The recommend way to do this scenario would be to use channel sharing feature. Since we dont restrict users from doing the imports to other orgs from rhn-satellite-exporter we should fix it. But we have two workarounds.

1. use rhn-satellite-exporter using --org-id or

2. Channel sharing feature through webui.

Since we have multiple workarounds. I don't consider this a blocker at this point.

Comment 2 Clifford Perry 2009-12-02 16:21:19 UTC
*** Bug 543507 has been marked as a duplicate of this bug. ***

Comment 3 Clifford Perry 2009-12-02 16:22:28 UTC
Not sure why Comment #1 was private, since it listed options. Going to make it public. 

Cliff

Comment 4 Marcus Nilsson 2009-12-02 19:18:07 UTC
How does --org-id of exporter work? Would you not get the same problem trying to copy channels across organisations?

Solution (2) did not work as a workaround for me, because I need to clone the channel, which is not possible with a shared channel.

Comment 9 Milan Zázrivec 2010-12-10 17:00:43 UTC
The problem described in this bug report is simply a technical limitation
of the Satellite multi-org implementation.

There are few things adding to the problem:

1. In the current Satellite schema, channel label has to be unique (across
the whole Satellite).

2. Every channel is tied to one particular organization (i.e. one channel
cannot be more copied from one org to another, it will always disappear
from one organization and appear in the new organization)

3. satellite-sync does updates in rhnChannelNewestPackage which we use
to find for every channel available, latest version of every package.

So when doing the procedure described in the initial comment, what happens
is:

1. the channel we're importing is moved from one organization to another,
while its channel.id stays the same.

2. the packages from the export are copied over to the new organization,
they all get new package.id

3. Sync tries to update rhnChannelNewestPackage, which is defined as:

Name                                      Null?    Type
 ----------------------------------------- -------- ------
 CHANNEL_ID                                NOT NULL NUMBER
 NAME_ID                                   NOT NULL NUMBER
 EVR_ID                                    NOT NULL NUMBER
 PACKAGE_ARCH_ID                           NOT NULL NUMBER
 PACKAGE_ID                                NOT NULL NUMBER

At this point, in the database we have at least two packages which:
- have same name_id, evr_id, package_arch_id and
- have different package_id and
- both of these packages want to belong to the same channel_id

Satellite sync tries to insert these two rows into the rhnChannelNewestPackage
table and violates the following constraint:

rhn_cnp_cid_nid_uq UNIQUE (channel_id, name_id, package_arch_id)

After this, the Satellite will be in a state where:

1. The channel moved from the old to the new organization

2. Packages in this channel are still the packages from the 
old organization.

Comment 10 Milan Zázrivec 2010-12-10 17:02:14 UTC
(In reply to comment #4)
> How does --org-id of exporter work?

I'm sure Pradeep meant satellite-sync --orgid here (i.e. not the exporter).

Comment 11 Clifford Perry 2010-12-10 17:28:17 UTC
For me : 

2. Channel sharing feature through webui.

This is why we have this feature, to allow you to easily share channels and their content over multiple Orgs. 

This combined with our ability to lock a channel in time (same as creating a dump) - by cloning the channel - should provide a work-flow anyone can use for Multi-Org Satellites. Customers have used QA > Stage > Prod work-flow for cloned channels for many years in Satellite. If you then breakup these cross-Org, the channel sharing capabilites allows you to extend/share those channels cross-Org as well. 

Suggested work-flow for some people would be :

create a channel in Org A - once your happy. 
 - Clone channel 
  - Share cloned channel to Other Orgs
  - On other orgs subscribe systems to new channel. 

You either then constantly repeat this process - re-subscribing to new cloned channels, as needed, or move content into the cloned channel when it is ready for consumption by others in the other Orgs. 

So:
 Org A - owns channels 
  - Master channel Foo 
   - Cloned channel Foo QA staged 
   - Cloned channel Foo QA 
   - Cloned channel Foo Stage staged
   - Cloned channel Foo Stage
   - Cloned channel Foo Prod staged
   - Cloned channel Foo Prod

QA channel Foo is shared to your QA org and systems, with select systems subscribed to the 'staged' channel before you move that content into main QA channel for all to consume for testing. 

This is the equivalant of taking a channel snapshot/dump in time and then importing it into another Org for them to consume. 

Where you have select systems subscribed to the 'staged' channels were content is tested before putting into the main channel for everyone else to consume. 

Depending on nature, you may choose to only have staged channel for the Prod instance where before releasing into prod they are given one final test before moving to prod. 

In short, due to nature of this issue with schema limitations at play - were not likely to try and address this until a major release of Satellite, such as 5.5, 6.0 or 6.1 and not as say part of 5.4.1 release. As such, moving back off the sat54-errata tracker to the sat600-triage tracker.

In the mean time as suggested initally two main alternatives noted in comment #1 and #10, but for me channel cloning and sharing is the best way to meet the same end result.

Cliff

Comment 13 Michael Mráka 2011-02-08 13:48:35 UTC
The fix here is to remove stalled packages, i.e. those with orgid of original org, from the channel.

Fixed in spacewalk master by
commit 9cff05430de98e1f081fedd37559203e11e02bba
    517173 - unlink packages with different orgid

Fixed spacewalk package: spacewalk-backend-1.4.5-1

Comment 17 Michael Mráka 2011-10-26 09:00:32 UTC
Backported to SATELLITE-5.4 as
commit 11a9521c05d128e3be2104de41cf183621d55113
    517173 - unlink packages with different orgid

Comment 20 errata-xmlrpc 2011-11-21 09:44:33 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

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