[improve][misc] Add primitive Long2LongOpenHashMap#26028
Conversation
lhotari
left a comment
There was a problem hiding this comment.
I'd rather use Fastutil for this purpose. However, it was dropped in #25413 due to a problem in implementing a gradle based solution to pick classes from Fastutil that are needed instead of pulling in the whole fastutil dependency to Pulsar client. In the maven build pulsar-client-dependencies-minimized handles including the classes which are needed.
The fastutil jar is over 25MB is size and that's why a minimizer solution is needed.
I'll take a look if we can revert #25413 and go back to a solution where it's minimized with Gradle. The reason for this is that there have been bugs in the past in custom collection implementations and it's a maintenance overhead for the project to implement various primitive collections to address different use cases (where keys and values are of different type).
I'll block this PR until I have checked the possibility of reverting #25413 and re-implementing pulsar-client-dependencies-minimized with Gradle. If that's not possible, let's go ahead with this PR.
|
PR to restore fastutil is #26032 |
Motivation
Part of #26027.
This adds a small primitive long-to-long hash map that can be reused by later PendingAcksMap storage changes. The patch is intentionally standalone and does not change broker behavior.
Modifications
Long2LongMapas the minimal primitive map contract needed by the follow-up work.Long2LongOpenHashMapusing open addressing with primitivelongkeys and values.The map returns
0for missing keys onget/put/remove, matching the existing primitive-map style in this package. Callers that need to distinguish a stored zero value can usecontainsKeyorgetOrDefault.Verifying this change
./gradlew :pulsar-common:test --tests org.apache.pulsar.common.util.collections.Long2LongOpenHashMapTest --max-workers=1 -PtestRetryCount=0./gradlew :pulsar-common:checkstyleMain :pulsar-common:checkstyleTest --max-workers=1