Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(swing-store): replace getAllState/etc with a debug facet #6796

Merged
merged 2 commits into from
Jan 20, 2023

Conversation

warner
Copy link
Member

@warner warner commented Jan 15, 2023

Previously, getAllState and setAllState were swing-store helper methods which copy (or set) all the state of a store at once, used exclusively for testing. These tests would either want to inspect the swing-store contents directly, or clone a swing-store for e.g. replay testing.

This commit replaces both with a new debug facet (a sibling of kernelStorage and hostStorage), which offers two methods.

debug.dump() returns a JS Object with the store data in an easy-to-examine format (dump.kvEntries['key']=value, dump.streams[vatID]=[..], and dump.snapshots[vatID] = {endPos, hash, compressedSnapshot }.

For cloning, debug.serialize() returns a Buffer that has a raw copy of the SQLite backing store. This can be used to make a new DB by passing it as an option to initSwingStore:

const serialized = swingstore1.debug.serialize();
const swingstore2 = initSwingStore(null, { serialized });

Note that both .serialize() and { serialized } require an in-RAM database, rather than an on-disk one.

@warner warner added the SwingSet package: SwingSet label Jan 15, 2023
@warner warner self-assigned this Jan 15, 2023
@warner
Copy link
Member Author

warner commented Jan 15, 2023

This PR wants to land on trunk after the two #6742 PRs finish rearranging the snapstore, but to get CI to run, I'm configuring the PR target to the second snapstore PR's branch. I don't actually want to merge it into that branch; this is a separate effort.

To get the types to pass lint, this makes some changes that should really be in #6742 (specifically the removal of the ephemeral/stub snapstore: now that snapshots are in the DB, even :memory: swingstores can hold snapshots). I figure I'll rewrite this PR once those fixes have been incorporated into the upstream PR. cc @FUDCo

@warner warner requested a review from FUDCo January 15, 2023 22:03
@warner
Copy link
Member Author

warner commented Jan 15, 2023

requesting a preliminary review from @FUDCo, also feel free to pull typedef updates or the no-more-ephemeral-snapstore changes from it

@mhofman mhofman self-requested a review January 17, 2023 18:42
@FUDCo FUDCo force-pushed the 6742-snapshot-with-metadata branch 2 times, most recently from b843da9 to 0da5f4b Compare January 18, 2023 22:24
Base automatically changed from 6742-snapshot-with-metadata to 6742-snapstore January 18, 2023 22:59
Base automatically changed from 6742-snapstore to master January 19, 2023 11:14
@warner warner marked this pull request as ready for review January 19, 2023 16:50
Copy link
Contributor

@FUDCo FUDCo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of minor nits you might want to consider before landing, but this looks good. It has that nice "ooh, this feels cleaner" feel.

Comment on lines +555 to +557
if (filePath !== ':memory:') {
throw Error('on-disk DBs with WAL mode enabled do not serialize well');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be an assert?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I'm unsure.. it's not like the user did something wrong, it's more like "I wish I could accomodate that, but I can't, sorry". assert.meekly(), as it were. I guess I'll leave it.

return db.serialize();
}

function getAllKVEntries() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For symmetry, I'm wondering if getAllKVEntries should be called something like dumpKVEntries.

I'm also wondering if at this point we should split all the kvStore stuff into its own source file, parallel to snapStore.js and streamStore.js. (Not in this PR, but if you agree it makes sense then one of us should add an issue.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes on both, I'll file an issue and I can do it after we land the getNext stuff (just to minimize merge conflicts)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I'll do the dumpKVEntries here, it's trivial, but I'll defer the refactoring for later, the activityhash made that nontrivial

@warner
Copy link
Member Author

warner commented Jan 20, 2023

Hrmph, the CI failure looks to be a GC variance between original and replay under Node.js (but only under Node-18.3.0, not 16). And of course I can't reproduce it locally, even under linux and the same version of Node.

I'm going to change it to only use XS (as the comment suggests). What this test is examining shouldn't depend upon the engine in use.

Previously, `getAllState` and `setAllState` were swing-store helper
methods which copy (or set) all the state of a store at once, used
exclusively for testing. These tests would either want to inspect the
swing-store contents directly, or clone a swing-store for e.g. replay
testing.

This commit replaces both with a new `debug` facet (a sibling of
`kernelStorage` and `hostStorage`), which offers two
methods.

`debug.dump()` returns a JS Object with the store data in an
easy-to-examine format (`dump.kvEntries['key']=value`,
`dump.streams[vatID]=[..]`, and `dump.snapshots[vatID] = {endPos,
hash, compressedSnapshot }`.

For cloning, `debug.serialize()` returns a Buffer that has a raw copy
of the SQLite backing store. This can be used to make a new DB by
passing it as an option to `initSwingStore`:

```js
const serialized = swingstore1.debug.serialize();
const swingstore2 = initSwingStore(null, { serialized });
```

Note that both `.serialize()` and `{ serialized }` require an in-RAM
database, rather than an on-disk one.

It also cleans up the streamstore types exports a bit.
I'm seeing CI failures under Node-18 in this test, presumeably because
we get GC variation between the first run and the replay. Super
annoying, and not germane to what this test is supposed to be
executing. The `test.serial` wrapper wasn't enough to fix it, so I've
just switched the test to only use xs-worker.

refs #3240
@warner warner added the automerge:no-update (expert!) Automatically merge without updates label Jan 20, 2023
@mergify mergify bot merged commit aa9922d into master Jan 20, 2023
@mergify mergify bot deleted the move-dumpstreams branch January 20, 2023 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:no-update (expert!) Automatically merge without updates SwingSet package: SwingSet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants