New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve concurrent behavior of Java ConcurrentMap
wrapper
#10027
Conversation
It'd be nice if you add @igabaydulin to co-authors. I guess most of the work was done by them. Thank you! |
I don't mind giving credit per https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors I need to know what info to use. "most of the work" would include writing the test and what to patch. But I appreciate the nice bug report. |
@som-snytt |
@som-snytt I wasn't about the counting efforts of fixing this bug in the statement 'most of the work', rather just asking for adding into co-authors, in a way you pointed it out, thanks 👍🏻 |
Thanks again. Oh hey, it worked, I see the tiny avatar. |
The racy unit test requires more cycles to be less false-negative. Co-authored-by: Igor Gabaydulin <igabaydulin@gmail.com>
I'll bring out my next album under the name The The Wrappers don't come pre-wrapped for mima:
|
The linearization is
where the order of
It's desirable for I think it's easier and clearer not to be too clever in minimizing duplication (by using My other observation is that I was under the mistaken impression that all users are trading performance for convenience. However, the code comment that |
Inspired by the recently linked tickets, I updated the PR description. The workaround is to inline |
ConcurrentMap
wrapper
It would be useful to describe in a bit more detail what is the expected behavior with this change.
On the other hand, the Scala
I looked at the tests added via this PR and it didn't seem like it tested |
ConcurrentMap
wrapperConcurrentMap
wrapper
I tweaked the description and title, as the change is not about A previous commit aligned handling of The test for this PR is just to demonstrate that concurrency is correctly supported. |
Thanks for the clarification @som-snytt. The following seems like an undesirable change though, no?
I'd expect |
@ijuma I think it falls under the umbrella of "follow the behavior established by Java". I see Java's
since Scala lacks At some cost, maybe it's possible to wrap the remapper, and then if it is invoked and returns |
Linked PR bends over backward to support |
(Does anyone want to argue that that PR can't/shouldn't wait until 2.13.10? Since we've already got a 2.13.9 release candidate.) |
On second thought: if we do anything further for 2.13.9, perhaps it should be to simply revert this PR, to give us more time to decide what the final state should be, and then later we could move to that final state all at once. When I commented 3 days ago my frame of mind was that I was very reluctant to consider any 2.13.9 changes now that we already have a release candidate, but we probably needn't be so strict about reversions — a reversion isn't really a new change, it just restores the previous status quo. @lrytz said he'd have a look at the details before weighing in. |
My take is that 2.12 and 2.13 should be very careful about changing behavior at this point, so best to err on the side of caution. |
My take is that the bug is really terrible and must be fixed. The Onion headline: "ConcurrentMap not actually concurrent." I think null policy is nice to have. Compare the previous fix in #9344 where I also unhappily got involved. If the set of users of the Java wrappers cared about nulls as a critical issue, it would have had more visibility earlier. I don't think the fix to throw NPE is a critical fix by any stretch. |
To make this explicit (and repeat from the PR description): by using What's the advantage of the new overrides that this PR adds to the non-concurrent wrappers in IMO, the following behavior in current 2.13.x is a regression we should iron out before 2.13.9:
To fix it, we could
I'm fine with either solution. The new PR would fix null handling also for the concurrent wrapper, but that doesn't seem very urgent / important as the two |
I'm willing to submit whatever sequence of PRs makes Seth's life easier. I think the contribution from ijuma and the follow-up represent normal "RC" tightening of screws, in the sense of "if there is anyone present who can show just cause why these two PRs may not be merged, speak now or forever hold your peace." Maybe lightbend can release the PRs under their special paid license plan! |
I'll escalate and see what can be arranged 😅 |
#10129 is merged for 2.13.9. I'll update the release thread on Discourse. |
Improve the atomicity of
updateWith
by callingcompute
on the JavaConcurrentMap
.Similarly,
getOrElseUpdate
callscomputeIfAbsent
.Note that
null
values are not supported.The 2.13.8 version of
concurrentMap.asScala.getOrElseUpdate
callsunderlying.putIfAbsent
, which NPEs onnull
; the new version callsunderlying.computeIfAbsent
, which ignores a null computed value.Code which relies on the new behavior will throw an exception when used with a previous version of the library.
Fixes scala/bug#12586