Skip to content

[improve][misc] Add primitive Long2LongOpenHashMap#26028

Open
void-ptr974 wants to merge 1 commit into
apache:masterfrom
void-ptr974:pending-acks-long2long-map
Open

[improve][misc] Add primitive Long2LongOpenHashMap#26028
void-ptr974 wants to merge 1 commit into
apache:masterfrom
void-ptr974:pending-acks-long2long-map

Conversation

@void-ptr974

@void-ptr974 void-ptr974 commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

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

  • Add Long2LongMap as the minimal primitive map contract needed by the follow-up work.
  • Add Long2LongOpenHashMap using open addressing with primitive long keys and values.
  • Add oracle, random, collision, removal, zero/default-value, and edge-key/value coverage.

The map returns 0 for missing keys on get/put/remove, matching the existing primitive-map style in this package. Callers that need to distinguish a stored zero value can use containsKey or getOrDefault.

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

@void-ptr974 void-ptr974 changed the title [improve][common] Part 1: Add primitive Long2LongOpenHashMap [improve][misc] Add primitive Long2LongOpenHashMap Jun 15, 2026

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lhotari

lhotari commented Jun 15, 2026

Copy link
Copy Markdown
Member

PR to restore fastutil is #26032

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants