Skip to content

Commit

Permalink
fix(swing-store): accept budget=Infinity to allow unlimited deletions
Browse files Browse the repository at this point in the history
This will make life easier for the upcoming swingset change, where
`runPolicy.allowCleanups()` can return `{ default: Infinity }`.
  • Loading branch information
warner committed Aug 12, 2024
1 parent 6813383 commit d589630
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/swing-store/docs/snapstore.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion packages/swing-store/docs/transcriptstore.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions packages/swing-store/src/snapStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions packages/swing-store/src/transcriptStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d589630

Please sign in to comment.