fix(storage): 여러 페이지를 다 지운 purge를 끝났다고 보고한다 (1101/13.6)

문제: 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절
This commit is contained in:
DongHyeonka
2026-11-03 01:23:05 +09:00
parent 498ae87554
commit c4052f0f8e
2 changed files with 45 additions and 7 deletions
@@ -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
+35
View File
@@ -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);