From b1b4380be2f017b101072c4d0a409e04fba8b439 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Sat, 21 Nov 2026 00:12:13 +0900 Subject: [PATCH 1/2] =?UTF-8?q?test(persistence-jpa):=20=EA=B3=84=EC=95=BD?= =?UTF-8?q?=20=EC=8B=9C=ED=97=98=20=EC=A0=95=EB=A6=AC=EC=9D=98=20TRUNCATE?= =?UTF-8?q?=20=EC=9E=A0=EA=B8=88=20=EB=8C=80=EA=B8=B0=EC=97=90=20=EC=83=81?= =?UTF-8?q?=ED=95=9C=EC=9D=84=20=EB=91=94=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JpaDurableOperationStoreContractTest의 @BeforeEach는 풀 연결로 TRUNCATE durable_operation을 lock_timeout 없이 돈다(서버 기본값 0). 앞 시험이 그 표를 잠근 트랜잭션을 남기면 TRUNCATE가 holder가 끝날 때까지 기다리고, 그 기다림에는 자기 상한이 없다. 지금은 worker 트랜잭션이 코드의 대기 상한 안에서 끝나 실제로 오래 걸리지 않을 뿐이다. 정리를 트랜잭션 하나로 돌리고 TRUNCATE 앞에 SET LOCAL lock_timeout = '2s'를 둔다. 55P03이면 rollback 뒤 pg_locks·pg_stat_activity로 그 표를 잠근 다른 세션(pid, mode, held/queued, state, 열린 초, 마지막 문장)을 적어 IllegalStateException으로 실패한다. 2초는 autovacuum이 막을 때 PostgreSQL이 그것을 취소하는 deadlock_timeout 1초의 두 배이고, 진행 중인 commit은 ms 안에 끝난다. SET LOCAL은 같은 풀을 쓰는 adapter가 이 상한을 물려받지 않게 한다. 세션 SET은 버렸다(아래 변이). rollback이나 진단 조회가 실패하면 원래 예외에 suppressed로 붙인다. 연결이 끊기면 Hikari가 rollback에서 "Connection is closed"를 던져 원래 예외를 덮기 때문이다(리뷰 발견). 위험·한계: 남은 holder가 있으면 뒤 시험들이 2초씩 기다리다 실패한다. 고치기 전처럼 조용히 기다리는 대신 holder를 적고 실패하는 쪽을 골랐다. 이 정리를 지키는 영구 시험은 두지 않았다. 표를 일부러 잠그는 시험은 실패하면 그 자체가 남는 holder가 된다. 대신 커밋하지 않는 탐침 둘로 보였다. 같은 모양의 무한 대기 TRUNCATE가 다른 통합 시험 8곳에 남는다 (범위 밖, 넘김). 검증(desktop, 버릴 worktree, jpaPlatformContractTest --rerun --no-build-cache, 탐침 L = claim의 잠금을 쥔 트랜잭션이 있을 때 정리, K = 정리의 backend를 기다리는 중에 끊음): - main f9318660(트리 f366d372): L FAIL 40,004ms 예외 없음(holder가 40초 뒤 놓을 때까지 대기, 트랜잭션 30초 제한보다 김), K pass - 첫 수정(트리 7a7d307e): L pass 2,010ms, K FAIL "Connection is closed"(원래 예외 없음, suppressed 없음) - 이 커밋(트리 d6767673) 2회: L pass 2,010·2,009ms, 메시지에 "pid 62 RowExclusiveLock held, idle in transaction for 2 s", K pass(원래 57P01 FATAL + suppressed "Connection is closed"), 두 번 모두 풀 연결 넷의 lock_timeout [0, 0, 0, 0] - 변이 SET LOCAL → SET: L FAIL, 풀 lock_timeout [2s, 2s, 0, 0] - lane 필터 없이: rc=0, 61 클래스 455 tests, 실패·skip 0, FROM-CACHE 0 - 이 커밋의 트리는 d6767673에 spotless 형식(줄바꿈 둘)만 더한 것이다 Refs: be-test-speed (4), PR #64 리뷰가 넘긴 항목 --- .../JpaDurableOperationStoreContractTest.java | 93 ++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-) diff --git a/src/adapter/outbound/persistence-jpa/src/postgresqlIntegrationTest/java/dev/caskeleton/adapter/outbound/persistence/operation/JpaDurableOperationStoreContractTest.java b/src/adapter/outbound/persistence-jpa/src/postgresqlIntegrationTest/java/dev/caskeleton/adapter/outbound/persistence/operation/JpaDurableOperationStoreContractTest.java index 93ca166f..11b16b5c 100644 --- a/src/adapter/outbound/persistence-jpa/src/postgresqlIntegrationTest/java/dev/caskeleton/adapter/outbound/persistence/operation/JpaDurableOperationStoreContractTest.java +++ b/src/adapter/outbound/persistence-jpa/src/postgresqlIntegrationTest/java/dev/caskeleton/adapter/outbound/persistence/operation/JpaDurableOperationStoreContractTest.java @@ -17,10 +17,12 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.sql.Connection; +import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.time.Duration; import java.time.Instant; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.CountDownLatch; @@ -74,6 +76,18 @@ class JpaDurableOperationStoreContractTest extends DurableOperationStoreContract /** Longer than worker-b may queue and inside the transaction timeout, so worker-a commits. */ private static final Duration WORKER_A_HOLDS_AT_MOST = WORKER_B_QUEUES_AT_MOST.multipliedBy(2); + /** + * How long the cleanup's TRUNCATE may wait for a lock on the table before it fails. + * + *

Twice the 1 s {@code deadlock_timeout} after which PostgreSQL cancels an autovacuum that + * blocks the TRUNCATE, and a commit still in flight ends in milliseconds: a lock held longer is a + * transaction a test left open, which an unbounded TRUNCATE would wait for for good. + */ + private static final String CLEANUP_LOCK_TIMEOUT = "2s"; + + /** PostgreSQL's SQLSTATE for a lock wait that ran out its {@code lock_timeout}. */ + private static final String LOCK_NOT_AVAILABLE = "55P03"; + private static JpaPlatformContractSupport support; private static AnnotationConfigApplicationContext context; @@ -98,9 +112,86 @@ class JpaDurableOperationStoreContractTest extends DurableOperationStoreContract } } + /** + * Empties the table, or fails naming the session whose lock on it stopped the TRUNCATE. + * + *

{@code SET LOCAL} ends with this transaction: the connection goes back to the pool the + * adapter under test borrows from, and the adapter must not inherit the cleanup's bound. The pool + * restores autocommit when the connection goes back. + */ @BeforeEach void empty() throws SQLException { - execute("TRUNCATE durable_operation"); + try (Connection connection = support.connection(); + Statement statement = connection.createStatement()) { + connection.setAutoCommit(false); + try { + statement.execute("SET LOCAL lock_timeout = '" + CLEANUP_LOCK_TIMEOUT + "'"); + statement.execute("TRUNCATE durable_operation"); + connection.commit(); + } catch (SQLException failure) { + // A broken connection fails the rollback too; that must not replace the original failure. + try { + connection.rollback(); + } catch (SQLException rollbackFailure) { + failure.addSuppressed(rollbackFailure); + throw failure; + } + if (!LOCK_NOT_AVAILABLE.equals(failure.getSQLState())) { + throw failure; + } + String holders; + try { + holders = lockHolders(statement); + } catch (SQLException lookFailure) { + failure.addSuppressed(lookFailure); + holders = "unknown, the lookup failed (suppressed below)"; + } + throw new IllegalStateException( + "the cleanup's TRUNCATE durable_operation gave up after waiting " + + CLEANUP_LOCK_TIMEOUT + + " for a lock on the table. Sessions locking it: " + + holders, + failure); + } + } + } + + /** Every other session's lock on the table, held or queued, and what it last ran. */ + private static String lockHolders(Statement statement) throws SQLException { + List holders = new ArrayList<>(); + try (ResultSet rows = + statement.executeQuery( + """ + SELECT l.pid, l.mode, l.granted, a.state, + extract(epoch FROM now() - a.xact_start)::int AS open_seconds, + left(a.query, 160) AS last_statement + FROM pg_locks l + JOIN pg_stat_activity a ON a.pid = l.pid + WHERE l.locktype = 'relation' + AND l.database = (SELECT oid FROM pg_database WHERE datname = current_database()) + AND l.relation = 'durable_operation'::regclass + AND l.pid <> pg_backend_pid() + ORDER BY l.pid, l.mode + """)) { + while (rows.next()) { + String lock = + "pid " + + rows.getInt("pid") + + " " + + rows.getString("mode") + + (rows.getBoolean("granted") ? " held" : " queued") + + ", " + + rows.getString("state"); + int openSeconds = rows.getInt("open_seconds"); + // No transaction start: the holder ended between reading pg_locks and pg_stat_activity. + String open = + rows.wasNull() ? ", no transaction open any more" : " for " + openSeconds + " s"; + holders.add(lock + open + ", last statement: " + rows.getString("last_statement")); + } + } + return holders.isEmpty() + ? "none any more; the holder ended between the timeout and this look" + : String.join("; ", holders); } @Test -- 2.54.0 From d1a1c68390534b76c1c1e4f94c2a3717b21d5b9e Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Sat, 21 Nov 2026 00:12:13 +0900 Subject: [PATCH 2/2] =?UTF-8?q?docs(ledger):=20be-test-speed=EB=A5=BC=20do?= =?UTF-8?q?ne=EC=9C=BC=EB=A1=9C=20=EB=8B=AB=EB=8A=94=20=EC=8B=A4=EC=B8=A1?= =?UTF-8?q?=EC=9D=84=20=EB=8D=94=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 앞 actual 줄(33f5c0e0)은 (4) JPA 정리 TRUNCATE가 남아 result partial이었다. 그 일을 끝냈으므로 같은 꼴의 actual 줄을 하나 더하고 result를 done으로 둔다. 앞 줄은 고치지 않는다. 세션 열 transcript의 기록 합(2026-11-21 00:04까지): 1067분, 작업 중 326분, 호출 1072, 출력 1,048,131. p80(187분·297호출·203K) 셋 다 위라 within은 over다. 넘친 이유는 why 칸에 적었다. 검증: scripts/verify.sh docs(노트북) --- docs/ledger/estimates.jsonl | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/ledger/estimates.jsonl b/docs/ledger/estimates.jsonl index 9d291c90..e7d2b5b8 100644 --- a/docs/ledger/estimates.jsonl +++ b/docs/ledger/estimates.jsonl @@ -24,3 +24,4 @@ {"schema": 1, "kind": "actual", "task": "be-ci-next", "transcript": "7f6aac72-543c-4f2a-a47c-550e4c727f99,5ef6a5a6-043b-4872-b8bf-0cc4ce2aee1f,0f7cd6ee-31dc-47e0-b33f-6900d1138d00,2d8f74db-59db-4b0f-970f-202c4a5fc46c,b669ba0e-0219-4098-a956-8479e8a74007,00277f8c-7b41-4984-ab25-6dd8d96e0786,a84946d1-7a15-491a-90fd-a8c21280ef0b", "minutes": 1139, "active_minutes": 485, "calls": 1652, "output_tokens": 1611695, "cache_read_tokens": 329186023, "max_context": 497013, "within": "over", "result": "done", "commits": ["fcd2edf4", "a0166b16", "2cfe2266", "9b76a3b4", "e9ee917f", "72268f30", "7c052142", "58d24346", "946f09bf", "5d9e7372", "3917dc01", "11c63825", "design-docs:45a1c2d", "design-docs:e535319"], "why": "세 값 모두 p80 위(작업 중 485분/254, 호출 1652/470, 출력 1.61M/348K). 예측은 PR 셋이었는데 총괄이 BE-5·BE-6+8과 리뷰가 찾은 고침 둘(#60·#61)을 더해 백엔드 PR 여덟·design-docs PR 둘이 됐다. context 250K 규칙으로 세션 일곱에 나눠 했고, 세션마다 노트·brief를 다시 읽었다. desktop은 runner·다른 세션과 잠금을 나눠 탐침·verify마다 기다렸다. BE-4 탐침의 dead store는 exclude-test.xml(이름 unused)과 Error Prone UnusedVariable 때문에 SpotBugs까지 가지 않아 세 번 고쳐 돌렸다. 다음 예측은 PR 수가 아니라 총괄이 더할 수 있는 고침 몫과 세션 인계 수를 근거로 쓴다. 실측은 2026-11-20 17:28까지 세션 일곱의 기록 합(max_context는 가장 큰 세션)", "recorded_at": "2026-11-20T17:29+09:00"} {"schema": 1, "kind": "actual", "task": "laptop-runner", "transcript": "27674009-98d8-4e0c-8946-fb1e590c4128", "minutes": 115, "active_minutes": 98, "calls": 220, "output_tokens": 329320, "within": "p50", "result": "done", "commits": ["b932d49b7", "1b9fbeb8a", "162c37c9f", "a1b6edccd"], "why": "시간·호출은 p50 안. 출력은 p80(290K) 위: H5로 설치를 묶음+install.sh로 다시 짰고, 리뷰 2라운드와 PR 뒤 도착한 총괄 답 넷(stop 시험·즉시 판단·incident·install 조건)을 반영했다", "recorded_at": "2026-11-20T17:29+09:00"} {"schema": 1, "kind": "actual", "task": "be-test-speed", "transcript": "46edb129-6c98-443f-b613-4c03a1995124,be35f975-1717-424b-be6e-d61f27431e20,fbf3edef-7c37-4d0d-831f-5e1869ec290c,2cac7b38-fb8e-4c7f-a664-f2b68025fc9b,c1a67390-a2f1-47a2-abf2-b69c1bddc72f,80b376f3-2368-4ed9-b993-334654d8e345,494a6187-4199-47db-a496-45f89ed5a586,6758746a-5e95-4999-9266-db165c5ece4c,b12d8138-aca2-4be2-8e15-bb4db5f431e2", "minutes": 992, "active_minutes": 277, "calls": 945, "output_tokens": 928115, "cache_read_tokens": 161892768, "max_context": 378335, "within": "over", "result": "partial", "commits": ["e9a57f95", "7de08bc3", "8259d0ca", "4db443e7", "120093a0", "e5558f25", "142b5265", "2f863c33", "40a10def", "30037329", "791bf1a9", "b9b3f107"], "why": "세 값 모두 p80 위(작업 중 277분/187, 호출 945/297, 출력 0.93M/203K). 예측은 PR 둘(BE-9·BE-10)이었는데 JPA claim 대기(#64)와 grpc 넘김 PR이 더해져 넷이 됐다. 리뷰가 넘긴 고침도 더해졌다(lease fencing, grpc 넘김의 다섯과 그 확인 리뷰의 셋). context 규칙으로 세션 아홉에 나눠 했고 세션마다 인계를 다시 읽었다. desktop 잠금을 다른 세션과 나눠 탐침·verify마다 기다렸다(RED 묶음은 다른 세션의 verify.sh merge 뒤로 11분). 다음 예측은 PR 수가 아니라 리뷰가 넘길 고침 몫과 세션 인계 수를 근거로 쓴다. 결과는 partial: (4) JPA TRUNCATE는 (3) grpc PR 병합 뒤에 하므로 이 줄에 없고, 끝나면 actual 줄을 하나 더한다. 실측은 2026-11-20 22:48까지 세션 아홉의 기록 합(max_context는 가장 큰 세션)", "recorded_at": "2026-11-20T22:48+09:00"} +{"schema": 1, "kind": "actual", "task": "be-test-speed", "transcript": "46edb129-6c98-443f-b613-4c03a1995124,be35f975-1717-424b-be6e-d61f27431e20,fbf3edef-7c37-4d0d-831f-5e1869ec290c,2cac7b38-fb8e-4c7f-a664-f2b68025fc9b,c1a67390-a2f1-47a2-abf2-b69c1bddc72f,80b376f3-2368-4ed9-b993-334654d8e345,494a6187-4199-47db-a496-45f89ed5a586,6758746a-5e95-4999-9266-db165c5ece4c,b12d8138-aca2-4be2-8e15-bb4db5f431e2,bf0b17ec-3561-45a1-be2f-98e80481cb7c", "minutes": 1067, "active_minutes": 326, "calls": 1072, "output_tokens": 1048131, "cache_read_tokens": 180482142, "max_context": 378335, "within": "over", "result": "done", "commits": ["e9a57f95", "7de08bc3", "8259d0ca", "4db443e7", "120093a0", "e5558f25", "142b5265", "2f863c33", "40a10def", "30037329", "791bf1a9", "b9b3f107", "2f42d4fb"], "why": "세 값 모두 p80 위(작업 중 326분/187, 호출 1072/297, 출력 1.05M/203K). 앞 줄(partial, 22:48까지)에 (4) JPA 정리 TRUNCATE PR 하나를 더한 합이다. (4)는 크기 작음, 세션 하나(작업 중 20분, 호출 75)로 끝났다. 그 안에서 리뷰 발견 하나(정리가 실패하면 원래 예외가 가려짐)가 탐침 하나와 desktop 재실행을 더했고, desktop 잠금은 다른 세션의 verify.sh merge 뒤로 약 10분 기다렸다. 넘친 이유는 앞 줄과 같다: 예측은 PR 둘이었는데 리뷰가 넘긴 고침이 PR 셋을 더했다. 결과는 done: (1)~(4)를 모두 끝냈다. 실측은 2026-11-21 00:04까지 세션 열의 기록 합(max_context는 가장 큰 세션)", "recorded_at": "2026-11-21T00:05+09:00"} -- 2.54.0