question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BloomFilter multithread problem: put() NOT atomic

See original GitHub issue

Hello team!

I just found a problem using com.google.common.hash.BloomFilter with more than one thread. Long story short: put() is not atomic so I am able to reproduce a false negative.

This is the config in pom.xml:

<dependency>
   <groupId>com.google.guava</groupId>
   <artifactId>guava</artifactId>
   <version>24.0-jre</version>
</dependency>

I created a simple Test.java class that proves the point. The fix is also included in the file: just uncomment lines 56 and 58 (make put() synchronized).

Looking at the BloomFilter javadoc I see:

 * As of Guava 23.0, this class is thread-safe and lock-free. It internally uses atomics and
 * compare-and-swap to ensure correctness when multiple threads are used to access it.

So I suppose that I’m not doing anything “wrong”. Can you please confirm the issue or tell me where I’m using the library wrong?

Thanks!

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ben-manescommented, Mar 5, 2018

My understanding was that thread-safe and lock-free in the JavaDoc does not guarantee that the entire operation is atomic. This allowed the small design change in #2748 to be racy, assuming that the results were overall okay.

The alternative that I proposed was more invasive, by using a Bloom-1 design. If redesigning the implementation to target concurrency, then I think it would be better to adopt that. But the goal was to expand usage to allow best effort concurrency, so the implementation change seemed reasonable as is.

0reactions
lowassercommented, Mar 5, 2018

I’m not sure I see a thread-safe, lock-free solution that returns a meaningful value from put. We might be in a position of being forced to break one of those API specifications.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Concurrent bloom filters - Chris Stucchio
Concurrent reads are no problem, but writes are trickier - and reading while writing is also not straightforward.
Read more >
thread-safe bloomfilter - java - Stack Overflow
I'm imagining the effects of replacing the long[] with an AtomicLongArray , and I'm pretty sure the semantics you end up with are...
Read more >
Java Multithreading (Hard) Question. Any idea? - LeetCode
Where will the concurrent writes by the background thread go? To a new list so that it does not affect the current list....
Read more >
BloomFilter (Guava: Google Core Libraries for Java 23.0 API)
The false positive probability ( FPP ) of a Bloom filter is defined as the ... return true for an object that has...
Read more >
On Adapting the Bloom Filter to Multithreaded Environments
To ensure consistency and data access ordering, all k values need to be updated atomically. This is not possible with atomic CPU operations...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found