[
https://issues.apache.org/jira/browse/PROTON-1958?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Robbie Gemmell reassigned PROTON-1958:
--------------------------------------
Assignee: Robbie Gemmell
Fix Version/s: proton-j-0.30.0
Description:
When reactor timer tasks are scheduled with the same deadline, there is some
handling in the task compareTo handling which looks to impose a first-scheduled
order on them. This isn't effective though as the counter value used in the
effort is erroneously always equal. Each timer should index its tasks to ensure
they can be ordered on the expected first-scheduled basis when tasks have equal
deadlines.
===============
Original description:
Looking at the implementation, it seems that every instance of TaskImpl has
{{this.counter == 0}}. This seems wrong. The {{count}} field should be static
for the instance id to work.
{code:java}
public class TaskImpl implements Task, Comparable<TaskImpl> {
[...]
private final AtomicInteger count = new AtomicInteger();
[...]
public TaskImpl(long deadline) {
this.deadline = deadline;
this.counter = count.getAndIncrement();
}
@Override
public int compareTo(TaskImpl other) {
int result;
if (deadline < other.deadline) {
result = -1;
} else if (deadline > other.deadline) {
result = 1;
} else {
result = counter - other.counter;
}
return result;
}
{code}
was:
Looking at the implementation, it seems that every instance of TaskImpl has
{{this.counter == 0}}. This seems wrong. The {{count}} field should be static
for the instance id to work.
{code}
public class TaskImpl implements Task, Comparable<TaskImpl> {
[...]
private final AtomicInteger count = new AtomicInteger();
[...]
public TaskImpl(long deadline) {
this.deadline = deadline;
this.counter = count.getAndIncrement();
}
@Override
public int compareTo(TaskImpl other) {
int result;
if (deadline < other.deadline) {
result = -1;
} else if (deadline > other.deadline) {
result = 1;
} else {
result = counter - other.counter;
}
return result;
}
{code}
Summary: incorrect ordering for reactor timer tasks with matching
deadlines (was: compareTo for tasks with same deadline is broken)
> incorrect ordering for reactor timer tasks with matching deadlines
> ------------------------------------------------------------------
>
> Key: PROTON-1958
> URL: https://issues.apache.org/jira/browse/PROTON-1958
> Project: Qpid Proton
> Issue Type: Bug
> Components: proton-j
> Affects Versions: proton-j-0.29.0
> Reporter: Jiri Daněk
> Assignee: Robbie Gemmell
> Priority: Major
> Fix For: proton-j-0.30.0
>
>
> When reactor timer tasks are scheduled with the same deadline, there is some
> handling in the task compareTo handling which looks to impose a
> first-scheduled order on them. This isn't effective though as the counter
> value used in the effort is erroneously always equal. Each timer should index
> its tasks to ensure they can be ordered on the expected first-scheduled basis
> when tasks have equal deadlines.
> ===============
> Original description:
> Looking at the implementation, it seems that every instance of TaskImpl has
> {{this.counter == 0}}. This seems wrong. The {{count}} field should be static
> for the instance id to work.
> {code:java}
> public class TaskImpl implements Task, Comparable<TaskImpl> {
> [...]
> private final AtomicInteger count = new AtomicInteger();
> [...]
> public TaskImpl(long deadline) {
> this.deadline = deadline;
> this.counter = count.getAndIncrement();
> }
> @Override
> public int compareTo(TaskImpl other) {
> int result;
> if (deadline < other.deadline) {
> result = -1;
> } else if (deadline > other.deadline) {
> result = 1;
> } else {
> result = counter - other.counter;
> }
> return result;
> }
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]