test(persistence-jpa): 계약 시험 정리의 TRUNCATE 잠금 대기에 상한을 둔다 #66
@@ -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"}
|
||||
|
||||
+92
-1
@@ -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.
|
||||
*
|
||||
* <p>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.
|
||||
*
|
||||
* <p>{@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<String> 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
|
||||
|
||||
Reference in New Issue
Block a user