@agoric/swing-store 0.9.2-dev-3fd7a2b.0 → 0.9.2-dev-a0c5f45.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.
Files changed (2) hide show
  1. package/docs/data-export.md +78 -51
  2. package/package.json +4 -4
@@ -39,30 +39,41 @@ The exporter is created by calling `makeSwingStoreExporter(dirpath)`, passing it
39
39
  After calling `hostStorage.commit()`, the host application can extract the first-stage export data, and then the second-stage export artifacts:
40
40
 
41
41
  ```js
42
- import { buffer } from 'node:stream/consumers';
43
-
44
- const dirPath = '.../swing-store';
45
- const swingStore = openSwingStore(dirPath);
46
- ...
47
- await controller.run();
48
- hostStorage.commit();
49
- // spawn a child process
50
-
51
- // child process does:
52
- const exporter = makeSwingStoreExporter(dirPath);
53
- // exporter now has a txn, parent process is free to proceed forward
54
- const exportData = new Map();
55
- for (const [key, value] of exporter.getExportData()) {
56
- exportData.set(key, value);
57
- }
58
- const exportArtifacts = new Map();
59
- for (const name of exporter.getArtifactNames()) {
60
- const reader = exporter.getArtifact(name);
61
- // reader is an async iterable of Uint8Array, e.g. a stream
62
- const data = await buffer(reader);
63
- exportArtifacts.set(name, data);
42
+ const dirPath = '.../swing-store';
43
+ const swingStore = openSwingStore(dirPath);
44
+ ...
45
+ await controller.run();
46
+ hostStorage.commit();
47
+ // spawn a child process and wait for it to open a transaction
48
+ const started = makePromiseKit();
49
+ const child = fork(path, args);
50
+ child.on('error', started.reject);
51
+ child.on('exit', started.reject);
52
+ child.on('message', msg => {
53
+ if (msg?.type === 'started') {
54
+ started.resolve();
64
55
  }
65
- // export is 'exportData' and 'exportArtifacts'
56
+ });
57
+ await started.promise;
58
+ ...
59
+
60
+ // child process does:
61
+ import { buffer } from 'node:stream/consumers';
62
+ const exporter = makeSwingStoreExporter(dirPath);
63
+ // exporter now has a txn, so parent process is free to proceed forward
64
+ process.send({ type: 'started' });
65
+ const exportData = new Map();
66
+ for (const [key, value] of exporter.getExportData()) {
67
+ exportData.set(key, value);
68
+ }
69
+ const exportArtifacts = new Map();
70
+ for (const name of exporter.getArtifactNames()) {
71
+ const reader = exporter.getArtifact(name);
72
+ // reader is an async iterable of Uint8Array, e.g. a stream
73
+ const data = await buffer(reader);
74
+ exportArtifacts.set(name, data);
75
+ }
76
+ // export is the combination of 'exportData' and 'exportArtifacts'
66
77
  ```
67
78
 
68
79
  ![image 3](./images/data-export-3.jpg)
@@ -92,35 +103,51 @@ Then, on the few occasions when the application needs to build a full state-sync
92
103
  ![image 4](./images/data-export-4.jpg)
93
104
 
94
105
  ```js
95
- const dirPath = '.../swing-store';
96
- const iavl = ...;
97
- function exportCallback(key, value) {
98
- const iavlKey = `ssed.${key}`; // 'ssed' is short for SwingStoreExportData
99
- if (value) {
100
- iavl.set(iavlKey, value);
101
- } else {
102
- iavl.delete(iavlKey); // value===undefined means delete
103
- }
104
- }
105
- const swingStore = openSwingStore(dirPath, { exportCallback });
106
- ...
107
- await controller.run();
108
- hostStorage.commit();
109
-
110
- // now, if the validator is configured to publish state-sync snapshots,
111
- // and if this block height is one of the publishing points,
112
- // do the following:
113
-
114
- // spawn a child process
115
-
116
- // child process does:
117
- const exporter = makeSwingStoreExporter(dirPath);
118
- // note: no exporter.getExportData(), the first-stage data is already in IAVL
119
- const artifacts = new Map();
120
- for (const name of exporter.getArtifactNames()) {
121
- artifacts.set(name, exporter.getArtifact(name));
106
+ const dirPath = '.../swing-store';
107
+ const iavl = ...;
108
+ function exportCallback(key, value) {
109
+ const iavlKey = `ssed.${key}`; // 'ssed' is short for SwingStoreExportData
110
+ if (value === undefined) {
111
+ iavl.delete(iavlKey);
112
+ } else {
113
+ iavl.set(iavlKey, value);
114
+ }
115
+ }
116
+ const swingStore = openSwingStore(dirPath, { exportCallback });
117
+ ...
118
+ await controller.run();
119
+ hostStorage.commit();
120
+
121
+ // now, if the validator is configured to publish state-sync snapshots,
122
+ // and if this block height is one of the publishing points,
123
+ // do the following:
124
+
125
+ // spawn a child process and wait for it to open a transaction
126
+ const started = makePromiseKit();
127
+ const child = fork(path, args);
128
+ child.on('error', started.reject);
129
+ child.on('exit', started.reject);
130
+ child.on('message', msg => {
131
+ if (msg?.type === 'started') {
132
+ started.resolve();
122
133
  }
123
- // instruct cosmos-sdk to include 'artifacts' in the state-sync snapshot
134
+ });
135
+ try {
136
+ await started.promise;
137
+ } catch (err) {
138
+ ...
139
+ }
140
+ ...
141
+
142
+ // child process does:
143
+ const exporter = makeSwingStoreExporter(dirPath);
144
+ process.send({ type: 'started' });
145
+ // note: no exporter.getExportData(), the first-stage data is already in IAVL
146
+ const artifacts = new Map();
147
+ for (const name of exporter.getArtifactNames()) {
148
+ artifacts.set(name, exporter.getArtifact(name));
149
+ }
150
+ // instruct cosmos-sdk to include 'artifacts' in the state-sync snapshot
124
151
  ```
125
152
 
126
153
  ## Import
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/swing-store",
3
- "version": "0.9.2-dev-3fd7a2b.0+3fd7a2b",
3
+ "version": "0.9.2-dev-a0c5f45.0+a0c5f45",
4
4
  "description": "Persistent storage for SwingSet",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -21,8 +21,8 @@
21
21
  "lint:eslint": "eslint ."
22
22
  },
23
23
  "dependencies": {
24
- "@agoric/assert": "0.6.1-dev-3fd7a2b.0+3fd7a2b",
25
- "@agoric/internal": "0.3.3-dev-3fd7a2b.0+3fd7a2b",
24
+ "@agoric/assert": "0.6.1-dev-a0c5f45.0+a0c5f45",
25
+ "@agoric/internal": "0.3.3-dev-a0c5f45.0+a0c5f45",
26
26
  "@endo/base64": "^0.2.34",
27
27
  "@endo/bundle-source": "^2.7.0",
28
28
  "@endo/check-bundle": "^0.2.21",
@@ -51,5 +51,5 @@
51
51
  "typeCoverage": {
52
52
  "atLeast": 75.52
53
53
  },
54
- "gitHead": "3fd7a2bef942ddcce5233c87116d6ef7e1220f6d"
54
+ "gitHead": "a0c5f45598785cdb60fb472649eecdcd13f05108"
55
55
  }