Skip to content

[fix] Fix ArrayIndexOut0fBoundsException caused by optimistic lock#4066

Merged
dlg99 merged 11 commits into
apache:masterfrom
thetumbled:Fix_OptimisticLock
Apr 28, 2024
Merged

[fix] Fix ArrayIndexOut0fBoundsException caused by optimistic lock#4066
dlg99 merged 11 commits into
apache:masterfrom
thetumbled:Fix_OptimisticLock

Conversation

@thetumbled

@thetumbled thetumbled commented Sep 1, 2023

Copy link
Copy Markdown
Member

Motivation

This is the bug fix simillar to Pulsar. refer to: apache/pulsar#18390.

Changes

Fix bugs in:

ConcurrentLongHashMap
ConcurrentLongHashSet
ConcurrentLongLongHashMap
ConcurrentLongLongPairHashMap
ConcurrentOpenHashMap
ConcurrentOpenHashSet

@thetumbled

thetumbled commented Sep 18, 2023

Copy link
Copy Markdown
Member Author

Could you help to reviw this PR? @eolivelli @sijie @hangc0276 @zymap
Thanks.

@thetumbled

Copy link
Copy Markdown
Member Author

Could you help to reviw this PR? @eolivelli @dlg99 @hangc0276 @nicoloboschi @shoothzj @zymap @wenbingshen
This bug could happen when the concurrent data structure shrink it's capacity.

@thetumbled

Copy link
Copy Markdown
Member Author

I find that the same concurrency problem is reported in bookkeeper #4316, it is time to merge this fix into the bookkeeper.
PTAL, thanks. @lhotari @hangc0276 @eolivelli @wenbingshen @zymap @shoothzj @horizonzy

@dlg99 dlg99 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Thank you!

@dlg99 dlg99 changed the title Fix ArrayIndexOut0fBoundsException caused by optimistic lock [fix] Fix ArrayIndexOut0fBoundsException caused by optimistic lock Apr 28, 2024
@dlg99

dlg99 commented Apr 28, 2024

Copy link
Copy Markdown
Contributor

retest this please

@eolivelli

Copy link
Copy Markdown
Contributor

closing/reopening to trigger CI

@eolivelli eolivelli closed this Apr 28, 2024
@eolivelli eolivelli reopened this Apr 28, 2024

@eolivelli eolivelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

thanks

@dlg99

dlg99 commented Apr 28, 2024

Copy link
Copy Markdown
Contributor

Please fix the checkstyle


[INFO] There are 6 errors reported by Checkstyle 9.3 with buildtools/src/main/resources/bookkeeper/checkstyle.xml ruleset.
Error:  src/test/java/org/apache/bookkeeper/util/collections/ConcurrentLongHashMapTest.java:[224,29] (whitespace) WhitespaceAfter: ',' is not followed by whitespace.
Error:  src/test/java/org/apache/bookkeeper/util/collections/ConcurrentLongLongPairHashMapTest.java:[41,1] (imports) ImportOrder: Extra separation in import group before 'org.apache.bookkeeper.util.collections.ConcurrentLongLongPairHashMap.LongPair'
Error:  src/test/java/org/apache/bookkeeper/util/collections/ConcurrentLongHashSetTest.java:[40,1] (imports) ImportOrder: Extra separation in import group before 'org.junit.Test'
Error:  src/test/java/org/apache/bookkeeper/util/collections/ConcurrentLongLongHashMapTest.java:[42,1] (imports) ImportOrder: Extra separation in import group before 'org.apache.bookkeeper.util.collections.ConcurrentLongLongHashMap.LongLongFunction'
Error:  src/test/java/org/apache/bookkeeper/util/collections/ConcurrentOpenHashMapTest.java:[220,32] (whitespace) WhitespaceAfter: ',' is not followed by whitespace.
Error:  src/test/java/org/apache/bookkeeper/util/collections/ConcurrentOpenHashSetTest.java:[39,1] (imports) ImportOrder: Extra separation in import group before 'org.junit.Test'

@thetumbled

Copy link
Copy Markdown
Member Author

Please fix the checkstyle


[INFO] There are 6 errors reported by Checkstyle 9.3 with buildtools/src/main/resources/bookkeeper/checkstyle.xml ruleset.
Error:  src/test/java/org/apache/bookkeeper/util/collections/ConcurrentLongHashMapTest.java:[224,29] (whitespace) WhitespaceAfter: ',' is not followed by whitespace.
Error:  src/test/java/org/apache/bookkeeper/util/collections/ConcurrentLongLongPairHashMapTest.java:[41,1] (imports) ImportOrder: Extra separation in import group before 'org.apache.bookkeeper.util.collections.ConcurrentLongLongPairHashMap.LongPair'
Error:  src/test/java/org/apache/bookkeeper/util/collections/ConcurrentLongHashSetTest.java:[40,1] (imports) ImportOrder: Extra separation in import group before 'org.junit.Test'
Error:  src/test/java/org/apache/bookkeeper/util/collections/ConcurrentLongLongHashMapTest.java:[42,1] (imports) ImportOrder: Extra separation in import group before 'org.apache.bookkeeper.util.collections.ConcurrentLongLongHashMap.LongLongFunction'
Error:  src/test/java/org/apache/bookkeeper/util/collections/ConcurrentOpenHashMapTest.java:[220,32] (whitespace) WhitespaceAfter: ',' is not followed by whitespace.
Error:  src/test/java/org/apache/bookkeeper/util/collections/ConcurrentOpenHashSetTest.java:[39,1] (imports) ImportOrder: Extra separation in import group before 'org.junit.Test'

fixed, please help to re-trigger the CI, thanks.

@dlg99
dlg99 merged commit e4faf25 into apache:master Apr 28, 2024
dlg99 pushed a commit to datastax/bookkeeper that referenced this pull request Apr 29, 2024
@lhotari

lhotari commented Apr 30, 2024

Copy link
Copy Markdown
Member

@dlg99 @eolivelli Please cherry-pick this PR to branch-4.16.

dlg99 added a commit to datastax/bookkeeper that referenced this pull request May 1, 2024
…pache#4066) (#18)

(cherry picked from commit e4faf25)

Co-authored-by: thetumbled <52550727+thetumbled@users.noreply.github.com>
@hezhangjian

Copy link
Copy Markdown
Member

@lhotari done

@keyboardbobo

keyboardbobo commented Nov 17, 2025

Copy link
Copy Markdown

java.lang.ArrayIndexOutOfBoundsException: 1774
at org.apache.bookkeeper.util.collections.ConcurrentLongHashMap$Section.get(ConcurrentLongHashMap.java:346) ~[bookkeeper-server-4.14_vivo-1.5.3-20251114.065856-16.jar:4.14_vivo-1.5.3-SNAPSHOT]
at org.apache.bookkeeper.util.collections.ConcurrentLongHashMap.get(ConcurrentLongHashMap.java:206) ~[bookkeeper-server-4.14_vivo-1.5.3-20251114.065856-16.jar:4.14_vivo-1.5.3-SNAPSHOT]

@thetumbled I cherry-pick this PR, but the error still occurred, although the probability of it appearing was greatly reduced. Should we catch the exception and perform lock upgrade when accessing long storedKey = keys[bucket] out of bounds?

@lhotari

lhotari commented Nov 17, 2025

Copy link
Copy Markdown
Member

java.lang.ArrayIndexOutOfBoundsException: 1774
at org.apache.bookkeeper.util.collections.ConcurrentLongHashMap$Section.get(ConcurrentLongHashMap.java:346) ~[bookkeeper-server-4.14_vivo-1.5.3-20251114.065856-16.jar:4.14_vivo-1.5.3-SNAPSHOT]
at org.apache.bookkeeper.util.collections.ConcurrentLongHashMap.get(ConcurrentLongHashMap.java:206) ~[bookkeeper-server-4.14_vivo-1.5.3-20251114.065856-16.jar:4.14_vivo-1.5.3-SNAPSHOT]

@thetumbled I cherry-pick this PR, but the error still occurred, although the probability of it appearing was greatly reduced. Should we catch the exception and perform lock upgrade when accessing long storedKey = keys[bucket] out of bounds?

@keyboardbobo please report a new issue and share your stack trace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants