Giter Site home page Giter Site logo

Comments (6)

ikhoon avatar ikhoon commented on June 9, 2024

As NonBlockingHashSet delegates to NonBlockingHashMap, the problem is also reproduced in NonBlockingHashMap

NonBlockingHashMap<MyEntry, String> map = new NonBlockingHashMap<>();
map.put(entry1, "a");
map.remove(entry1);
map.put(entry2, "a");
// entry1 is revived.
assert map.keySet().toArray()[0] == entry1;

from jctools.

nitsanw avatar nitsanw commented on June 9, 2024

The issue here is that:

  1. NBHM retains deleted keys (values in the set). This is a potential GC issue, but is inherent to the implementation.
  2. MyEntry is not a good key

Your code asserts that 2 entries are equal if the value is the same, ignoring updatedAt. NBHM therefore treats them as such and will not replace the reference to the first key with the second.

from jctools.

nitsanw avatar nitsanw commented on June 9, 2024

I'm closing, please comment if you feel this is breaking the Map API somehow.

from jctools.

ikhoon avatar ikhoon commented on June 9, 2024

please comment if you feel this is breaking the Map API somehow.

Yes, I think so. It is unexpected behavior and causes bugs in our project.

- final Set<Endpoint> healthyEndpoints = new NonBlockingHashSet<>();
+ final Set<Endpoint> healthyEndpoints = ConcurrentHashMap.newKeySet();

from jctools.

nitsanw avatar nitsanw commented on June 9, 2024

@ikhoon I understand your frustration. I don't think this is an issue that we can easily fix within the confines of the current implementation however.

  • NBHM hangs on to deleted keys until resize.
  • NBHM will not overwrite key (deleted or otherwise) with a new key which is equal to it on put.

Changing this latter behaviour will slow down all operations on map by adding more code to a critical path which is already crowded. It can be done (by specialising behaviour on previous value being TOMBSTONE and key being equal), but I would need a strong argument from Map/Set documentation which clearly shows this behaviour to be wrong.

from jctools.

ikhoon avatar ikhoon commented on June 9, 2024

Thanks for your consideration. As I knew the expected behavior of NBHM, I can carefully use it. Mentioning this behavior in Javadoc would be super helpful for users. 🙇‍♂️

from jctools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.