Repository navigation
ARTEMIS-6289 Use AtomicLong instead of synchronized counter in SimpleIDGenerator - #6770
amarkevich wants to merge 1 commit into
Conversation
|
This looks good to me, although That said, I did notice that there's no unit test for |
| return idSequence.getAndUpdate(id -> { | ||
| if (id == Long.MAX_VALUE) { | ||
| // Wrap - Very unlikely to happen | ||
| throw new IllegalStateException("Exhausted ids to use!"); |
There was a problem hiding this comment.
I would set it to 0 if this ever happens... similar to what the Journal backed generator does.
There was a problem hiding this comment.
The constructor does not enforce that the sequence starts at/above 0 so it could as equally have been Long.MIN_VALUE it started at, or any other value. Wrapping to 0 would seem to be making an assumption which doesnt necessarily fit with that constructor?
There was a problem hiding this comment.
I just meant to wrap like it used to be. it used to be MIN_VALUE I guess.
There was a problem hiding this comment.
It didnt used to wrap at all, it threw which is why I was confused between this and the other comment (which I wonder if you meant to reply to here instead) that seemed they might conflict.
There was a problem hiding this comment.
Well ok...it wrapped the field, noticed, remembered it, then threw rather than return any value. Is that what you meant? Here it just noticed the value (tracing the current/previous id) hit MAX_VALUE and threw before the incrementing wrapped, so that it didnt need to remember anything.
| public long generateID() { | ||
| return idSequence.getAndUpdate(id -> { | ||
| if (id == Long.MAX_VALUE) { | ||
| // Wrap - Very unlikely to happen |
There was a problem hiding this comment.
I would keep the previous semantics.
There was a problem hiding this comment.
I'm not clear which semantics you mean here, can you clarify? Especially as you have 2 comments from <1min apart overlapping 3 of the same line numbers of code context.
|
If making changes here it would make more sense to use AtomicLongFieldUpdater and a single volatile long value instead of creating a new AtomicLong for every instance of this type. |
I'm not sure there would ever be enough instances of |
I'm not sure why one needs to justify good coding practices... |
1d89e67 to
4aa20c3
Compare
Perhaps I'm wrong about this, but my understanding is that the main use-case for any field updater is lowering memory use at scale. The main trade-offs being some clunky boilerplate code, the loss of compile-time type safety, and slightly higher per-call overhead. However, if the scale is too low to reap meaningful memory benefits then it seems reasonable to use the standard |
4aa20c3 to
43babc8
Compare
There seem like enough connection and session specific uses of it that it might be worth it in this case? Having one would mean both use cases were covered, vs having both implementations as the PR now seems to? |
| /** | ||
| * {@link AtomicLongFieldUpdater} can only bind to a {@code volatile} <em>instance</em> field | ||
| * ({@code newUpdater} throws {@link IllegalArgumentException} for static fields), so the | ||
| * JVM-wide counter lives on this single static holder instance. |
There was a problem hiding this comment.
Why is this generator now being made JVM-wide? It doesnt seem like it was originally in the place you used it, but rather per-session.
There was a problem hiding this comment.
Unclear why this was resolved...unresolving.
There was a problem hiding this comment.
move logic completely to ActiveMQSessionContext to avoid generator instance creation
There was a problem hiding this comment.
I'm not sure if you arent understanding my question or are just repeatedly ignoring it.
Why have you changed the semantics of the session-level consumer id, from being indexed per-session to being per-JVM? I see nothing here or the Jira about why that is being done.
There was a problem hiding this comment.
got your point - reverted per-session counter
1ed70f1 to
869ade2
Compare
869ade2 to
dc6917e
Compare
SimpleIDGenerator
dc6917e to
3e19475
Compare
No description provided.