[ 
https://issues.apache.org/jira/browse/AMQ-7002?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16525025#comment-16525025
 ] 

Jamie goodyear commented on AMQ-7002:
-------------------------------------

[^amq7002-master.patch]

Please find attached a patch for AMQ-7002.

The code change is to start using ID_GENERATOR to set JobId when scheduling a 
job instead of using messageId.

The test suits in Broker, unit tests & use cases all pass with this change in 
place.

A unit test, AMQ7002Test, has been created to exercise this code.

In short the unit test configures a broker with redelivery plugin installed, 
and send a message to a virtual topic with two consumers.
The consumers will perform a rollback operation, this causes the scheduler to 
come into play.
When then check that the jobs in the scheduler have unique IDs.

If we do not have the ID_GENERATOR in play than this test case fails, with the 
ID_GENERATOR we get the unique IDs we require.

JobIDs need to be unique in the scheduler. Under the existing code its possible 
for a race condition in which two or more jobs get the same JobID while having 
different payloads, the ID_GENERATOR resolves this issue by ensuring each job 
ID is unique.

Please review this patch for both the AMQ 5.15.x and 5.16.x (master) branches. 

I'd like to thank jgenender, joed, hkesler, and gtully for helping in 
identifying the issue and how to test/exercise the fix.

> Activemq SchedulerBroker doSchedule can schedule duplicate jobIds leading to 
> runtime exception 
> -----------------------------------------------------------------------------------------------
>
>                 Key: AMQ-7002
>                 URL: https://issues.apache.org/jira/browse/AMQ-7002
>             Project: ActiveMQ
>          Issue Type: Bug
>          Components: Broker, Job Scheduler
>    Affects Versions: 5.15.4
>         Environment: Java 8
> AMQ 5.15.4
>            Reporter: Jamie goodyear
>            Priority: Major
>             Fix For: 5.x
>
>         Attachments: amq7002-master.patch
>
>
> Under load we've observed that SchedulerBroker will attempt to schedule jobs 
> using the same JobId.
> When JobScheduleView attempts to process these jobs we'll encounter an 
> exception during the below put call:
> {color:#bbb529}@Override{color}{color:#cc7832}public {color}TabularData 
> {color:#ffc66d}getAllJobs{color}() {color:#cc7832}throws {color}Exception {
>  OpenTypeFactory factory = 
> OpenTypeSupport.getFactory(Job.{color:#cc7832}class{color}){color:#cc7832};{color}
>  CompositeType ct = factory.getCompositeType(){color:#cc7832};{color} 
> TabularType tt = {color:#cc7832}new 
> {color}TabularType({color:#6a8759}"Scheduled Jobs"{color}{color:#cc7832}, 
> {color}{color:#6a8759}"Scheduled Jobs"{color}{color:#cc7832}, 
> {color}ct{color:#cc7832}, new {color}String[] { {color:#6a8759}"jobId" 
> \{color}});{color} TabularDataSupport rc = {color:#cc7832}new 
> {color}TabularDataSupport(tt){color:#cc7832};{color} List<Job> jobs = 
> {color:#cc7832}this{color}.{color:#9876aa}jobScheduler{color}.getAllJobs(){color:#cc7832};{color}{color:#cc7832}
>  for {color}(Job job : jobs) {
>  rc.put({color:#cc7832}new {color}CompositeDataSupport(ct{color:#cc7832}, 
> {color}factory.getFields(job))){color:#cc7832};{color} }
>  {color:#cc7832}return {color}rc;
>  \{color}}
> This can be triggered by clicking on the Schduled tab in the webconsole.
> The error only occurs due to duplicate JobIds.
> Debugging this error, we can see that two jobs with different payloads have 
> the same JobId - this should not be allowed to occur.
> We need to ensure that JobIds are unique.
> Note:
> In test scenario virtual topics are in use, with two consumers.
> Redelivery plugin is also in use on the Broker.
> <plugins>
>             <redeliveryPlugin fallbackToDeadLetter="false" 
> sendToDlqIfMaxRetriesExceeded="false">
>                 <redeliveryPolicyMap>
>                     <redeliveryPolicyMap>
>                         <defaultEntry>
>                             <redeliveryPolicy backOffMultiplier="2" 
> initialRedeliveryDelay="60000" maximumRedeliveries="20" 
> maximumRedeliveryDelay="300000" useExponentialBackOff="true"/>
>                         </defaultEntry>
>                     </redeliveryPolicyMap>
>                 </redeliveryPolicyMap>
>             </redeliveryPlugin>
>         </plugins>



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to