Skip to content

feat(engine): encapsulate label management in the Router SPI - #2404

Merged
jfallows merged 5 commits into
developfrom
claude/router-spi-label-manager
Aug 20, 2026
Merged

jfallows merged 5 commits into
developfrom
claude/router-spi-label-manager

Conversation

@jfallows

Copy link
Copy Markdown
Contributor

Summary

  • Move label-id assignment and lookup from the engine's internal LabelManager singleton onto the Router/RouterContext SPI (supplyLabelId, supplyLabel, and watchLabels on Router), so a Router implementation owns label-id coordination — letting a future cluster-aware router supply its own consistency mechanism instead of relying on today's process-local, append-order assignment.
  • EngineRouter absorbs LabelManager's in-memory behavior (seeded from the existing <directory>/labels file); internal.LabelManager is deleted. TestRouter mirrors the same behavior so type: test router configs keep working.
  • The engine remains solely responsible for bootstrapping from and flushing to the on-disk labels file, independent of which Router implementation is active, so zilla dump's independent reader of that file format is unaffected.
  • No new binding and no Router.store(): Store — Router is already the correct process-wide SPI extension point, and routing label consistency through a generic Store would force an implicit mandatory store-memory runtime dependency for the default case and mismatch the CP guarantees a future cluster router needs.

Test plan

  • ./mvnw clean verify -pl runtime/engine — 226 unit tests + 208 integration tests pass, including EngineIT and RouterFactoryTest (extended with new coverage for supplyLabelId/supplyLabel through both Router and RouterContext, watchLabels notification, and bootstrap-from-existing-file correctness)
  • JaCoCo coverage checks pass
  • Confirmed incubator/command-dump's independent labels file reader has no coupling to the deleted internal.LabelManager class

Generated by Claude Code

claude added 4 commits August 20, 2026 02:22
Router/RouterContext gain supplyLabelId/supplyLabel (and Router gains
watchLabels) so a Router implementation owns label-id assignment and
lookup consistency, instead of the engine's own internal.LabelManager
singleton. EngineRouter/TestRouter absorb LabelManager's in-memory
behavior; the Engine remains solely responsible for bootstrapping from
and flushing to the on-disk labels file, independent of which Router
implementation is active, so zilla dump keeps working unchanged.
…le-agnostic

EngineRouter/TestRouter drop all knowledge of the labels file and the
synchronized block used to serialize new-label registration. Id
assignment is now a plain ConcurrentHashMap + AtomicInteger (mirroring
MemoryStoreHandler's lock-free style) since computeIfAbsent's per-key
atomicity is the only guarantee actually needed.

Engine now owns bootstrapping too: it reads the labels file itself and
replays each entry through the ordinary supplyLabelId call before
registering the watchLabels flush listener, so a Router implementation
never needs file-reading logic to reproduce prior label ids.
Router.watchLabels now takes ObjectIntBiConsumer<String> instead of
BiConsumer<String, Integer>, mirroring the existing LongObjectBiConsumer
pattern in this package. The primitive int overload lets EngineRouter/
TestRouter notify listeners on every new-label registration without
boxing the label id.
binding-http and engine each carried their own copy of this helper
functional interface. Helper functional interfaces of this shape
already live in common-lang's util.function package (LongObjectBiFunction,
LongObjectPredicate), so ObjectIntBiConsumer moves there too and both
call sites reference the shared type instead of a local duplicate.

engine now depends on common-lang (a dependency-free leaf module, no
cycle risk) and re-exports it transitively so any Router implementation
can reference ObjectIntBiConsumer; binding-http picks it up the same
way it already does common-agrona, transitively through its existing
engine dependency, with no pom.xml or module-info change needed there.

@jfallows jfallows left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Contributor Author

Build (25) and CodeQL's Analyze (java) are both red, but on the same pre-existing, unrelated cause: runtime/binding-tcp/NOTICE fails notice:check because the checked-in file already lists zilla::runtime::common-lang as a dependency, even on develop — where runtime/engine/pom.xml doesn't declare common-lang at all (confirmed via git show origin/develop:runtime/engine/pom.xml, no match). That NOTICE entry was checked in by #2231, unrelated to this PR, and this PR never touches binding-tcp.

Not fixing it here since it's out of scope for this change. Proposed fix for a follow-up: regenerate runtime/binding-tcp/NOTICE via ./mvnw notice:generate --projects runtime/binding-tcp against current develop (or investigate why #2231's checked-in NOTICE doesn't match its own dependency tree).

Will keep watching and re-run once the base recovers.


Generated by Claude Code

common-lang reaches binding-tcp only transitively through engine, which
is a provided-scope dependency here; the notice-plugin's includeScopes
is compile-only, so provided-scope transitives are correctly excluded
(engine and its own dependencies are attributed via the Docker image
assembly, not per-binding). The checked-in NOTICE incorrectly listed
common-lang since #2231 -- unrelated to this branch's own change of
adding common-lang as a real (compile-scope) dependency of engine.

Verified against the authoritative NOTICE.expected produced by a full
reactor build (mirroring CI's ./mvnw clean package): the only diff was
this one stray line.
@jfallows
jfallows merged commit 1aad271 into develop Aug 20, 2026
42 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