@agoric/swing-store 0.9.1 → 0.9.2-calypso-dev-84eb287.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/data-export.md +116 -74
- package/docs/swingstore.md +52 -0
- package/package.json +25 -16
- package/src/assertComplete.js +21 -0
- package/src/bundleStore.js +141 -48
- package/src/exporter.js +221 -0
- package/src/importer.js +133 -0
- package/src/index.js +11 -0
- package/src/internal.js +22 -0
- package/src/kvStore.js +172 -0
- package/src/repairMetadata.js +67 -0
- package/src/snapStore.js +173 -38
- package/src/snapStoreIO.js +8 -0
- package/src/swingStore.js +94 -597
- package/src/transcriptStore.js +265 -61
- package/src/types.d.ts +15 -0
- package/src/types.js +6 -0
- package/src/util.js +7 -1
- package/test/{test-bundles.js → bundles.test.js} +21 -10
- package/test/{test-deletion.js → deletion.test.js} +1 -1
- package/test/export.test.js +350 -0
- package/test/{test-exportImport.js → exportImport.test.js} +87 -67
- package/test/exports.js +102 -0
- package/test/{test-hasher.js → hasher.test.js} +0 -2
- package/test/import.test.js +413 -0
- package/test/repair-metadata.test.js +143 -0
- package/test/{test-snapstore.js → snapstore.test.js} +2 -5
- package/test/{test-state.js → state.test.js} +36 -3
- package/test/util.js +27 -0
- package/{jsconfig.json → tsconfig.json} +1 -0
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
import '@endo/init/debug.js';
|
|
4
3
|
import { Buffer } from 'node:buffer';
|
|
5
4
|
import zlib from 'zlib';
|
|
6
5
|
import sqlite3 from 'better-sqlite3';
|
|
7
6
|
|
|
8
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
9
7
|
import test from 'ava';
|
|
10
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
11
8
|
import { makeMeasureSeconds } from '@agoric/internal';
|
|
12
9
|
import { makeSnapStore } from '../src/snapStore.js';
|
|
13
10
|
|
|
@@ -29,6 +26,7 @@ function ensureTxn() {}
|
|
|
29
26
|
async function* getSnapshotStream(payload) {
|
|
30
27
|
yield Buffer.from(payload);
|
|
31
28
|
}
|
|
29
|
+
harden(getSnapshotStream);
|
|
32
30
|
|
|
33
31
|
test('compress to cache file; closes snapshot stream', async t => {
|
|
34
32
|
const db = sqlite3(':memory:');
|
|
@@ -83,6 +81,7 @@ test('compress to cache file; closes snapshot stream', async t => {
|
|
|
83
81
|
sqlGetSnapshot.pluck(true);
|
|
84
82
|
const snapshotGZ = sqlGetSnapshot.get(hash);
|
|
85
83
|
t.truthy(snapshotGZ);
|
|
84
|
+
// @ts-expect-error unknown
|
|
86
85
|
const contents = zlib.gunzipSync(snapshotGZ);
|
|
87
86
|
t.is(contents.toString(), 'abc', 'gunzip(contents) matches original');
|
|
88
87
|
const logInfo = { vatID: 'fakeVatID', ...exportInfo };
|
|
@@ -103,7 +102,6 @@ test('snapStore prepare / commit delete is robust', async t => {
|
|
|
103
102
|
|
|
104
103
|
const hashes = [];
|
|
105
104
|
for (let i = 0; i < 5; i += 1) {
|
|
106
|
-
// eslint-disable-next-line no-await-in-loop
|
|
107
105
|
const { hash } = await store.saveSnapshot(
|
|
108
106
|
'fakeVatID2',
|
|
109
107
|
i,
|
|
@@ -133,7 +131,6 @@ test('snapStore prepare / commit delete is robust', async t => {
|
|
|
133
131
|
t.is(sqlCountSnapshots.get(), 0);
|
|
134
132
|
|
|
135
133
|
for (let i = 0; i < 5; i += 1) {
|
|
136
|
-
// eslint-disable-next-line no-await-in-loop
|
|
137
134
|
const { hash } = await store.saveSnapshot(
|
|
138
135
|
'fakeVatID4',
|
|
139
136
|
i,
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
import '@endo/init/debug.js';
|
|
4
|
-
|
|
5
3
|
import tmp from 'tmp';
|
|
6
4
|
import test from 'ava';
|
|
7
5
|
|
|
@@ -32,7 +30,7 @@ async function embundle(filename) {
|
|
|
32
30
|
const bundleFile = new URL(filename, import.meta.url).pathname;
|
|
33
31
|
const bundle = await bundleSource(bundleFile);
|
|
34
32
|
const bundleID = `b1-${bundle.endoZipBase64Sha512}`;
|
|
35
|
-
return [bundleID, bundle];
|
|
33
|
+
return /** @type {const} */ ([bundleID, bundle]);
|
|
36
34
|
}
|
|
37
35
|
|
|
38
36
|
function* iterate(kvStore, start, end) {
|
|
@@ -49,6 +47,7 @@ function* iterate(kvStore, start, end) {
|
|
|
49
47
|
prev = next;
|
|
50
48
|
}
|
|
51
49
|
}
|
|
50
|
+
harden(iterate);
|
|
52
51
|
|
|
53
52
|
function makeExportLog() {
|
|
54
53
|
const exportLog = [];
|
|
@@ -316,3 +315,37 @@ test('close will abort transaction', async t => {
|
|
|
316
315
|
t.is(kvStore.get('key2'), undefined);
|
|
317
316
|
t.falsy(kvStore.has('key2'));
|
|
318
317
|
});
|
|
318
|
+
|
|
319
|
+
test('savepoints', async t => {
|
|
320
|
+
const [dbDir, cleanup] = await tmpDir('testdb');
|
|
321
|
+
t.teardown(cleanup);
|
|
322
|
+
const ss1 = initSwingStore(dbDir);
|
|
323
|
+
ss1.kernelStorage.startCrank();
|
|
324
|
+
ss1.kernelStorage.kvStore.set('key', 'value1');
|
|
325
|
+
ss1.kernelStorage.establishCrankSavepoint('sp1');
|
|
326
|
+
ss1.kernelStorage.kvStore.set('key', 'value2');
|
|
327
|
+
ss1.kernelStorage.establishCrankSavepoint('sp2');
|
|
328
|
+
ss1.kernelStorage.kvStore.set('key', 'value3');
|
|
329
|
+
ss1.kernelStorage.rollbackCrank('sp1');
|
|
330
|
+
ss1.kernelStorage.endCrank();
|
|
331
|
+
await ss1.hostStorage.commit();
|
|
332
|
+
await ss1.hostStorage.close();
|
|
333
|
+
|
|
334
|
+
const ss2 = openSwingStore(dbDir);
|
|
335
|
+
t.is(ss2.kernelStorage.kvStore.get('key'), 'value1');
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
test('savepoints do not automatically commit', async t => {
|
|
339
|
+
const [dbDir, cleanup] = await tmpDir('testdb');
|
|
340
|
+
t.teardown(cleanup);
|
|
341
|
+
const ss1 = initSwingStore(dbDir);
|
|
342
|
+
ss1.kernelStorage.startCrank();
|
|
343
|
+
ss1.kernelStorage.establishCrankSavepoint('sp1');
|
|
344
|
+
ss1.kernelStorage.kvStore.set('key', 'value1');
|
|
345
|
+
// #8423 meant this .endCrank() accidentally did a commit()
|
|
346
|
+
ss1.kernelStorage.endCrank();
|
|
347
|
+
await ss1.hostStorage.close();
|
|
348
|
+
|
|
349
|
+
const ss2 = openSwingStore(dbDir);
|
|
350
|
+
t.false(ss2.kernelStorage.kvStore.has('key'));
|
|
351
|
+
});
|
package/test/util.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import tmp from 'tmp';
|
|
3
|
+
import { createSHA256 } from '../src/hasher.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {string} [prefix]
|
|
7
|
+
* @returns {Promise<[string, () => void]>}
|
|
8
|
+
*/
|
|
9
|
+
export const tmpDir = prefix =>
|
|
10
|
+
new Promise((resolve, reject) => {
|
|
11
|
+
tmp.dir({ unsafeCleanup: true, prefix }, (err, name, removeCallback) => {
|
|
12
|
+
if (err) {
|
|
13
|
+
reject(err);
|
|
14
|
+
} else {
|
|
15
|
+
resolve([name, removeCallback]);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export async function* getSnapshotStream(contents) {
|
|
21
|
+
yield Buffer.from(contents);
|
|
22
|
+
}
|
|
23
|
+
harden(getSnapshotStream);
|
|
24
|
+
|
|
25
|
+
export function makeB0ID(bundle) {
|
|
26
|
+
return `b0-${createSHA256(JSON.stringify(bundle)).finish()}`;
|
|
27
|
+
}
|