Skip to content

Fix MagazineManager evicting every other magazine on registration - #15

Merged
mirzabob merged 9 commits into
mainfrom
develop_shantanu
Sep 24, 2026
Merged

mirzabob merged 9 commits into
mainfrom
develop_shantanu

Conversation

@tshan10

@tshan10 tshan10 commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

The bug

MagazineManager.refresh(List<Magazine<?>>) replaced the entire registry instead of upserting into it. A caller registering magazines one at a time — the natural reading of "refresh", and what the method did in 1.x — unregistered every other magazine. The next access to one of them threw MAGAZINE_NOT_FOUND, and rebuilding the handle cost a shard configuration read, because Magazine's constructor ends with an unconditional baseMagazineStorage.initialize(magazineIdentifier).

Nothing was deleted from storage — a Magazine is a handle. The cost is latency, and under concurrent single-magazine registrations the miss rate approaches 100%.

Why it regressed

1.x magazines.forEach(m -> magazineMap.put(m.getMagazineIdentifier(), m)) — upsert
2.0.0 magazineMap.set(magazines.stream().collect(toUnmodifiableMap(...))) — replace

2.0.0 fixed a genuine thread-safety bug (unsynchronised HashMap under concurrent refresh/get) by publishing an immutable map through an AtomicReference. The semantic change came along with it, under an unchanged name and an unchanged javadoc.

Changes

Removed refresh(List<Magazine<?>>). This is source-breaking against 2.0.0, which is why it is called out here — but 2.0.0 has no adopters, and the name was the whole defect. Migration is a rename to replaceAll, with no behaviour change.

Added

Method Purpose
register(Magazine<?>) Add one magazine, leaving other registrations untouched
getOrRegister(String, Supplier<Magazine<T>>) Return the registered handle, invoking the factory only on a miss
find(String) Non-throwing lookup returning Optional
unregister(String) Drop one registration; storage untouched
replaceAll(List<Magazine<?>>) The replace-everything operation, named accordingly

@sonarqubecloud

Copy link
Copy Markdown

@mirzabob
mirzabob merged commit 984bcb8 into main Sep 24, 2026
7 checks passed
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.

2 participants