Files
clean-architecture-backend-…/docs/adr/ADR-MONGO-004-index-schema-admin-plane.md
DongHyeonka 74108497d4 docs(records): 기록과 ADR 맨 위에 한국어 머리 블록을 단다
문제: 설계서·계획서·납품 패키지·증거·학습 문서와 ADR이 기록이라는 표시
없이 지금 문서처럼 읽힌다. 상태 칸이 설계서 72개 중 40개, 계획서는
거의 없고, 있어도 Approved·확정·Accepted.처럼 값이 제각각이며 영어다.

고른 방법: docs/design, docs/history, docs/adr, docs/notification/adr의
.md 246개 맨 위에 같은 모양의 머리 블록을 단다. 칸은 상태·작성일·
요약(한국어 한 문장)·현재 정본, 대체됐으면 대체됨이다. 블록은 표시 줄
두 개로 감싸서 빼면 원문 바이트가 그대로 돌아온다(246개 모두 대조함).
- 종류는 폴더가 정하고 둘째 줄에 적는다(plans/evidence는 증거).
- 상태는 원래 상태 줄을 고정 어휘로 바꾼 값이다. 상태 줄이 없는
  설계서와 체크 상자가 다 표시되지 않은 계획서는 「확인 안 함」.
  capability-status.md 제거 표로 지운 것이 확인된 설계서 다섯은 「폐기」,
  2026-07-20 하네스 설계·계획과 production capability platform 설계는
  「대체됨」이다.
- 현재 정본은 구조 정리로 옮겨질 수 있는 src/messaging·src/grpc 대신
  docs/ 쪽 문서나 옮기지 않는 leaf README를 가리킨다.
docs/README.md에 「문서 수명과 언어」「기록 문서의 머리 블록」「문서와
코드를 같은 변경에서 고친다」를 더하고, 파생 서비스 안내에 머리 블록
충돌 가능성을 적었다.

버린 대안: H1 제목 아래에 블록을 두는 안은 보기에는 낫지만 빼는 규칙이
파일마다 달라져 원문 복원이 기계적이지 않다. 「종류」 칸을 따로 두는
안은 폴더와 같은 정보를 두 번 쓰게 한다.

위험·한계: 「확인 안 함」 설계서 38개, 계획서 51개는 지금 유효한지
아무도 판정하지 않았다. 요약은 제목·목표 줄을 보고 쓴 것이라 본문을
끝까지 읽지 않았다. 납품 패키지 셋의 MANIFEST.sha256는 이제 맞지 않는다
(납품 당시 바이트의 해시이고, 블록을 빼면 다시 맞는다). 리뷰 폴더에는
아직 머리 블록을 달지 않았다.

검증: 머리 블록을 뺀 내용과 HEAD 원본 246개 일치, check-work-docs.py
rc=0, --links docs·README.md·CLAUDE.md·AGENTS.md 깨진 링크 0.
2026-11-07 12:23:32 +09:00

4.2 KiB

결정 기록 본문은 결정한 때의 원문이다. 지금도 유효한지는 「상태」를, 지금 동작은 「현재 정본」을 읽는다.

  • 상태: 채택
  • 작성일: 2026-08-13
  • 요약: 인덱스와 스키마 변경은 관리 평면이 맡는다는 결정이다.
  • 현재 정본: docs/mongodb/schema-index-migration-guide.md

ADR-MONGO-004 — Index and schema changes belong to the admin plane

  • Status: Accepted
  • Date: 2026-08-13
  • Design source: design §21–§25, decisions D-11, D-13

Context

Spring Data can create indexes automatically from annotations. On a laptop this is convenient. On a collection with a hundred million documents, an index build is a capacity event: it consumes CPU, IO and memory on the primary for minutes to hours, and it starts because a pod restarted.

Worse, it starts N times when N pods restart, and there is no approval step, no ordering relative to the code that needs the index, and no record afterwards of what was created.

Schema validators have the same shape with a sharper edge: tightening a validator on a collection with existing data rejects writes to documents that were legal when they were written.

TTL has a third shape. It looks like a scheduler and is not one: the TTL monitor runs about once a minute and deletes in batches, so an expired document routinely remains readable for minutes or hours.

Decision

Indexes and validators are declared in a manifest and applied by the admin plane (D4). Automatic index creation in production is disabled.

  1. MongoManifestRegistry holds the declared indexes (MongoIndexManifest) and validator (MongoSchemaManifest) per collection. The manifest is the source of truth, reviewed in a pull request.
  2. MongoIndexDiffEngine compares manifest against observed state and reports missing, extra and changed indexes. Changed ones are reported rather than re-issued: MongoDB will not silently rebuild an index whose definition moved.
  3. MongoIndexApplyPolicy sets what an environment may do — APPLY (local), APPLY_WITH_DIFF (staging), DIFF_WITH_APPROVED_APPLY (production), REPORT_ONLY (audit).
  4. Ownership gates every drop. MongoMetadataOwnership distinguishes APPLICATION_MANAGED from SEARCH_MANAGED, ENCRYPTION_MANAGED and EXTERNAL. Only application-managed objects are droppable on drift. A diff engine without ownership eventually proposes dropping enxcol_.customers.esc, and "the drift tool cleaned it up" is a very bad incident summary.
  5. Retirement is staged. MongoIndexRetirementState moves an index declared → hidden → observed-unused → droppable, one deployment per transition. Hiding is instantly reversible; dropping is a rebuild.
  6. Stable validation actions are error and warn only. errorAndLog is not part of the Stable contract on 7.0 or 8.0 and is refused. Tightening goes warn+MODERATE → confirm zero warnings → error+STRICT, in two deployments.
  7. TTL is physical cleanup only (D-13). MongoExpirationAccessPolicy states the rule: a document's presence is not authorization and its absence is not a deadline. Access control checks the expiry field; scheduling uses a scheduler.
  8. Migrations are checksummed, locked, precondition-checked and resumable. MongoMigrationRunner fails hard when an applied id's checksum changed — two environments running different code under one id is worse than a failed deploy.

Consequences

Positive. Index builds are scheduled by people who know the capacity. Rollback is possible at every step. Drift is visible without being dangerous. Nothing drops what it does not own.

Negative. Adding an index is a manifest change plus an apply, not an annotation. Local development uses APPLY so the friction is confined to environments where it is warranted.

Rejected alternative — "auto-create with a feature flag." The flag is either on in production, which is the problem, or off, in which case the manifest is the real mechanism and the annotation is a second, divergent source of truth.