You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by "dao-jun (via GitHub)" <gi...@apache.org> on 2024/04/27 00:36:40 UTC
[I] [Bug] Bookkeeper concurrent containers has concurrency issues [bookkeeper]
dao-jun opened a new issue, #4318:
URL: https://github.com/apache/bookkeeper/issues/4318
**BUG REPORT**
***Describe the bug***
[ConcurrentLongHashMap](https://github.com/apache/bookkeeper/blob/master/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/collections/ConcurrentLongHashMap.java), [ConcurrentLongHashSet](https://github.com/apache/bookkeeper/blob/master/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/collections/ConcurrentLongHashSet.java),[ConcurrentLongLongHashMap](https://github.com/apache/bookkeeper/blob/master/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/collections/ConcurrentLongLongHashMap.java), [ConcurrentLongLongPairHashMap](https://github.com/apache/bookkeeper/blob/master/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/collections/ConcurrentLongLongPairHashMap.java),[ConcurrentOpenHashMap](https://github.com/apache/bookkeeper/blob/master/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/collections/ConcurrentOpenHashMap.java) and [ConcurrentOpenHashSet](https://github.com/apache/bookkeeper/blob/master/bookkeeper-server/src/main/java/
org/apache/bookkeeper/util/collections/ConcurrentOpenHashSet.java)
has the same issue refers to https://github.com/apache/bookkeeper/issues/4316.
This issue caused by their `rehash` method, the inner class `Section` extends `StampedLock` for the purpose of performance optimization.
We read entry from array without requires `lock` as following code(copy from ConcurrentLongHashMap) to optimize `read` operations:
```java
V get(long key, int keyHash) {
int bucket = keyHash;
long stamp = tryOptimisticRead();
boolean acquiredLock = false;
try {
while (true) {
int capacity = this.capacity;
bucket = signSafeMod(bucket, capacity);
// First try optimistic locking
long storedKey = keys[bucket];
V storedValue = values[bucket];
// ignore.....
}
// ignore...
}
// ignore....
```
The problem is
```java
int capacity = this.capacity;
bucket = signSafeMod(bucket, capacity);
```
and
```java
// First try optimistic locking
long storedKey = keys[bucket];
V storedValue = values[bucket];
```
are *not* in an atomic scope.
If `rehash` method triggered in an async thread *after* calculating `bucket` and finished *before* read entry from the array, we can read incorrect values from arrays.
Before https://github.com/apache/bookkeeper/pull/3074, it will only lead to read incorrect values, but https://github.com/apache/bookkeeper/pull/3074 introduces `shrink`, the new arrays' capital can be smaller than before, so `ArrayIndexOutOfBoundsExeception` happens.
The issue can be fixed with a same pattern, see https://github.com/apache/bookkeeper/pull/4317/files#diff-1214718241c7ea351d22fa5806ba112c64d64183fe2f091976d6165c4573d05a
***To Reproduce***
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
***Expected behavior***
A clear and concise description of what you expected to happen.
***Screenshots***
If applicable, add screenshots to help explain your problem.
***Additional context***
Add any other context about the problem here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@bookkeeper.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug] Bookkeeper concurrent containers has concurrency issues [bookkeeper]
Posted by "dao-jun (via GitHub)" <gi...@apache.org>.
dao-jun commented on issue #4318:
URL: https://github.com/apache/bookkeeper/issues/4318#issuecomment-2080270093
I'll handle the issue.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug] Bookkeeper concurrent containers has concurrency issues [bookkeeper]
Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on issue #4318:
URL: https://github.com/apache/bookkeeper/issues/4318#issuecomment-2080407079
There's already #4066 to fix the issue. @eolivelli @hangc0276 please review and merge it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug] Bookkeeper concurrent containers has concurrency issues [bookkeeper]
Posted by "dao-jun (via GitHub)" <gi...@apache.org>.
dao-jun closed issue #4318: [Bug] Bookkeeper concurrent containers has concurrency issues
URL: https://github.com/apache/bookkeeper/issues/4318
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org