From c4052f0f8e73169f5a5bee65e907b14630e7cc32 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Tue, 3 Nov 2026 00:34:55 +0900 Subject: [PATCH] =?UTF-8?q?fix(storage):=20=EC=97=AC=EB=9F=AC=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=EB=A5=BC=20=EB=8B=A4=20=EC=A7=80=EC=9A=B4=20?= =?UTF-8?q?purge=EB=A5=BC=20=EB=81=9D=EB=82=AC=EB=8B=A4=EA=B3=A0=20?= =?UTF-8?q?=EB=B3=B4=EA=B3=A0=ED=95=9C=EB=8B=A4=20(1101/13.6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: OPFS `enforcePolicies`의 LOGOUT·ACCOUNT_DELETION purge가 journal 목록을 두 페이지 이상 읽으면, 객체를 모두 지워도 `moreObjectsAvailable: true`를 보고하고 chunk sweep을 하지 않는다. 페이지를 넘길 때 `moreObjectsAvailable = page.value.moreAvailable`가 true를 넣고, 마지막 페이지의 `||=`가 그 값을 그대로 둔다. 호출자는 다시 불러야 끝나고, 그 사이 chunk 바이트가 기기에 남는다. 고른 방법: 페이지 넘김 대입을 지운다. 대신 "다음 페이지를 읽기 전에 멈췄다"(객체 한도나 시간 예산 소진)는 루프 머리에서 true로 적는다. `while` 조건을 루프 안 첫 검사로 옮긴 것이다. 0929/05-02(`85d8b59`)의 "건너뛴 객체가 있으면 true" 규칙은 그대로다. 그 값을 지우는 대입이 없다(마지막 페이지는 `||=`, PRESSURE 대입은 sweep하지 않는 purge). 버린 대안: 건너뜀 표시를 별도 변수로 나누기. 페이지 넘김 true가 남는 한 마지막 페이지에서 여전히 섞여 고쳐지지 않는다. 위험·한계: - 동봉 IndexedDB journal은 페이지 한도를 "남은 객체 한도"로 받아 꽉 찬 페이지를 돌려주므로, 한 번의 호출에서 두 번째 페이지가 생기지 않는다. 결함은 port가 허용하는 짧은 페이지를 돌려주는 journal에서 드러난다. 테스트도 그 journal(페이지 1개씩)로 재현했다. - 동작 차이 하나: 앞선 시간 검사를 통과한 직후 첫 페이지를 읽기 전에 시간이 다 되면, 전에는 `moreObjectsAvailable: false`로 sweep을 시도했고 이제는 true로 보고하고 sweep하지 않는다. 아무 객체도 읽지 않았으니 이쪽이 사실에 맞다. - offline-indexeddb 레시피 gzip: 36,896 → 36,889 B (한도 36,900). 검증: - RED: 새 테스트 "finishes a purge that walked more than one journal page"가 수정 전 `moreObjectsAvailable: true`, `chunkSweep` 없음으로 실패했다. - GREEN: `node scripts/run-vitest.ts run tests/unit/opfs-worker-runtime.test.ts tests/unit/opfs-byte-store.test.ts tests/unit/indexeddb-opfs-journal.test.ts` 103건 통과. `tsc` app·test·web-worker 통과, 바꾼 파일 eslint 통과. Refs: docs/reviews/2026-11-01-maturity-review/README.md 13.6절 --- .../storage/opfs/opfs-byte-store-adapter.ts | 17 +++++---- tests/unit/opfs-worker-runtime.test.ts | 35 +++++++++++++++++++ 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/adapters/storage/opfs/opfs-byte-store-adapter.ts b/src/adapters/storage/opfs/opfs-byte-store-adapter.ts index 1f590f52..1aab66bd 100644 --- a/src/adapters/storage/opfs/opfs-byte-store-adapter.ts +++ b/src/adapters/storage/opfs/opfs-byte-store-adapter.ts @@ -782,10 +782,14 @@ export function createOpfsByteStoreAdapter( let moreObjectsAvailable = false; let deadlineReached = false; - while ( - inspectedObjects < maxObjects && - now() < deadline - ) { + for (;;) { + // 1101/13.6. Only stopping before a page is read leaves objects + // behind. Turning to the next page says nothing yet, so it no longer + // sets `moreObjectsAvailable`; a finished last page used to inherit it. + if (inspectedObjects >= maxObjects || now() >= deadline) { + moreObjectsAvailable = true; + break; + } const page = await dependencies.journal.listCommittedObjects({ scope: dependencies.scope, afterObjectId, @@ -821,8 +825,8 @@ export function createOpfsByteStoreAdapter( if (removed.error.code === "CONFLICT" || removed.error.code === "NOT_FOUND") { // [0929] 05-02. Another context changed this object, so it may // still be here: report more work and skip the chunk sweep. No - // later assignment clears this — the page-advance one below only - // runs when the page had more objects, and PRESSURE never sweeps. + // later assignment clears this — the last-page one ORs, and the + // PRESSURE one only runs for a purge that never sweeps. moreObjectsAvailable = true; continue; } @@ -849,7 +853,6 @@ export function createOpfsByteStoreAdapter( break; } afterObjectId = page.value.nextObjectId; - moreObjectsAvailable = page.value.moreAvailable; } // 05-04. Removing an object leaves its chunks, and GC only takes a // chunk 24 h after it was written, so a purged user's bytes stayed on diff --git a/tests/unit/opfs-worker-runtime.test.ts b/tests/unit/opfs-worker-runtime.test.ts index 8aba8732..8aa17744 100644 --- a/tests/unit/opfs-worker-runtime.test.ts +++ b/tests/unit/opfs-worker-runtime.test.ts @@ -2373,6 +2373,41 @@ describe("05-04 a LOGOUT or ACCOUNT_DELETION purge leaves no partition bytes beh }, ); + // 1101/13.6. A journal may hand back a page shorter than the limit (the port + // does not promise full pages). A purge that walked two such pages and + // removed everything is finished: it must say so and sweep the chunks. + it("finishes a purge that walked more than one journal page", async () => { + const { root, idb, tab } = sharedRootTabs(); + const journal = createIndexedDbOpfsJournal({ + authorityToken: scopeA.authorityToken, + factory: idb.factory, + keyRange: idb.keyRange, + }); + const purged = tab("p", { + ...authority, + journal: { + ...journal, + listCommittedObjects: (request) => + journal.listCommittedObjects({ ...request, limit: 1 }), + }, + }); + expect(await putBytes(purged, "object_secret_1", [1, 2, 3])).toMatchObject({ ok: true }); + expect(await putBytes(purged, "object_secret_2", [4, 5])).toMatchObject({ ok: true }); + + expect( + await purged.maintenance.enforcePolicies({ reason: "ACCOUNT_DELETION" }), + ).toMatchObject({ + ok: true, + value: { + inspectedObjects: 2, + removedObjects: 2, + moreObjectsAvailable: false, + chunkSweep: "COMPLETED", + }, + }); + expect(filesUnder(root, scopeA)).toEqual([]); + }); + it("never sweeps the chunk of a put that runs while the purge does", async () => { const { tab } = sharedRootTabs(); const purger = tab("p", authority);