[
https://issues.apache.org/jira/browse/IGNITE-3809?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15467391#comment-15467391
]
Semen Boikov commented on IGNITE-3809:
--------------------------------------
Hi,
There was a mistake in the my code snippet for 'getAndIncrement', it should
return 'next' instead of 'cur'. Also I think code can be simplified a little
for offer/prePoll (here you do not need extra '% cnt' for 'offer'):
{noformat}
final int MAX_CNT;
GridUnsafeLru(short cnt, GridUnsafeMemory mem) {
...
MAX_CNT = cnt - 1;
}
long offer(int part, long addr, int hash) throws
GridOffHeapOutOfMemoryException {
return lrus[getAndIncrement(addIdx, MAX_CNT)].offer(part, addr, hash);
}
long prePoll() {
int idx = getAndIncrement(rmvIdx, MAX_CNT);
// Must try to poll from each LRU.
for (int i = 0; i < lrus.length; i++) {
long qAddr = lrus[(idx + i) % cnt].prePoll();
if (qAddr != 0)
return qAddr;
}
return 0;
}
{noformat}
> ArrayIndexOutOfBoundsException in GridUnsafeLru
> -----------------------------------------------
>
> Key: IGNITE-3809
> URL: https://issues.apache.org/jira/browse/IGNITE-3809
> Project: Ignite
> Issue Type: Bug
> Components: cache
> Affects Versions: 1.7
> Reporter: Valentin Kulichenko
> Assignee: Roman Shtykh
> Fix For: 1.8
>
>
> {{GridUnsafeLru.offer(..)}} method uses atomic integer as a counter. In case
> of integer overflow this method will throw {{ArrayIndexOutOfBoundsException}}.
> We should use {{abs}} to avoid this. For example, like this:
> {code}
> return lrus[U.safeAbs(addIdx.getAndIncrement()) % cnt].offer(part, addr,
> hash);
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)