fix: 3차 확인 리뷰의 Minor 19건을 고친다

문제: 3차 수정의 확인 리뷰가 새 Important 없이 Minor 19건을 남겼다.
동작에 닿는 것이 셋이다. JDK read-idle watchdog이 공용 ForkJoinPool에서
돌아 그 풀이 바쁘면 300ms timeout이 6초 가까이 늦었다. 붙여 쓴
-x<task>를 verifyStrictLaneStages가 읽지 않아 lane을 뺀 workflow가
통과했다. 사용자 전송이 중간 클래스를 거쳐 @SystemCaller bean을 부르면
ArchUnit 규칙을 지났다. 잠금 대기 검사기는 FK·trigger·REINDEX와
lock_timeout = 0을 못 봤고, 쿼터 보정 SQL은 코드와 다른 모양의 행을
넣었다.

방법: 영역별 4묶음이 맡은 Minor만 test-driven-development 절차로
고쳤다(재리뷰 README 12절).
- watchdog은 전용 데몬 스레드 하나에서 돌고 스트림을 닫으면 작업을
  취소한다. read당 비용은 그대로다(21–24ns).
- 사용자 전송 → @SystemCaller는 직접·간접 의존 모두 거부한다. 리뷰가
  권한 직접 의존 검사는 중간 클래스 하나로 다시 열려서 버렸다.
- 검사기를 보강하면서 새로 걸린 이미 배포된 마이그레이션 5개는 내용을
  바꾸지 않고 동결 목록에 더했다(main과 blob이 같다).
- 비밀 목록 bean은 규칙보다 먼저 만들어 실제 클래스로 검사한다.

위험·한계: 회복 필요 예외 메시지 끝에 scope digest가 붙고 기동 실패
문구가 바뀌어, 문구 전체에 맞추던 로그 매처는 고쳐야 한다. 코드가 든
Redis 계정 참조의 fixture- 검사는 문서로만 막았다(코드로 막으려면 새
의존 edge가 필요하다). failure-retention ≥ replay-ttl 기동 검사는 넣지
않았다. -mx 같은 짧은 플래그 묶음과 graphql 전송 fixture는 남았다.
spotbugsTestFixtures(게이트 밖)의 정규식 경고가 15건으로 늘었다.

검증: ci, 두 빌드의 verifyStrictLaneStages --dry-run, mainCheck,
:integrationCheck, -p optional-platforms ci integrationCheck
performanceCheck, :performanceCheck, :releaseCheck(-PgitRevision),
verify-compose-profile-contracts(18 lane) 첫 실행 통과. watchdog은
공용 풀을 채운 상태에서 300ms 설정이 300ms에 끝나는 것을 쟀다.

Refs: docs/reviews/2026-11-03-rereview/README.md 11·12절, round3/
This commit is contained in:
DongHyeonka
2026-11-04 03:00:21 +09:00
parent 8edac6abb1
commit ac42bc7293
2 changed files with 61 additions and 22 deletions
@@ -3,6 +3,7 @@ package dev.caskeleton.grpc.ledger;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -13,9 +14,10 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.postgresql.ds.PGSimpleDataSource;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
@@ -31,6 +33,13 @@ import org.testcontainers.postgresql.PostgreSQLContainer;
* Flyway runs it, in one transaction. Unbounded it waits until the writer leaves, with every claim
* queued behind it, and then applies; bounded it fails with {@code lock_not_available} first and
* its rollback leaves the ledger as it was.
*
* <p>Every migration after V001 is held to this, read from the tree itself ({@link
* GrpcOperationLedgerMigrations#inOrder()}), so a V004 is checked without anyone naming it here.
* This is the ledger tree's lock-wait rule: the optional build cannot reach the persistence-jpa
* testkit whose text check the other trees run, and a copy of that check would drift (re-review
* 2026-11-03 round 3, RR3-02-04). A later migration that does not touch the ledger at all fails
* here too, on purpose: say so in this test rather than let the rule pass it unseen.
*/
@Testcontainers(disabledWithoutDocker = true)
class GrpcOperationLedgerMigrationLockWaitIT {
@@ -47,12 +56,13 @@ class GrpcOperationLedgerMigrationLockWaitIT {
.withUsername("grpc")
.withPassword("grpc");
/** Every ledger migration after V001, the one that creates the ledger. */
static Stream<String> migrationsAfterTheFirst() throws IOException {
return GrpcOperationLedgerMigrations.inOrder().stream().skip(1);
}
@ParameterizedTest
@ValueSource(
strings = {
"V002__index_grpc_operation_ledger_finished_rows.sql",
"V003__add_grpc_operation_ledger_claim_attempt.sql"
})
@MethodSource("migrationsAfterTheFirst")
@DisplayName("ledger에 쓴 트랜잭션이 열려 있으면 ledger를 잠그는 마이그레이션은 상한 안에 실패하고 아무것도 바꾸지 않는다")
void aLedgerMigrationGivesUpOnAnOpenWriterAndChangesNothing(String migration) throws Exception {
PGSimpleDataSource dataSource = dataSource();
@@ -73,6 +83,10 @@ class GrpcOperationLedgerMigrationLockWaitIT {
String.valueOf(attempt.sqlState()),
attempt.took().compareTo(GIVES_UP_WITHIN) < 0,
schema(statement)))
.as(
"%s must put SET LOCAL lock_timeout = '5s'; before it locks the ledger"
+ " (docs/jpa/migration-guide.md, \"Bound the lock wait\")",
migration)
.containsExactly(LOCK_NOT_AVAILABLE, true, schemaBefore);
}
}
@@ -3,24 +3,44 @@ package dev.caskeleton.grpc.ledger;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Stream;
/**
* The ledger's Flyway scripts in version order, as one SQL text for a test database.
*
* <p>One list for every PostgreSQL lane, so a new migration is applied by all of them or by none;
* two copies of the list drift the first time someone adds a V003 to one of them.
* <p>One list for every PostgreSQL lane, so a new migration is applied by all of them or by none.
* The list is the tree on disk, not a copy of it: a hand-kept list let a V004 that nobody added to
* it go unapplied and unchecked by every lane (re-review 2026-11-03 round 3, RR3-02-04).
*/
final class GrpcOperationLedgerMigrations {
private static final List<String> IN_ORDER =
List.of(
"db/migration/grpc/V001__create_grpc_operation_ledger.sql",
"db/migration/grpc/V002__index_grpc_operation_ledger_finished_rows.sql",
"db/migration/grpc/V003__add_grpc_operation_ledger_claim_attempt.sql");
/** The ledger's tree from this leaf's directory, where the lanes run. */
private static final Path TREE = Path.of("src/main/resources/db/migration/grpc");
/** The same tree on the classpath, where the scripts are read from. */
private static final String LOCATION = "db/migration/grpc/";
private GrpcOperationLedgerMigrations() {}
/**
* The file name of every versioned migration in the tree ({@code V<version>__<name>.sql}), in
* Flyway's order: by version, its parts compared as numbers.
*/
static List<String> inOrder() throws IOException {
try (Stream<Path> files = Files.list(TREE)) {
return files
.map(file -> file.getFileName().toString())
.filter(name -> name.matches("V\\d+(?:[._]\\d+)*__.+\\.sql"))
.sorted(Comparator.comparing(GrpcOperationLedgerMigrations::version, Arrays::compare))
.toList();
}
}
/** Every migration's SQL, concatenated in version order. */
static String all() throws IOException {
return before(null);
@@ -29,26 +49,31 @@ final class GrpcOperationLedgerMigrations {
/** The SQL of every migration before the one named, concatenated in version order. */
static String before(String fileName) throws IOException {
StringBuilder sql = new StringBuilder();
for (String path : IN_ORDER) {
if (path.endsWith("/" + fileName)) {
for (String name : inOrder()) {
if (name.equals(fileName)) {
break;
}
sql.append(read(path)).append('\n');
sql.append(read(name)).append('\n');
}
return sql.toString();
}
/** One migration's SQL, by its file name. */
static String named(String fileName) throws IOException {
for (String path : IN_ORDER) {
if (path.endsWith("/" + fileName)) {
return read(path);
}
if (!inOrder().contains(fileName)) {
throw new IOException("no gRPC operation-ledger migration is named " + fileName);
}
throw new IOException("no gRPC operation-ledger migration is named " + fileName);
return read(fileName);
}
private static String read(String path) throws IOException {
private static int[] version(String fileName) {
return Arrays.stream(fileName.substring(1, fileName.indexOf("__")).split("[._]"))
.mapToInt(Integer::parseInt)
.toArray();
}
private static String read(String fileName) throws IOException {
String path = LOCATION + fileName;
try (InputStream stream =
GrpcOperationLedgerMigrations.class.getClassLoader().getResourceAsStream(path)) {
if (stream == null) {