Skip to content

Replace unused failover with fanout for WAL/CDC writes - #344

Merged
em3s merged 5 commits into
kakao:mainfrom
eazyhozy:feature/producer-list-fanout
May 20, 2026
Merged

em3s merged 5 commits into
kakao:mainfrom
eazyhozy:feature/producer-list-fanout

Conversation

@eazyhozy

@eazyhozy eazyhozy commented May 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Unify produce() with produceHeartBeat() by replacing the primary/backup failover logic with an N-fanout. (see Note below) Replace the (effectively unused) primary/backup failover in produce() with an N-way fanout for WAL/CDC writes; produceHeartBeat() is unchanged (already a fanout, monitoring-only). All configured producers receive every message; any per-producer error propagates and fails the overall Mono<Void>.

Closes #343

Changes

  • Rewrite produce() using Flux.fromIterable(producers).flatMap { it.produce(message) }.then()
  • Remove assert(producers.size <= 2), primaryIdx, backUpIdx, producePrimaryOnly, and producePrimaryAndBackUp
  • Add require(producers.isNotEmpty()) in init block to fail fast on empty configuration
  • Update WalSpec and CdcSpec: replace failover-based scenarios with "all succeed → complete" and "any fails → error" cases
  • Add ProducerListSpec: directly test ProducerList fanout behavior with N=2 and N=3 producers, including verify assertions that all producers receive the message

Test cases (WalSpec / CdcSpec)

Spec Before After
WalSpec primary success, wal write succeed all producers succeed, wal write succeeds
WalSpec primary failed, but secondary success, wal write succeed any producer fails, wal write fails
WalSpec all wals failed, wal write failed (removed — covered by above)
CdcSpec primary success, cdc write succeed all producers succeed, cdc write succeeds
CdcSpec primary failed, but secondary success, cdc write succeed any producer fails, cdc write fails
CdcSpec all cdc failed, cdc write failed (removed — covered by above)

Test cases (ProducerListSpec — new)

Test Description
all producers receive the message N=2, both producers' produce() verified via mockk verify
any producer fails, produce fails N=2, one error → verifyError()
empty producer list throws IllegalArgumentException ProducerList(emptyList()) → IllegalArgumentException
fanout works with more than two producers N=3, all three producers' produce() verified

How to Test

./gradlew :engine:test --tests "com.kakao.actionbase.v2.engine.wal.WalSpec" --tests "com.kakao.actionbase.v2.engine.cdc.CdcSpec" --tests "com.kakao.actionbase.v2.engine.producer.ProducerListSpec"

AI Assistance

  • This PR was written largely with AI assistance.
    • Tool / model: Claude Sonnet 4.6 via Claude Code

Note by @em3s

Reframed the summary to match the issue (#343): this replaces the effectively-unused primary/backup failover with an N-way fanout for WAL/CDC writes, rather than "unifying produce() with produceHeartBeat()." produceHeartBeat() is out of scope — it already fans out and is monitoring-only. Chosen semantics: any per-producer error fails the overall Mono<Void> (we want to know when a dual-write cluster drops writes). The code already matches; only the summary wording changed.

@eazyhozy
eazyhozy requested a review from em3s as a code owner May 20, 2026 03:06
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label May 20, 2026
@CLAassistant

CLAassistant commented May 20, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Previously, produce() used primary/backup failover semantics — only the
primary was called on the happy path, and the backup was a fallback on
error. Configuring multiple producers (e.g. two Kafka clusters for
dual-publish) only sent actual mutations to the first producer that
succeeded, making true dual-publish impossible.

Rewrite produce() to fan out to all configured producers via
Flux.fromIterable().flatMap(). Unlike produceHeartBeat(), per-producer
errors are not swallowed — any failure propagates and fails the overall
Mono<Void>.

Remove assert(producers.size <= 2) and the now-unused primaryIdx,
backUpIdx, producePrimaryOnly, and producePrimaryAndBackUp members.

Update WalSpec and CdcSpec to reflect the new semantics:
- "all producers succeed" → verifyComplete
- "any producer fails" → verifyError

Closes kakao#343

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Happy <[email protected]>
@eazyhozy
eazyhozy force-pushed the feature/producer-list-fanout branch from 516d6ed to 57eae50 Compare May 20, 2026 03:09
@eazyhozy

eazyhozy commented May 20, 2026 •

Copy link
Copy Markdown
Member Author

@em3s One thing worth confirming before this merges: the WAL write is chained to the mutation via .then() in Graph.mutate(), and any WAL error is caught by .onErrorResume which returns EdgeOperationStatus.ERROR without executing the mutation.

kotlin~~ ~~// Graph.kt~~ ~~wal.write(...)~~ ~~ .then(label.mutate(...)) // skipped if WAL fails~~ ~~ .onErrorResume { ... Mono.just(MutationResultItem(status = ERROR)) }~~ ~~

With the current PR (all-or-nothing), a failure on any single producer propagates as a WAL error → mutation returns ERROR without executing.

If at-least-one is the intended policy (mutation proceeds as long as one producer succeeds), the implementation should use onErrorContinue per producer instead.

Given the context of a Kafka cluster migration where common3 is being stabilized, at-least-one may be more appropriate — a transient common3 failure would otherwise surface as a mutation error to callers.

Which policy is intended?


Update (resolved): Confirmed by @em3s in #343 (comment): all-or-nothing is the intended policy — all producers must succeed, errors must propagate (no onErrorContinue). The current PR implementation already aligns with this.

- Verify all producers receive the message (fanout)
- Verify any producer failure propagates as error (all-or-nothing)
- Verify fanout works with N>2 producers

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Happy <[email protected]>
@eazyhozy

Copy link
Copy Markdown
Member Author

@em3s Ready for review. Added ProducerListSpec (N=2, N=3 fanout + verify assertions) and updated the PR description accordingly.

@em3s

em3s commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

@eazyhozy quick review:

  1. (blocking) Empty producer list completes successfully without writing anywhere. Please guard it on startup (e.g. require(producers.isNotEmpty())).

  2. (non-blocking) On partial failure the other in-flight writes get cancelled — fine here since downstream is idempotent. Nice-to-have: short-circuit on first failure.

Add require(producers.isNotEmpty()) to fail fast on construction
rather than silently completing without publishing anywhere.
Add corresponding test case in ProducerListSpec.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Happy <[email protected]>
@eazyhozy

eazyhozy commented May 20, 2026 •

Copy link
Copy Markdown
Member Author

Fixed: added require(producers.isNotEmpty()) in the init block + test case in ProducerListSpec.

For the short-circuit nice-to-have: skipping for now — flatMap cancels in-flight subscriptions on first error, which is acceptable given idempotent downstream.

@em3s

@em3s em3s changed the title feat(producer-list): fan out produce() to all N producers feat(producer-list): replace unused failover with fanout for WAL/CDC writes May 20, 2026
@em3s em3s changed the title feat(producer-list): replace unused failover with fanout for WAL/CDC writes Replace unused failover with fanout for WAL/CDC writes May 20, 2026
@em3s
em3s removed their request for review May 20, 2026 13:08
@em3s

em3s commented May 20, 2026

Copy link
Copy Markdown
Contributor

Nice work.

On a partial failure we can't yet tell which cluster failed, but monitoring will surface that either way, so let's leave it for a follow-up improvement.

@em3s
em3s merged commit e0d5e73 into kakao:main May 20, 2026
1 check passed
eazyhozy added a commit that referenced this pull request May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace unused primary/backup failover with fanout for WAL/CDC writes

3 participants