Bug 617544

Summary: Multiple click on 'SYNCHRONIZE' of JBoss CSP patch feed gives error in server log - duplicate key value violates unique constraint "rhq_repo_pkg_ver_map_key"
Product: [Other] RHQ Project Reporter: Rajan Timaniya <rtimaniy>
Component: ContentAssignee: RHQ Project Maintainer <rhq-maint>
Status: CLOSED CURRENTRELEASE QA Contact: Mike Foley <mfoley>
Severity: medium Docs Contact:
Priority: high    
Version: 3.0.0CC: ccrouch, jshaughn
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-06-17 21:20:46 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: 678340    
Attachments:
Description Flags
server log
none
server log - JON goes down
none
git patch none

Description Rajan Timaniya 2010-07-23 12:08:30 UTC
Created attachment 433929 [details]
server log

Description of problem:
Multiple click on 'SYNCHRONIZE' of JBoss CSP patch feed gives error in server log - duplicate key value violates unique constraint "rhq_repo_pkg_ver_map_key"

2010-07-23 14:41:38,942 INFO  [org.rhq.enterprise.server.plugin.pc.content.sync.PackageSourceSynchronizer] Lazy load enabled for source [JBoss Patch Content Source], skipping package bits sync for repo [JBoss Patches]
2010-07-23 14:41:42,054 WARN  [org.hibernate.util.JDBCExceptionReporter] SQL Error: 0, SQLState: 23505
2010-07-23 14:41:42,054 ERROR [org.hibernate.util.JDBCExceptionReporter] Batch entry 0 insert into RHQ_REPO_PKG_VERSION_MAP (CTIME, REPO_ID, PACKAGE_VERSION_ID) values ('1279876297797', '10001', '10164') was aborted.  Call getNextException to see the cause.
2010-07-23 14:41:42,054 WARN  [org.hibernate.util.JDBCExceptionReporter] SQL Error: 0, SQLState: 23505
2010-07-23 14:41:42,054 ERROR [org.hibernate.util.JDBCExceptionReporter] ERROR: duplicate key value violates unique constraint "rhq_repo_pkg_ver_map_key"
2010-07-23 14:41:42,055 ERROR [org.hibernate.event.def.AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:254)
	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
        . . .

Version-Release number of selected component (if applicable):
version: 2.4.0.GA_QA (build #75) build number: 10876:a0cdffc

How reproducible:
Intermittent

Steps to Reproduce:
1) Log-in to JON 2.4 (build #75)
2) Go to Administration > Content > Content Sources 
3) Click on 'JBoss CSP Patch Feed' link
4) Provide user name/password to 'CSP Feed Settings' and make it active
5) Click on 'SAVE'
6) Click on 'SYNCHRONIZE' button
7) Click on 'JBoss Patches' link
8) Click on 'SYNCHRONIZE' button
  
Actual results:
Multiple click on 'SYNCHRONIZE' of JBoss CSP patch feed gives error in server log - duplicate key value violates unique constraint "rhq_repo_pkg_ver_map_key"

Expected results:
JON should not give 'duplicate key value violates unique constraint' error and it should synchronize Jboss CSP patch feed.

Additional info:
Tried to reproduce same issue many time but for some attempts JON server goes down.

Please refer attached server log.

Comment 1 Charles Crouch 2010-07-23 13:23:24 UTC
Needs triage.

Rajan, can you elaborate on what happens during " JON server goes
down."

Comment 2 Rajan Timaniya 2010-07-23 14:00:59 UTC
JON server goes down details:

version: 2.4.0.GA_QA (build #75) build number: 10876:a0cdffc

Steps to Reproduce:
1) Log-in to JON 2.4 (build #75)
2) Go to Administration > Content > Content Sources 
3) Click on 'JBoss CSP Patch Feed' link
4) Provide user name/password to 'CSP Feed Settings' and make it active
5) Click on 'SAVE'
6) Click on 'SYNCHRONIZE' button
7) Click on 'JBoss Patches' link
8) Click on 'SYNCHRONIZE' button
9) Repeat steps 6 to 8 for couple of times

Observation:
Running JON server goes down, there isn't any error/exception in server log.

Additional info:
Please refer attached server log for the case of JON server down.

Comment 3 Rajan Timaniya 2010-07-23 14:01:47 UTC
Created attachment 433960 [details]
server log - JON goes down

Comment 4 Joseph Marques 2010-07-23 14:10:41 UTC
from resourceOperationScheduleNew.xhtml...


<h:commandButton action="#{ResourceOperationScheduleUIBean.schedule}"
                 value="SCHEDULE" styleClass="buttonmed"
                 rendered="#{ResourceUIBean.permissions.control}"
                 onclick="return preventDoubleClick();"/>


      <script type="text/javascript">
         var submitted = false;
         function preventDoubleClick() {
            if (submitted) {
               return false;
            } else {
               submitted = true;
               return true;
            }
         }
      </script>

Comment 5 Charles Crouch 2010-07-23 14:20:29 UTC
Needs to be reproduced but clicking the synchronize button, returning to the
page, and clicking again repeatedly is not a typical execution path. Double click prevention would not seem to help in this case either.

Comment 6 Jay Shaughnessy 2010-07-23 19:52:35 UTC
I failed to reproduce but...

After looking at this I don't think we have in place any good mechanism for
serializing or protecting against concurrent, ui requested, sync job execution.
There are Content Source syncs and their are Repo syncs, both of which can be
kicked off manually and via cron job.  Moreover, a Content Source sync, when
completing its sync of discovered repos, goes on to sync the repos as well.

So, to really protect against concurrent repo syncs we need to put in synch job
serialization, or be smart enough to fail if one is in progress (for a
particular source or repo).

One very basic enhancement we can make is to add a bit of gui protection
against a single gui session requesting multiple repo syncs from the repo view.
This UI bean actually does know when a sync is in progress.  The one line patch is attached as fix1.patch.

I think any real protection will require a more sophisticated approach.

Comment 7 Jay Shaughnessy 2010-07-23 19:53:55 UTC
Created attachment 434047 [details]
git patch

Comment 8 Charles Crouch 2010-07-23 20:02:14 UTC
Dropping priority as this could not be reproduced and multiple manual syncs should not be a common use case.

Comment 9 Jay Shaughnessy 2014-06-17 21:20:46 UTC
This may be fixed at the gui level in coregui. Closing due to inactivity.