Files
document-haness/docs/clean-architecture-backend-template/final/evidence/rendered/a05-f026-enqueue-race.svg
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

162 lines
12 KiB
XML

<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="1404" viewBox="0 0 1200 1404" role="img">
<title>terminal evidence</title>
<desc>Terminal-style rendering generated from retained command output. Sensitive-looking values are redacted in the visual asset.</desc>
<rect x="1" y="1" width="1198" height="1402" rx="14" fill="#0d1117" stroke="#30363d"/>
<rect x="1" y="1" width="1198" height="44" rx="14" fill="#161b22"/>
<rect x="1" y="30" width="1198" height="14" fill="#161b22"/>
<circle cx="24" cy="22" r="6" fill="#ff5f57"/>
<circle cx="44" cy="22" r="6" fill="#febc2e"/>
<circle cx="64" cy="22" r="6" fill="#28c840"/>
<text x="92" y="27" fill="#8b949e" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace">terminal evidence</text>
<text x="24" y="68" fill="#c9d1d9" font-size="15" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0">$ set -e
mkdir -p /tmp/probe
CT=recovery-race-probe
docker rm -f &quot;$CT&quot; &gt;/dev/null 2&gt;&amp;1 || true
docker run -d --name &quot;$CT</tspan><tspan x="24" dy="22">&quot; --network &quot;container:workmachine&quot; \
-e POSTGRES_PASSWORD=probe -e POSTGRES_USER=probe -e POSTGRES_DB=probe \
postg</tspan><tspan x="24" dy="22">res:16-alpine -p 55432 &gt;/dev/null
for i in $(seq 1 40); do
docker inspect -f &#x27;{{.State.Running}}&#x27; &quot;$CT&quot; | grep -q true</tspan><tspan x="24" dy="22"> || { echo &#x27;컨테이너가 뜨지 않았다&#x27;; exit 1; }
docker exec &quot;$CT&quot; pg_isready -U probe -p 55432 &gt;/dev/null 2&gt;&amp;1 &amp;&amp; break</tspan><tspan x="24" dy="22">
sleep 1
done
docker exec &quot;$CT&quot; psql -U probe -p 55432 -d probe -tAc &#x27;select version()&#x27; | cut -c1-24
M=adapter/outboun</tspan><tspan x="24" dy="22">d/persistence-jpa/src/main/resources/db/migration
for d in postgresql jpa/core jpa/fileserver; do
for f in $(ls &quot;$M/$d</tspan><tspan x="24" dy="22">&quot;/V*.sql | sort -V); do
docker exec -i &quot;$CT&quot; psql -U probe -p 55432 -d probe -q -v ON_ERROR_STOP=1 &lt; &quot;$f&quot; &gt;/dev/null</tspan><tspan x="24" dy="22"> 2&gt;&amp;1 || true
done
done
echo
echo &#x27;# 열린 항목이 없는 상태에서 두 연결을 장벽으로 맞춰 동시에 푼다. 여섯 번 반복.&#x27;
ec</tspan><tspan x="24" dy="22">ho &#x27;# 시계 출처만 DB 로 바꿨다. 조건과 열은 저장소 질의 그대로다.&#x27;
cat &gt; /tmp/probe/cp.sh &lt;&lt;&#x27;CPSH&#x27;
# 락파일의 한 구성</tspan><tspan x="24" dy="22">에 실린 좌표 전부를 캐시 경로로 바꾼다. Gradle 실행 없이 재현된다.
LOCK=${1:-adapter/outbound/persistence-jpa/gradle.loc</tspan><tspan x="24" dy="22">kfile}
CONF=${2:-postgresqlIntegrationTestRuntimeClasspath}
CACHE=/root/.gradle/caches/modules-2/files-2.1
cp=&quot;&quot;
while I</tspan><tspan x="24" dy="22">FS= read -r line; do
coord=${line%%=*}; confs=${line#*=}
case &quot;,$confs,&quot; in *&quot;,$CONF,&quot;*) ;; *) continue ;; esac
gr</tspan><tspan x="24" dy="22">oup=${coord%%:*}; rest=${coord#*:}; name=${rest%%:*}; ver=${rest##*:}
jar=$(find &quot;$CACHE/$group/$name/$ver&quot; -name &#x27;*.j</tspan><tspan x="24" dy="22">ar&#x27; ! -name &#x27;*sources*&#x27; ! -name &#x27;*javadoc*&#x27; 2&gt;/dev/null | head -1)
[ -n &quot;$jar&quot; ] &amp;&amp; cp=&quot;$cp:$jar&quot;
done &lt; &lt;(grep -E &#x27;^[</tspan><tspan x="24" dy="22">a-zA-Z0-9._-]+:[^=]+=&#x27; &quot;$LOCK&quot;)
echo &quot;${cp#:}&quot;
CPSH
cat &gt; /tmp/probe/RecoveryRaceProbe.java &lt;&lt;&#x27;JAVA&#x27;
import java.sql.Con</tspan><tspan x="24" dy="22">nection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.UUID;
imp</tspan><tspan x="24" dy="22">ort java.util.concurrent.CountDownLatch;
/** 두 호출자가 동시에 enqueue 를 부르는 상황을 그 구조 그대로 돌린다. */
publ</tspan><tspan x="24" dy="22">ic class RecoveryRaceProbe {
private static final String REFRESH =
&quot;update fs_recovery_item set reason_code = ?</tspan><tspan x="24" dy="22">, attempt = attempt + 1, updated_at = now()&quot;
+ &quot; where file_id = ? and status = &#x27;PENDING&#x27;&quot;;
private static </tspan><tspan x="24" dy="22">final String INSERT =
&quot;insert into fs_recovery_item (recovery_id, file_id, reason_code, status, attempt,&quot;
</tspan><tspan x="24" dy="22"> + &quot; created_at, updated_at) values (?, ?, ?, &#x27;PENDING&#x27;, 0, now(), now())&quot;;
public static void main(String[] args) t</tspan><tspan x="24" dy="22">hrows Exception {
int wins = 0;
int violations = 0;
int extraRows = 0;
for (int round = 0; round &lt; 6; ro</tspan><tspan x="24" dy="22">und++) {
runOnce(round);
}
}
private static void runOnce(int round) throws Exception {
String url = &quot;</tspan><tspan x="24" dy="22">jdbc:postgresql://127.0.0.1:55432/probe&quot;;
UUID file = UUID.randomUUID();
try (Connection setup = DriverManager.g</tspan><tspan x="24" dy="22">etConnection(url, &quot;probe&quot;, &quot;probe&quot;);
Statement s = setup.createStatement()) {
s.execute(&quot;delete from fs_re</tspan><tspan x="24" dy="22">covery_item&quot;);
s.execute(&quot;delete from fs_file&quot;);
s.execute(&quot;insert into fs_file (file_id, namespace, state, </tspan><tspan x="24" dy="22">original_name, created_at,&quot;
+ &quot; updated_at) values (&#x27;&quot; + file + &quot;&#x27;, &#x27;probe&#x27;, &#x27;CREATED&#x27;, &#x27;probe.txt&#x27;, now(), no</tspan><tspan x="24" dy="22">w())&quot;);
}
var started = new CountDownLatch(2);
var go = new CountDownLatch(1);
String[] result = new St</tspan><tspan x="24" dy="22">ring[2];
Runnable enqueue = () -&gt; {
int slot = Integer.parseInt(Thread.currentThread().getName());
try </tspan><tspan x="24" dy="22">(Connection db = DriverManager.getConnection(url, &quot;probe&quot;, &quot;probe&quot;)) {
db.setAutoCommit(false);
started.</tspan><tspan x="24" dy="22">countDown();
go.await();
int updated;
try (var refresh = db.prepareStatement(REFRESH)) {
</tspan><tspan x="24" dy="22"> refresh.setString(1, &quot;reason-&quot; + slot);
refresh.setObject(2, file);
updated = refresh.executeUpda</tspan><tspan x="24" dy="22">te();
}
if (updated == 0) {
try (var insert = db.prepareStatement(INSERT)) {
inser</tspan><tspan x="24" dy="22">t.setObject(1, UUID.randomUUID());
insert.setObject(2, file);
insert.setString(3, &quot;reason-&quot; + sl</tspan><tspan x="24" dy="22">ot);
insert.executeUpdate();
}
}
db.commit();
result[slot] = updated &gt; 0 ?</tspan><tspan x="24" dy="22"> &quot;갱신으로 흡수&quot; : &quot;삽입 성공&quot;;
} catch (Exception failure) {
result[slot] = failure.getClass().getSimpleN</tspan><tspan x="24" dy="22">ame() + &quot;: &quot;
+ String.valueOf(failure.getMessage()).split(&quot;\n&quot;)[0];
}
};
Thread a = new Threa</tspan><tspan x="24" dy="22">d(enqueue, &quot;0&quot;);
Thread b = new Thread(enqueue, &quot;1&quot;);
a.start();
b.start();
started.await();
go.coun</tspan><tspan x="24" dy="22">tDown();
a.join();
b.join();
int rows;
try (Connection db = DriverManager.getConnection(url, &quot;probe&quot;, &quot;</tspan><tspan x="24" dy="22">probe&quot;);
Statement s = db.createStatement();
ResultSet r = s.executeQuery(&quot;select count(*) from fs_recov</tspan><tspan x="24" dy="22">ery_item&quot;)) {
r.next();
rows = r.getInt(1);
}
String winner = result[0].startsWith(&quot;삽입&quot;) ? &quot;A&quot; : &quot;</tspan><tspan x="24" dy="22">B&quot;;
String loser = winner.equals(&quot;A&quot;) ? result[1] : result[0];
System.out.printf(&quot;%d 회차: 이긴 쪽 %s · 진 쪽 %</tspan><tspan x="24" dy="22">s · 남은 행 %d%n&quot;,
round + 1, winner, loser.replaceFirst(&quot;^PSQLException: ERROR: &quot;, &quot;&quot;), rows);
}
}
JAVA
CP=&quot;</tspan><tspan x="24" dy="22">$(bash /tmp/probe/cp.sh adapter/outbound/persistence-jpa/gradle.lockfile postgresqlIntegrationTestRuntimeClasspath)&quot;
jav</tspan><tspan x="24" dy="22">ac -encoding UTF-8 -nowarn -cp &quot;$CP&quot; -d /tmp/probe /tmp/probe/RecoveryRaceProbe.java
java -Dstdout.encoding=UTF-8 -cp &quot;$</tspan><tspan x="24" dy="22">CP:/tmp/probe&quot; RecoveryRaceProbe
docker rm -f &quot;$CT&quot; &gt;/dev/null 2&gt;&amp;1 || true</tspan></text>
<text x="24" y="1080" fill="#8b949e" font-size="13" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0">cwd: /shared/codebase/clean-architecture-backend-template/src</tspan></text>
<text x="24" y="1102" fill="#8b949e" font-size="13" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0">time: 2026-09-02T05:03:15+00:00 · exit 0</tspan></text>
<line x1="24" y1="1116" x2="1176" y2="1116" stroke="#30363d"/>
<text x="24" y="1156" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0">PostgreSQL 16.15 on x86_</tspan></text>
<text x="24" y="1178" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0"></tspan></text>
<text x="24" y="1200" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0"># 열린 항목이 없는 상태에서 두 연결을 장벽으로 맞춰 동시에 푼다. 여섯 번 반복.</tspan></text>
<text x="24" y="1222" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0"># 시계 출처만 DB 로 바꿨다. 조건과 열은 저장소 질의 그대로다.</tspan></text>
<text x="24" y="1244" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0">1 회차: 이긴 쪽 B · 진 쪽 duplicate key value violates unique constraint &quot;uq_fs_recovery_open&quot; · 남은 행 1</tspan></text>
<text x="24" y="1266" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0">2 회차: 이긴 쪽 B · 진 쪽 duplicate key value violates unique constraint &quot;uq_fs_recovery_open&quot; · 남은 행 1</tspan></text>
<text x="24" y="1288" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0">3 회차: 이긴 쪽 A · 진 쪽 duplicate key value violates unique constraint &quot;uq_fs_recovery_open&quot; · 남은 행 1</tspan></text>
<text x="24" y="1310" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0">4 회차: 이긴 쪽 A · 진 쪽 duplicate key value violates unique constraint &quot;uq_fs_recovery_open&quot; · 남은 행 1</tspan></text>
<text x="24" y="1332" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0">5 회차: 이긴 쪽 B · 진 쪽 duplicate key value violates unique constraint &quot;uq_fs_recovery_open&quot; · 남은 행 1</tspan></text>
<text x="24" y="1354" fill="#e6edf3" font-size="14" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" xml:space="preserve"><tspan x="24" dy="0">6 회차: 이긴 쪽 A · 진 쪽 duplicate key value violates unique constraint &quot;uq_fs_recovery_open&quot; · 남은 행 1</tspan></text>
</svg>