From 2be0fa9c510468468ccb1a539bf73c0da2e16915 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 12 Aug 2024 12:38:28 -0500 Subject: [PATCH] fix(swing-store): accept budget=Infinity to allow unlimited deletions This will make life easier for the upcoming swingset change, where `runPolicy.allowCleanups()` can return `{ default: Infinity }`. --- packages/swing-store/docs/snapstore.md | 2 +- packages/swing-store/docs/transcriptstore.md | 2 +- packages/swing-store/src/snapStore.js | 4 ++-- packages/swing-store/src/transcriptStore.js | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/swing-store/docs/snapstore.md b/packages/swing-store/docs/snapstore.md index de4bff1f2fb..8cd88097a56 100644 --- a/packages/swing-store/docs/snapstore.md +++ b/packages/swing-store/docs/snapstore.md @@ -42,7 +42,7 @@ The SnapStore doesn't provide an explicit API to call when a vat is first create When terminating a vat, the kernel should first call `snapStore.stopUsingLastSnapshot(vatID)`, the same call it would make at the end of an incarnation, to indicate that we're no longer using the last snapshot. This results in zero in-use snapshots. -Then, the kernel must either call `snapStore.deleteVatSnapshots(vatID, undefined)` to delete everything at once, or make a series of calls (spread out over time/blocks) to `snapStore.deleteVatSnapshots(vatID, budget)`. Each will return `{ done, cleanups }`, which can be used to manage the rate-limiting and know when the process is finished. +Then, the kernel must either call `snapStore.deleteVatSnapshots(vatID)` or `deleteVatSnapshots(vatID, Infinity)` to delete everything at once, or make a series of calls (spread out over time/blocks) to `snapStore.deleteVatSnapshots(vatID, budget)`. Each will return `{ done, cleanups }`, which can be used to manage the rate-limiting and know when the process is finished. The `stopUsingLastSnapshot()` is a performance improvement, but is not mandatory. If omitted, exports will continue to include the vat's snapshot artifacts until the first call to `deleteVatSnapshots()`, after which they will go away. Snapshots are deleted in descending `snapPos` order, so the first call will delete the only `inUse = 1` snapshot, after which exports will omit all artifacts for the vatID. `stopUsingLastSnapshot()` is idempotent, and extra calls will leave the DB unchanged. diff --git a/packages/swing-store/docs/transcriptstore.md b/packages/swing-store/docs/transcriptstore.md index a3540e02f6f..563590d8874 100644 --- a/packages/swing-store/docs/transcriptstore.md +++ b/packages/swing-store/docs/transcriptstore.md @@ -63,7 +63,7 @@ Unlike the [SnapStore](./snapstore.md), the TranscriptStore *does* have an expli When a vat is terminated, the kernel should first call `transcriptStore.stopUsingTranscript(vatID)`. This will mark the single current span as `isCurrent = 0`. The kernel must not attempt to read, add, or rollover spans or items while in this state. While in this state, exports (export for `mode = debug`) will not emit artifacts for this VatID: export-data records will still exist for all spans, as these must be deleted slowly, however there will be no associated artifacts or artifact names. -Then, the kernel should either call `transcriptStore.deleteVatTranscripts(vatID, undefined)` exactly once, or it should call `transcriptStore.deleteVatTranscripts(vatID, budget)` until it returns `{ done: true }`. +Then, the kernel should either call `transcriptStore.deleteVatTranscripts(vatID)` exactly once, or it should call `transcriptStore.deleteVatTranscripts(vatID, budget)` until it returns `{ done: true }`. As with snapshots, the `stopUsingTranscript()` is a non-mandatory performance improvement. If omitted, exports will continue to include (many) span artifacts for this vat until the first call to `deleteVatTranscripts()` removes the one `isCurrent = 1` span (since spans are deleted most-recent-first). After that point, exports will stop including any artifacts for the vatID. `stopUsingTranscript()` is idempotent, and extra calls will leave the DB unchanged. diff --git a/packages/swing-store/src/snapStore.js b/packages/swing-store/src/snapStore.js index 20e13373f9f..c1dee7b2ecd 100644 --- a/packages/swing-store/src/snapStore.js +++ b/packages/swing-store/src/snapStore.js @@ -393,9 +393,9 @@ export function makeSnapStore( * @param {number} [budget] * @returns {{ done: boolean, cleanups: number }} */ - function deleteVatSnapshots(vatID, budget = undefined) { + function deleteVatSnapshots(vatID, budget = Infinity) { ensureTxn(); - const deleteAll = budget === undefined; + const deleteAll = budget === Infinity; assert(deleteAll || budget >= 1, 'budget must be undefined or positive'); // We can't use .iterate because noteExport can write to the DB, // and overlapping queries are not supported. diff --git a/packages/swing-store/src/transcriptStore.js b/packages/swing-store/src/transcriptStore.js index 1a10e897d1d..73145cfe9e2 100644 --- a/packages/swing-store/src/transcriptStore.js +++ b/packages/swing-store/src/transcriptStore.js @@ -394,9 +394,9 @@ export function makeTranscriptStore( * @param {number} [budget] * @returns {{ done: boolean, cleanups: number }} */ - function deleteVatTranscripts(vatID, budget = undefined) { + function deleteVatTranscripts(vatID, budget = Infinity) { ensureTxn(); - const deleteAll = budget === undefined; + const deleteAll = budget === Infinity; assert(deleteAll || budget >= 1, 'budget must be undefined or positive'); // We can't use .iterate because noteExport can write to the DB, // and overlapping queries are not supported.