Files
document-haness/docs/clean-architecture-backend-template/tech-log-studio/state-ownership-and-concurrency/case/case-complete-drain-rolls-back-a-rotation.md
T
DongHyeonkaandClaude Opus 5 b2963105a8 docs(keycloak-session-store): import the session-storage lab as a new project
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>
2026-09-04 22:51:59 +09:00

108 lines
5.4 KiB
Markdown

---
kind: CASE
slug: complete-drain-rolls-back-a-rotation
title: 배수 완료가 자기가 읽은 값으로 상태를 다시 써서 진행 중인 자격증명 회전을 되돌린다
topic: state-ownership-and-concurrency
project: clean-architecture-backend-template
status: 게시 전
sourceRevision: 21234e38cdb9a926cbc92bb97a2aee2e4a7d2916
rootTreeNode: case:complete-drain-rolls-back-a-rotation
evidenceCapturedOn: 2026-09-01
body: case-complete-drain-rolls-back-a-rotation.body.md
assets:
- key: complete-drain-rolls-back-a-rotation
file: ../../../final/evidence/rendered/complete-drain-rolls-back-a-rotation.svg
evidence:
- ../../../final/evidence/raw/complete-drain-rolls-back-a-rotation.txt
source:
- 원본 분석 절은 analysis/grpc/grpc-policy.md#L158 이다.
---
# 배수 완료가 자기가 읽은 값으로 상태를 다시 써서 진행 중인 자격증명 회전을 되돌린다
회전 관리자가 원자 참조를 들고 있으면서 두 메서드 모두 읽고 나서 조건 없이 쓴다. 배수 완료가 자기가 읽은 현재 세대로 새 상태를 만들기 때문에, 그 사이에 일어난 회전이 지워지고 이전 세대가 다시 현재가 된다.
## 관계
- **Atomic 타입의 존재는 원자성의 증거가 아니다**
이 사례가 그 규칙의 형태다.
- **배정 식별자 때문에 insert-first 청구가 UPSERT가 되어 커밋된 결과를 덮었다**
같은 통독에서 나온 같은 계열의 사례다.
- **재시도 안전은 증거로 결정된다**
같은 가족이 원자성을 제대로 다룬 정본이 그 옆에 있다.
## 문제
자격증명 회전 관리자의 자바독이 존재 이유를 적는다.
자재를 제자리에서 바꾸는 것이 이 클래스가 피하려는 실패를 만든다는 것이다. 교체 시점에 진행 중이던 모든 호출이 인증 오류로 실패하고, 그 오류는 클라이언트에서 보면 애초에 유효하지 않았던 자격증명과 똑같아 보인다는 것이다.
그래서 준비하고 교체하고 배수하는 순서를 지킨다.
상태는 원자 참조 하나에 담긴다. 현재 세대와 배수 중 세대와 배수 마감을 묶은 값이다.
## 결론
두 메서드 모두 원자적이지 않다.
회전은 현재 상태를 읽고, 승계 여부를 판정하고, 새 상태를 조건 없이 쓴다.
배수 완료는 현재 상태를 읽고, 자기가 읽은 현재 세대로 새 상태를 만들어 조건 없이 쓴다.
두 결과가 다르다.
회전 경합에서는 두 회전이 같은 값을 읽고 둘 다 승계 검사를 통과할 수 있다. 나중 쓰기가 앞의 것을 덮고, 덮인 회전이 배수 대상으로 기록해 둔 세대가 상태에서 사라진다. 그 세대 위의 호출은 아무도 배수하지 않는다.
자바독이 이 상황을 이미 안다. 승계 검사의 존재 이유로 회전이 뒤로 가는 흔한 원인이 두 회전자의 경합이라고 적는다. 검사는 있고 원자성이 없다.
배수 완료의 되돌림이 더 무겁다.
읽기와 쓰기 사이에 회전이 일어나면, 그 회전이 활성화한 세대가 지워지고 이전 세대가 다시 현재가 된다.
방금 교체된 자격 자재가 되살아난다. 이 클래스의 존재 이유가 그 교체다.
같은 가족 안에 정본이 있다. 재시도 예산과 헤징 예산이 정확한 비교 후 교체 루프를 쓰고, 수요 제어기는 같은 형태를 동기화로 닫는다.
그리고 같은 형태가 옆 리프에도 있다. 채널 런타임 레지스트리의 회전이 같은 파일의 설치가 비교 후 교체를 쓰는데도 조건 없이 덮는다.
## 검증 환경
OpenJDK : 21.0.12
확인 방식 : 두 메서드의 읽기와 쓰기 사이 원자성 분석, 같은 가족의 정본 대조
소스 수정 : x
## 재현 조건
원문은 document-detail 의 analysis/grpc/grpc-policy.md 와 analysis/grpc/grpc-client.md 에 있다.
1. 회전 관리자의 상태 필드 타입을 확인한다.
2. 회전 메서드에서 읽기와 쓰기 사이에 조건이 있는지 본다.
3. 배수 완료 메서드가 새 상태를 무엇으로 만드는지 읽는다.
4. 자바독의 경합 서술을 읽는다.
5. 같은 가족의 예산 클래스들과 비교한다.
## 본문
<!-- body:start -->
`AtomicReference` 를 들고 있으면서 `rotate``completeDrain` 이 모두 `get()` 후 조건 없는 `set()` 을 한다.
## 두 메서드가 같은 참조를 다루는 방식
:::evidence key="complete-drain-rolls-back-a-rotation" alt="분석 문서 analysis/grpc/grpc-policy.md 에서 이 기록의 근거 절을 그대로 잘라낸 15줄. 코드베이스를 측정한 것이 아니라 원본 판정이 무엇을 적었는지를 보여 준다." caption="analysis/grpc/grpc-policy.md 발췌 — 15줄" zoom="true"
:::
## 두 경합의 결과가 다르다
회전 경합에서는 덮인 세대가 배수 목록에 오르지 못한다. 배수 완료에서는 자기가 읽은 `observed.current()` 로 새 상태를 만들기 때문에 그 사이에 일어난 회전이 지워지고 이전 세대가 다시 현재가 된다.
## 클래스의 목적이 뒤집힌다
자격 자재를 떨어뜨리지 않고 교체하려고 만든 클래스가 교체 자체를 되돌린다. 같은 파일의 형제(`install`)와 같은 가족의 `GrpcRetryBudget` 이 비교 후 교체를 정확히 쓴다.
## 확인하지 못한 것
동시 회전과 동시 배수 완료를 실행으로 재현하지 않았다. 두 리프 모두 배선 경로가 없다.
<!-- body:end -->