Skip to content

Commit

Permalink
fixup! feat(SwingSet): add runtimeOption to keep worker on snapshot
Browse files Browse the repository at this point in the history
keepWorker -> restartWorker
  • Loading branch information
mhofman committed Apr 30, 2023
1 parent e22d3bc commit ac46574
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/SwingSet/misc-tools/replay-transcript.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ async function replay(transcriptFile) {
const { hash, compressSeconds: saveSeconds } = await manager.makeSnapshot(
lastTranscriptNum,
snapStore,
true,
false, // Do not restart, we'll do that ourselves if needed
);
fs.writeSync(
snapshotActivityFd,
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/controller/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ export async function makeSwingsetController(
* slogCallbacks?: unknown;
* slogSender?: import('@agoric/telemetry').SlogSender;
* testTrackDecref?: unknown;
* warehousePolicy?: import('../types-external.js').VatWarehousePolicy;
* warehousePolicy?: import('../types-external.js').VatWarehousePolicy;
* }} runtimeOptions
* @param {Record<string, unknown>} deviceEndowments
* @typedef { import('@agoric/swing-store').KVStore } KVStore
Expand Down
12 changes: 8 additions & 4 deletions packages/SwingSet/src/kernel/state/vatKeeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,17 +543,21 @@ export function makeVatKeeper(
* Store a snapshot, if given a snapStore.
*
* @param {VatManager} manager
* @param {boolean} [keepWorker]
* @param {boolean} [restartWorker]
* @returns {Promise<void>}
*/
async function saveSnapshot(manager, keepWorker) {
async function saveSnapshot(manager, restartWorker) {
if (!snapStore || !manager.makeSnapshot) {
return;
}

// tell the manager to save a heap snapshot to the snapStore
const endPosition = getTranscriptEndPosition();
const info = await manager.makeSnapshot(endPosition, snapStore, keepWorker);
const info = await manager.makeSnapshot(
endPosition,
snapStore,
restartWorker,
);

const {
hash: snapshotID,
Expand Down Expand Up @@ -583,7 +587,7 @@ export function makeVatKeeper(
compressedSize,
compressSeconds,
endPosition,
keepWorker,
restartWorker,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,14 @@ export function makeXsSubprocessFactory({
/**
* @param {number} snapPos
* @param {SnapStore} snapStore
* @param {boolean} [keepWorker]
* @param {boolean} [restartWorker]
* @returns {Promise<SnapshotResult>}
*/
async function makeSnapshot(snapPos, snapStore, keepWorker) {
async function makeSnapshot(snapPos, snapStore, restartWorker) {
const snapshotDescription = `${vatID}-${snapPos}`;
const snapshotStream = worker.makeSnapshotStream(snapshotDescription);

if (keepWorker) {
if (!restartWorker) {
return snapStore.saveSnapshot(vatID, snapPos, snapshotStream);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/SwingSet/src/kernel/vat-warehouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export function makeVatWarehouse({
panic,
warehousePolicy,
}) {
const { maxVatsOnline = 50, keepWorkerOnSnapshot = false } =
const { maxVatsOnline = 50, restartWorkerOnSnapshot = true } =
warehousePolicy || {};
// Often a large contract evaluation is among the first few deliveries,
// so let's do a snapshot after just a few deliveries.
Expand Down Expand Up @@ -590,7 +590,7 @@ export function makeVatWarehouse({
// with an initialize-snapshot or load-snapshot pseudo-delivery,
// regardless of whether the worker was restarted from snapshot
// or not.
await vatKeeper.saveSnapshot(manager, keepWorkerOnSnapshot);
await vatKeeper.saveSnapshot(manager, restartWorkerOnSnapshot);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/types-external.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export {};
*
* @typedef {object} VatWarehousePolicy
* @property { number } [maxVatsOnline] Limit the number of simultaneous workers
* @property { boolean } [keepWorkerOnSnapshot] Disable reloading from snapshot when one is taken
* @property { boolean } [restartWorkerOnSnapshot] Disable reloading from snapshot when one is taken
*/

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/types-internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export {};
* bundle?: Bundle,
* }} ManagerOptions
*
* @typedef {(snapPos: number, ss: SnapStore, keepWorker?: boolean) => Promise<SnapshotResult>} MakeSnapshot
* @typedef {(snapPos: number, ss: SnapStore, restartWorker?: boolean) => Promise<SnapshotResult>} MakeSnapshot
*
* @typedef { { deliver: (delivery: VatDeliveryObject, vatSyscallHandler: VatSyscallHandler)
* => Promise<VatDeliveryResult>,
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/test/test-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ test('static vats are unmetered on XS', async t => {
return spawn(command, args, options);
},
warehousePolicy: {
keepWorkerOnSnapshot: true,
restartWorkerOnSnapshot: false,
},
},
);
Expand Down
8 changes: 4 additions & 4 deletions packages/SwingSet/test/vat-warehouse/test-reload-snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@agoric/swing-store';
import { initializeSwingset, makeSwingsetController } from '../../src/index.js';

const vatReloadFromSnapshot = async (t, keepWorkerOnSnapshot) => {
const vatReloadFromSnapshot = async (t, restartWorkerOnSnapshot) => {
const config = {
defaultReapInterval: 'never',
snapshotInitial: 3,
Expand All @@ -30,7 +30,7 @@ const vatReloadFromSnapshot = async (t, keepWorkerOnSnapshot) => {
const argv = [];
await initializeSwingset(config, argv, kernelStorage);

const warehousePolicy = { keepWorkerOnSnapshot };
const warehousePolicy = { restartWorkerOnSnapshot };
const runtimeOptions = { warehousePolicy };

const c1 = await makeSwingsetController(kernelStorage, null, runtimeOptions);
Expand Down Expand Up @@ -102,5 +102,5 @@ const vatReloadFromSnapshot = async (t, keepWorkerOnSnapshot) => {
await c2.shutdown();
};

test('vat reload from snapshot (reload worker)', vatReloadFromSnapshot, false);
test('vat reload from snapshot (keep worker)', vatReloadFromSnapshot, false);
test('vat reload from snapshot (restart worker)', vatReloadFromSnapshot, true);
test('vat reload from snapshot (reuse worker)', vatReloadFromSnapshot, false);

0 comments on commit ac46574

Please sign in to comment.