review-followup Wave 3 라운드 4(P30): caller 트랜잭션 guard(결정 33), persistence 명시적 조립, 보안 파일 primitive, sample 기능별 패키지
- 결정 33: persistence-notification·persistence-fileserver → persistence-jpa edge, 모든 JPA store 쓰기에 `CallerTransaction.require` (그 전에 트랜잭션 밖에서 쓰던 호출자 2곳 수정 — fileserver staging 정리 P30-new-1, 알림 Blocked roll-up P30-new-2) - objectstorage local-dev provider가 디렉터리 핸들 primitive로만 파일 접근(objectstorage → support edge) — 쓰기 중 상위 디렉터리를 symlink로 바꾸면 루트 밖에 게시되던 결함 재현 FAIL→PASS - persistence-jpa 8개 패키지 component scan → 명시적 bean 선언, Mongo 조립의 반복 enabled 스위치 제거(S2-#8a) - 새 notification 제출은 공용 tenant 문법(저장된 값은 기존 규칙으로 읽음), redis-session이 tenant 저장·복원(snapshot v2, v1 읽기 유지) - sample 애플리케이션 코드를 worklog·poster·posterimage·event 패키지로, 패키지 순환 금지 테스트 검증: ./gradlew check architectureCheck verifyDependencyLocks verifyPublicPathSnapshot --continue 통과(675 task). 묶음 worktree(같은 기준 커밋)에서 PG lane(jpaPlatformContract 221·Migration 45·fileserver·idempotency·outbox·lock), Mongo 실제 lane 6개, objectstorage mainCheck(MinIO), sample integration·system·messaging contract, app-bootstrap integrationTest 통과 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f860e417a1
commit
8bbf1bf01d
+8
-1
@@ -202,7 +202,14 @@ public final class DefaultCleanupService implements CleanupService {
|
||||
// and the delete a writer could acquire that very lease, and the bytes removed were then the
|
||||
// ones an upload was actively appending to. The claim clears the lease in the same statement
|
||||
// that proves it was not held, and the session is terminal, so no later acquire can succeed.
|
||||
if (sessionStore.find(uploadId).isPresent() && !sessionStore.claimForCleanup(uploadId, now)) {
|
||||
// It commits before the bytes go: its own boundary, because the store refuses a modifying
|
||||
// statement without one (it used to run between two, and failed every time — P30-new-1).
|
||||
boolean claimed =
|
||||
transactions.inWrite(
|
||||
() ->
|
||||
sessionStore.find(uploadId).isEmpty()
|
||||
|| sessionStore.claimForCleanup(uploadId, now));
|
||||
if (!claimed) {
|
||||
markFailed(item, "ACTIVE_WRITER_LEASE", now);
|
||||
return Outcome.of(OutcomeKind.SKIPPED_ACTIVE_LEASE, 0);
|
||||
}
|
||||
|
||||
+31
-1
@@ -40,6 +40,7 @@ class CleanupServiceTest {
|
||||
private final InMemoryFileMetadataStore metadata = new InMemoryFileMetadataStore();
|
||||
private final InMemoryUploadSessionStore sessions = new InMemoryUploadSessionStore();
|
||||
private final RecordingQuotaReclaimGateway quota = new RecordingQuotaReclaimGateway();
|
||||
private final DirectTransactions transactions = new DirectTransactions();
|
||||
|
||||
private final CleanupService cleanup =
|
||||
new DefaultCleanupService(
|
||||
@@ -50,7 +51,7 @@ class CleanupServiceTest {
|
||||
quota,
|
||||
Duration.ofMinutes(5),
|
||||
FileserverMetricsPort.noop(),
|
||||
new DirectTransactions(),
|
||||
transactions,
|
||||
Clock.fixed(FileserverFixtures.NOW, ZoneOffset.UTC));
|
||||
|
||||
@Test
|
||||
@@ -213,6 +214,35 @@ class CleanupServiceTest {
|
||||
.isEqualTo(queue.claimSweeps().get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* The staging claim is a modifying statement, and the JPA store refuses one without a caller
|
||||
* transaction (review X1-#4). It used to run between two boundaries, so against the real store
|
||||
* every staging item with a session failed and was retried until abandoned (P30-new-1).
|
||||
*/
|
||||
@Test
|
||||
void theStagingClaimRunsInsideACallerTransaction() {
|
||||
// given
|
||||
UploadId uploadId = UploadId.of(UUID.randomUUID());
|
||||
FileId fileId = FileId.of(UUID.randomUUID());
|
||||
sessions.create(
|
||||
new UploadSessionDraft(
|
||||
uploadId,
|
||||
fileId,
|
||||
UploadMode.SINGLE_SHOT,
|
||||
OptionalLong.of(SIZE),
|
||||
FileserverFixtures.NOW.plusSeconds(3600)));
|
||||
sessions.terminate(uploadId);
|
||||
content.storeStaging(uploadId);
|
||||
queue.enqueue(CleanupRequest.forStaging(CleanupType.CANCELLED_STAGING, fileId, uploadId));
|
||||
sessions.requireBoundaryOf(transactions);
|
||||
|
||||
// when
|
||||
CleanupBatchResult result = cleanup.runBatch(100, 1L << 30);
|
||||
|
||||
// then
|
||||
assertThat(result.deleted()).isEqualTo(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Settling twice reclaims once.
|
||||
*
|
||||
|
||||
+19
-4
@@ -19,6 +19,12 @@ public final class DirectTransactions implements TransactionPort {
|
||||
|
||||
private final List<String> opened = new ArrayList<>();
|
||||
private RuntimeException nextNewFailure;
|
||||
private int depth;
|
||||
|
||||
/** True while an action runs inside one of this port's boundaries. */
|
||||
public boolean active() {
|
||||
return depth > 0;
|
||||
}
|
||||
|
||||
/** Makes the next {@link #inNew(Supplier)} fail with {@code failure} instead of running. */
|
||||
public void failNextNew(RuntimeException failure) {
|
||||
@@ -37,19 +43,19 @@ public final class DirectTransactions implements TransactionPort {
|
||||
@Override
|
||||
public <T> T inWrite(Supplier<T> action) {
|
||||
opened.add("write");
|
||||
return action.get();
|
||||
return run(action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T inRootWrite(Supplier<T> action) {
|
||||
opened.add("root-write");
|
||||
return action.get();
|
||||
return run(action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T inRead(Supplier<T> action) {
|
||||
opened.add("read");
|
||||
return action.get();
|
||||
return run(action);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,6 +66,15 @@ public final class DirectTransactions implements TransactionPort {
|
||||
nextNewFailure = null;
|
||||
throw failure;
|
||||
}
|
||||
return action.get();
|
||||
return run(action);
|
||||
}
|
||||
|
||||
private <T> T run(Supplier<T> action) {
|
||||
depth++;
|
||||
try {
|
||||
return action.get();
|
||||
} finally {
|
||||
depth--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
@@ -33,6 +33,16 @@ public final class InMemoryUploadSessionStore
|
||||
implements UploadSessionPort, StagingUploadLocatorPort {
|
||||
|
||||
private final Map<UploadId, UploadSession> sessions = new LinkedHashMap<>();
|
||||
private DirectTransactions boundary;
|
||||
|
||||
/**
|
||||
* Refuses a claim made outside {@code transactions}, as the JPA store's {@code CallerTransaction}
|
||||
* guard does. Off by default, so fixture set-up can still seed rows directly.
|
||||
*/
|
||||
public void requireBoundaryOf(DirectTransactions transactions) {
|
||||
this.boundary = transactions;
|
||||
}
|
||||
|
||||
private Instant now = FileserverFixtures.NOW;
|
||||
|
||||
public void advanceTo(Instant instant) {
|
||||
@@ -192,6 +202,10 @@ public final class InMemoryUploadSessionStore
|
||||
|
||||
@Override
|
||||
public boolean claimForCleanup(UploadId uploadId, Instant clockNow) {
|
||||
if (boundary != null && !boundary.active()) {
|
||||
throw new IllegalStateException(
|
||||
"upload session claimForCleanup requires an active caller transaction");
|
||||
}
|
||||
UploadSession current = sessions.get(uploadId);
|
||||
if (current == null || !current.terminal()) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user