Skip to content

Commit

Permalink
rename snapstore 'endPos' to 'snapPos'
Browse files Browse the repository at this point in the history
This should reduce the chances of confusing it with
`transcriptSpan.endPos`. The two numbers are related: `snapPos` is the
same as `endPos` in the brief moment when we've just written out the
snapshot, but we immediately append a `save-snapshot` event, causing
`endPos` to increment. The `endPos` of the transcript span, being an
exclusive-right-edge kind of number, will be one larger than the last
item in the span, which means it will also be one larger than the
`snapPos`.
  • Loading branch information
warner committed Apr 27, 2023
1 parent 0c2e6ec commit f9f9456
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 68 deletions.
8 changes: 4 additions & 4 deletions packages/SwingSet/misc-tools/extract-xs-snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ if (!vatIDToExtract) {
const h = `all snapshots: pos hash compressed raw`;
console.warn(h);
for (const info of snapStore.listAllSnapshots()) {
const { vatID, inUse, endPos, hash } = info;
const { vatID, inUse, snapPos, hash } = info;
const name = namedVats.get(vatID) || '?';
const used = inUse ? 'used' : 'old';
const sVatID = vatID.padEnd(3);
const sName = name.padEnd(15);
const sUsed = used.padStart(4);
const sPos = endPos.toString().padStart(6);
const sPos = snapPos.toString().padStart(6);
const sHash = `${hash.slice(0, 10)}..`;
const sCompressed = info.compressedSize.toString().padStart(7);
const sRaw = info.uncompressedSize.toString().padStart(8);
Expand All @@ -50,10 +50,10 @@ if (!vatIDToExtract) {
}
} else {
const info = snapStore.getSnapshotInfo(vatIDToExtract);
const { endPos, hash } = info;
const { snapPos, hash } = info;
const write = async tmpFilePath => {
const snapshot = fs.readFileSync(tmpFilePath);
const fn = `${vatIDToExtract}-${endPos}-${hash}.xss`;
const fn = `${vatIDToExtract}-${snapPos}-${hash}.xss`;
fs.writeFileSync(fn, snapshot);
console.log(`wrote snapshot to ${fn}`);
};
Expand Down
4 changes: 2 additions & 2 deletions packages/SwingSet/misc-tools/replay-transcript.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ async function replay(transcriptFile) {

if (argv.useCustomSnapStore) {
snapStore = /** @type {SnapStore} */ ({
async saveSnapshot(_vatID, endPos, saveRaw) {
const snapFile = `${vatID}-${endPos}-${
async saveSnapshot(_vatID, snapPos, saveRaw) {
const snapFile = `${vatID}-${snapPos}-${
saveSnapshotID || 'unknown'
}.xss`;
const { duration: rawSaveSeconds } = await measureSeconds(() =>
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/state/vatKeeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ export function makeVatKeeper(
function transcriptSnapshotStats() {
const totalEntries = getTranscriptEndPosition();
const snapshotInfo = getSnapshotInfo();
const snapshottedEntries = snapshotInfo ? snapshotInfo.endPos : 0;
const snapshottedEntries = snapshotInfo ? snapshotInfo.snapPos : 0;
return { totalEntries, snapshottedEntries };
}

Expand Down
4 changes: 2 additions & 2 deletions packages/SwingSet/src/kernel/vat-loader/manager-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import {
/**
*
* @typedef { { getManager: (shutdown: () => Promise<void>,
* makeSnapshot?: (endPos: number, ss: SnapStore) => Promise<SnapshotResult>) => VatManager,
* makeSnapshot?: (snapPos: number, ss: SnapStore) => Promise<SnapshotResult>) => VatManager,
* syscallFromWorker: (vso: VatSyscallObject) => VatSyscallResult,
* setDeliverToWorker: (dtw: unknown) => void,
* } } ManagerKit
Expand Down Expand Up @@ -170,7 +170,7 @@ function makeManagerKit(retainSyscall = false) {
/**
*
* @param { () => Promise<void>} shutdown
* @param {(endPos: number, ss: SnapStore) => Promise<SnapshotResult>} [makeSnapshot]
* @param {(snapPos: number, ss: SnapStore) => Promise<SnapshotResult>} [makeSnapshot]
* @returns {VatManager}
*/
function getManager(shutdown, makeSnapshot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ export function makeXsSubprocessFactory({
return worker.close().then(_ => undefined);
}
/**
* @param {number} endPos
* @param {number} snapPos
* @param {SnapStore} snapStore
* @returns {Promise<SnapshotResult>}
*/
function makeSnapshot(endPos, snapStore) {
return snapStore.saveSnapshot(vatID, endPos, fn => worker.snapshot(fn));
function makeSnapshot(snapPos, snapStore) {
return snapStore.saveSnapshot(vatID, snapPos, fn => worker.snapshot(fn));
}

return mk.getManager(shutdown, makeSnapshot);
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 @@ -59,7 +59,7 @@ export {};
*
* @typedef { { deliver: (delivery: VatDeliveryObject, vatSyscallHandler: VatSyscallHandler)
* => Promise<VatDeliveryResult>,
* makeSnapshot?: undefined | ((endPos: number, ss: SnapStore) => Promise<SnapshotResult>),
* makeSnapshot?: undefined | ((snapPos: number, ss: SnapStore) => Promise<SnapshotResult>),
* shutdown: () => Promise<void>,
* } } VatManager
* @typedef { { createFromBundle: (vatID: string,
Expand Down
4 changes: 2 additions & 2 deletions packages/SwingSet/test/transcript/test-transcript-entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ test('transcript spans', async t => {
c.pinVatRoot('bootstrap');
const vatID = c.vatNameToID('bootstrap');

const snapInfo = () => snapStore.getSnapshotInfo(vatID)?.endPos;
const snapInfo = () => snapStore.getSnapshotInfo(vatID)?.snapPos;
const readFull = () => [...transcriptStore.readFullVatTranscript(vatID)];
const full = () => readFull().map(row => JSON.parse(row.item));
const readOld = startPos => [...transcriptStore.readSpan(vatID, startPos)];
Expand Down Expand Up @@ -166,7 +166,7 @@ test('transcript spans', async t => {

// snapshotInitial=2 and snapshotInterval=7, so we'll see a
// save-snapshot on deliveryNum 2, and when (deliveryNum -
// snapshot.endPos) = k*7. Until an upgrade causes a span to end
// snapshot.snapPos) = k*7. Until an upgrade causes a span to end
// early, that means save-snapshot on deliveries 2, 9, 16, 23

// the full sequence of deliveries will be:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ test('vat reload from snapshot', async t => {
function getPositions() {
const snapshotInfo = snapStore.getSnapshotInfo(vatID);

const snap = snapshotInfo ? snapshotInfo.endPos : 0;
const snap = snapshotInfo ? snapshotInfo.snapPos : 0;
const bounds = kernelStorage.transcriptStore.getCurrentSpanBounds(vatID);
const start = bounds.startPos;
const end = bounds.endPos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ test('xsnap bundles are stable', async t => {
// save-snapshot as deliveryNum=2
t.is(snapStore.getSnapshotInfo('v1'), undefined);
await c2.run();
t.is(snapStore.getSnapshotInfo('v1')?.endPos, 2);
t.is(snapStore.getSnapshotInfo('v1')?.snapPos, 2);
await c2.shutdown;

// now that the worker has a snapshot, the vat preload won't fetch
Expand Down
Loading

0 comments on commit f9f9456

Please sign in to comment.