Bug 1017331

Summary: Duplicate entry 'Administrator' for key 'PRIMARY' SQLState: 23000 when RuntimeManager is used by multiple threads
Product: [Retired] JBoss BPMS Platform 6 Reporter: Jiri Svitak <jsvitak>
Component: jBPM CoreAssignee: Maciej Swiderski <mswiders>
Status: CLOSED CURRENTRELEASE QA Contact: Jiri Svitak <jsvitak>
Severity: high Docs Contact:
Priority: high    
Version: 6.0.0CC: mbaluch, mrietvel
Target Milestone: ER5Keywords: TestBlocker
Target Release: 6.0.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-08-06 20:10:40 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:
Attachments:
Description Flags
console log none

Description Jiri Svitak 2013-10-09 16:06:36 UTC
Created attachment 810016 [details]
console log

Duplicate entry 'Administrator' for key 'PRIMARY' when RuntimeManager is used by multiple threads. See the whole console log in attachment.

2013-10-09 16:49:43,113 INFO  [DefaultMessageGenerator] Starting to generate...
2013-10-09 16:49:44,344 WARN  [SqlExceptionHelper] SQL Error: 1062, SQLState: 23000
2013-10-09 16:49:44,344 WARN  [SqlExceptionHelper] SQL Error: 1062, SQLState: 23000
2013-10-09 16:49:44,344 ERROR [SqlExceptionHelper] Duplicate entry 'Administrator' for key 'PRIMARY'
2013-10-09 16:49:44,344 ERROR [SqlExceptionHelper] Duplicate entry 'Administrator' for key 'PRIMARY'
2013-10-09 16:49:44,345 WARN  [SqlExceptionHelper] SQL Error: 1062, SQLState: 23000
2013-10-09 16:49:44,345 ERROR [SqlExceptionHelper] Duplicate entry 'Administrator' for key 'PRIMARY'

To reproduce:
1.) git clone git://git.app.eng.bos.redhat.com/jbossqe-process-flood.git
2.) make sure that you are on company vpn to download all required maven artifacts
3.) make sure that you have local MySQL instance with clean database bpms, user bpms, password bpms (according to file mysql-localhost.xml)
4.) Run the test:
cd jbossqe-process-flood/bpms-6.x
./execute_scenario.sh -Dscenario=HumanTask_startProcess_Java -Dthreads=4 -DruntimeManager=PerProcessInstance -s ../mysql-localhost.xml

It can be either concurrency problem in runtime manager or bad usage of it. In any case this should not happen and more informative error message would be better.

Comment 1 Maciej Swiderski 2013-10-14 09:05:44 UTC
the main issue with this was that attempt to insert users/groups by user group callback was not secured to be thread safe and thus when several task were tried to be inserted at the same time for same users/groups caused the failure. Fix was applied to ensure that only single thread can perform the insertion and rest will wait and rely on already done operation

jbpm 
master:
https://github.com/droolsjbpm/jbpm/commit/e2af85494576f7d9ffd20cec58d8688bdda91e22

6.0.x
https://github.com/droolsjbpm/jbpm/commit/8e5de869436695bafa36e3a2dd6d5a6061b2432b

Comment 2 Marco Rietveld 2013-10-30 15:50:49 UTC
Maciej, 

Do you have a test for this somewhere? Of was this particularly hard to test?

Comment 3 Maciej Swiderski 2013-10-31 08:20:55 UTC
Marco, I used the jbossqe-process-flood as reproducer for this issue. Besides that I haven't created any junit test as it is tricky simulate that as junit test which essentially can fail with false results many times and thus I relied on jbossqe-process-flood only.

Comment 4 Jiri Svitak 2013-11-22 16:09:11 UTC
Verified in BPMS 6 ER5 (6.0.0-redhat-6).

One of the commands I used to verify:
./execute_scenario.sh -Dscenario=HumanTask_Java -Dthreads=4 -DruntimeManager=PerProcessInstance -s ../mysql-localhost.xml