Files
document-haness/docs/clean-architecture-backend-template/tech-log-studio/state-machines-and-ownership/concept/concept-messaging-transport-spi-c03.md
T
DongHyeonkaandClaude Fable 5.1 b25357c48a docs(clean-architecture-backend-template): fold analysis into final and re-select one topic
- analysis/·source-index·state.json 을 final/document.md 제2부·제3부로 접었다. SSOT 는 하나다
- 파일럿 — commit-ambiguity-as-a-result 를 새 기준으로 재선별. 후보 14 → 글감 5
  (PROMOTE 5 · MERGE_INTO 3 · KEEP_IN_SSOT 4 · 보류 2). 기록 5건을 다시 썼고 그림 1개를
  techviz 로 만들었다
- 재선별이 잡은 것: 제1부 §6.2·§11.1 이 자기 §13.2 와 어긋나 있었다(레인을 안 돌렸다 vs
  돌렸다) — 정정. 이미 답이 나와 있던 Question 을 HEAD 재실행 질문으로 다시 세웠다.
  Concept 이 인용한 코드가 SSOT 에 없어 뺐다
- candidateScope·sourceRepository 기록. 나머지 43개 주제는 재선별 대기(PENDING 905)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-07 12:39:20 +09:00

67 lines
3.9 KiB
Markdown

---
kind: CONCEPT
slug: messaging-transport-spi-c03
title: 회전은 변경이 아니라 교체다
topic: state-machines-and-ownership
project: clean-architecture-backend-template
status: 게시 전
sourceRevision: 21234e38cdb9a926cbc92bb97a2aee2e4a7d2916
rootTreeNode: concept:messaging-transport-spi-c03
evidenceCapturedOn: 2026-09-01
assets:
- key: messaging-transport-spi-c03
file: ../../../final/evidence/rendered/messaging-transport-spi-c03.svg
- key: messaging-transport-spi-c03-diagram
file: ../../../final/assets/diagrams/messaging-transport-spi-c03.svg
evidence:
- ../../../final/evidence/raw/messaging-transport-spi-c03.txt
source:
- 원본 분석 절은 final/document.md#a19-messaging-transport-spi#L124 이다.
module: messaging-transport-spi
---
# 회전은 변경이 아니라 교체다
자격증명 회전과 토폴로지 재적재는 살아 있는 세대를 바꾸지 않고 통째로 교체한다. 진행 중인 발행은 시작한 세대를 유지한다.
## 관계
- **멱등 종료를 보장하는 컴포넌트는 종료 이후의 등록도 정의한다**
같은 분석 리프에서 끌어낸 규칙이다.
- **같은 개념의 sentinel은 계층을 넘어 하나로 정한다**
같은 분석 리프에서 끌어낸 규칙이다.
## 본문
<!-- body:start -->
세대 모델의 근거가 javadoc에 있다.
> "Credential rotation and topology reload replace a whole generation rather than mutating a live one. In-flight publishes keep the generation they started on, which is what makes a rotation invisible to callers instead of a burst of authentication failures."
## 회전이 교체인 순서
:::evidence key="messaging-transport-spi-c03-diagram" alt="새 세대 설치와 옛 세대 은퇴와 lease 반환 대기와 정확히 한 번 close 가 왼쪽에서 오른쪽으로 이어지는 구조" caption="회전이 교체인 순서" zoom="false"
:::
`ConcurrentHashMap.put`이 원자적이므로 호출자는 옛 세대 또는 새 세대만 본다 — javadoc: "never a half-rebuilt connection pool". `computeIfPresent`의 리맵 함수가 **버킷 잠금 안에서** 실행되므로, 조회와 증가가 원자적이다. `get` 후 증가였다면 그 사이에 `install`이 세대를 교체해 이미 은퇴한 세대의 계수를 올릴 수 있다.
## ConcurrentHashMap 참조 위치
:::evidence key="messaging-transport-spi-c03" alt="코드베이스에서 ConcurrentHashMap 를 검색한 출력 2줄. 이 기록이 세는 참조가 그 출력에 그대로 보인다." caption="ConcurrentHashMap 코드베이스 검색 — 2줄 · exit 0" zoom="true"
:::
## 두 층의 멱등성
`closed`가 CAS로 보호되므로 **정확히 한 번만** `runtime.close()`가 불린다. 테스트가 그것을 직접 단언한다(`aRetiredGenerationIsClosedExactlyOnce`, `as("a second close on a real connection pool throws from a shutdown hook")`). `Lease.close()`도 자체 `AtomicBoolean released`로 멱등이다.
## 고쳐진 세 결함
**세대별 은퇴 시각** — 하나의 타임스탬프를 전체 목록에 적용하면 회전이 겹칠 때 판정이 호출자가 우연히 넘긴 값에 좌우된다. **닫힌 세대의 목록 제거**`drainingCount()`가 관측 지표이므로, 이미 닫힌 세대가 목록에 남으면 지표가 영원히 0으로 안 떨어진다. **`close()`가 현재 세대까지 닫는다** — 회전 없이 종료하는 프로세스(=대부분의 프로세스)가 연결을 정리하지 않았다.
## 남은 미세 결함과 이중 검사
`close()``draining``synchronized`로 비우지만 `current``List.copyOf(current.keySet())` 후 하나씩 `remove`한다. 그 사이에 `install`이 새 세대를 넣으면 그 세대는 닫히지 않는다. 종료 중 설치는 정상 시나리오가 아니므로 실질 위험은 낮다 — §17의 P3. `tryBeginWork`는 **이중 검사**다 — 증가 후 다시 확인해서 증가와 `beginDrain` 사이의 경합에서 계수를 되돌린다.
<!-- body:end -->