The keycloak project ended with four open questions that design could not
settle. A two-VM lab was built to answer them by measurement, and this is
that material: 26 experiments, 125 raw command outputs, 22 browser captures.
Follows the import procedure in README.md.
source/ the originating repository verbatim — 78 documents, 28 SVGs,
8 manifests, plus .source-revision recording the commit
final/ the SSOT
document.md 729 lines written from the 29 experiment documents, not
concatenated: what was predicted, what was measured, and
where the measurement itself was wrong
evidence/raw 125 outputs, flattened to <experiment>__<file> because
the originals collided (01-baseline.txt appeared three
times) and the audit only globs the top level
evidence/meta one per raw file; command and exitCode are null and the
README says why rather than inventing them
evidence/browser 22 captures
assets/ three diagrams through techviz
.techviz/ their VizSpecs
A separate project rather than an addition to keycloak: the B-layer answers
that project's four questions, but the A, C and D layers are about cluster
failure, SSO and operations, and one document.md should hold one subject.
The four question records there can point here through 관계.
Recorded rather than papered over: only three of the 28 diagrams were
remade. The repository forbids hand-drawn SVG and forbids titles inside the
canvas; all 28 originals carry both, so converting them is redrawing, not
reformatting. They stay in source/ and the gap is written into the document.
verify-pipeline.py passes. audit-records.py reports no issues.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
68 lines
4.1 KiB
Markdown
68 lines
4.1 KiB
Markdown
---
|
|
kind: CONCEPT
|
|
slug: adapter-outbound-persistence-mongo-c07
|
|
title: 투영 먼저 checkpoint 나중, 그리고 3-state claim
|
|
topic: delivery-and-settlement-models
|
|
project: clean-architecture-backend-template
|
|
status: 게시 전
|
|
sourceRevision: 21234e38cdb9a926cbc92bb97a2aee2e4a7d2916
|
|
rootTreeNode: concept:adapter-outbound-persistence-mongo-c07
|
|
evidenceCapturedOn: 2026-09-01
|
|
assets:
|
|
- key: adapter-outbound-persistence-mongo-c07
|
|
file: ../../../final/evidence/rendered/adapter-outbound-persistence-mongo-c07.svg
|
|
evidence:
|
|
- ../../../final/evidence/raw/adapter-outbound-persistence-mongo-c07.txt
|
|
source:
|
|
- 원본 분석 절은 analysis/06-adapter-outbound-persistence-mongo.md#L1015 이다.
|
|
module: adapter-outbound-persistence-mongo
|
|
---
|
|
|
|
# 투영 먼저 checkpoint 나중, 그리고 3-state claim
|
|
|
|
이 leaf에서 유일하게 조립까지 된 대형 서브시스템이고, 그 설계의 규칙 대부분이 과거 결함을 이름으로 적어 두고 있다.
|
|
|
|
## 본문
|
|
|
|
<!-- body:start -->
|
|
|
|
앞선 sub-scope들과 다르다. `MongoPlatformAutoConfiguration`이 두 개의 bean을 실제로 만든다.
|
|
|
|
- `mongoChangeStreamSource`(209행) — `SpringReactiveChangeStreamSource`, 무조건.
|
|
- `reactiveMongoChangeStreamConsumer`(235행) — fork만 공급할 수 있는 5종(`MongoChangeStreamSubscription`, `MongoResumeCheckpointStore`, `MongoResumeTokenCodec`, `MongoChangeProjector`, `MongoChangeDeduplicationStore`)에 `@ConditionalOnBean`.
|
|
|
|
## MongoPlatformAutoConfiguration 참조 위치
|
|
|
|
:::evidence key="adapter-outbound-persistence-mongo-c07" alt="코드베이스에서 MongoPlatformAutoConfiguration 를 검색한 출력 14줄. 이 기록이 세는 참조가 그 출력에 그대로 보인다." caption="MongoPlatformAutoConfiguration 코드베이스 검색 — 14줄 · exit 0" zoom="true"
|
|
:::
|
|
|
|
## fork가 다섯을 채우면 완성된 소비자가 돈다
|
|
|
|
pipeline·runner·recovery policy·invalidate recovery는 auto-configuration이 직접 `new`한다. 이 사실이 아래 §67의 심각도를 결정한다.
|
|
|
|
## 순서가 계약이다
|
|
|
|
`MongoChangeStreamRunner`는 투영 먼저, checkpoint 나중이다 — "Checkpointing first would mean a crash between the two loses the event permanently, with no trace." 그래서 중복을 택하고 중복을 제거한다.
|
|
|
|
## 읽고-쓰기가 동시성에서 살아남지 못했다
|
|
|
|
과거 `alreadyProjected` + `markProjected`는 동시에 `false`를 읽은 두 subscriber가 둘 다 투영했다 — "the deduplication that exists precisely because redelivery is guaranteed did not survive concurrency". 지금은 `CLAIMED`/`ALREADY_COMPLETED`/`BUSY`의 원자적 전이다.
|
|
|
|
## 빈 완료는 프로토콜 위반이다
|
|
|
|
`Mono<Boolean>`이 empty로 완료되면 `flatMap`을 그냥 통과해 "투영도 checkpoint도 없이 아무도 문제를 보고하지 않는" 상태가 됐다. 이제 `switchIfEmpty(Mono.error(...))`로 잡는다.
|
|
|
|
## 구분자를 0x1F로 고른 이유
|
|
|
|
identity는 SHA-256이고 구분자는 ASCII unit separator(0x1F)다 — namespace/clusterTime/operationType에 나타날 수 없으므로 필드 재배열로 다른 이벤트의 identity를 위조할 수 없다. 한 transaction이 같은 문서를 두 번 고치면 앞 네 필드가 모두 같아지므로 `txnNumber`+`lsid` discriminator를 추가로 넣는다 — 없으면 두 번째가 첫 번째의 재전달로 **버려진다**.
|
|
|
|
## 로그에 찍히면 안 되는 것
|
|
|
|
`MongoResumeCheckpoint.toString()`은 길이만 보고한다. token은 clusterTime과 documentKey를 인코딩하므로 로그에 찍는 순간 production write의 모양과 타이밍이 샌다.
|
|
|
|
## 기본 구현을 일부러 두지 않았다
|
|
|
|
`MongoResumeTokenCodec`에는 기본 구현이 없다 — "a built-in that merely encoded would be worse than none: it would satisfy the type and none of the reason for it." `HISTORY_LOST`는 자동 복구하지 않는다 — "resuming from now… the projection then looks healthy and is quietly wrong, which is worse than a stopped consumer somebody has to look at." `MongoClusterTime`은 숫자로 비교한다 — 텍스트 비교는 `1700000000.10`을 `1700000000.9`보다 앞에 놓는데, 그것은 바쁜 1초가 정확히 만드는 경우다.
|
|
|
|
<!-- body:end -->
|