-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: tools for fiddling with kernel DB
- Loading branch information
Showing
5 changed files
with
252 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env -S node -r esm | ||
|
||
import '@agoric/install-ses'; | ||
import process from 'process'; | ||
import { openSwingStore } from '@agoric/swing-store-lmdb'; | ||
|
||
const log = console.log; | ||
|
||
function usage() { | ||
log(` | ||
Command line: | ||
db-delete-key.js [FLAGS] STATEDIR KEY | ||
FLAGS may be: | ||
--range - delete all keys starting with \`\${KEY}.\` | ||
`); | ||
} | ||
|
||
function fail(message, printUsage) { | ||
if (message) { | ||
log(message); | ||
} | ||
if (printUsage) { | ||
usage(); | ||
} | ||
process.exit(1); | ||
} | ||
|
||
function run() { | ||
const argv = process.argv.slice(2); | ||
|
||
let range = false; | ||
while (argv[0] && argv[0].startsWith('-')) { | ||
const flag = argv.shift(); | ||
switch (flag) { | ||
case '--range': | ||
range = true; | ||
break; | ||
default: | ||
fail(`invalid flag ${flag}`, true); | ||
break; | ||
} | ||
} | ||
if (argv.length !== 2) { | ||
fail('wrong number of args', true); | ||
} | ||
const stateDBDir = argv.shift(); | ||
const key = argv.shift(); | ||
|
||
const { storage, commit } = openSwingStore(stateDBDir); | ||
|
||
if (range) { | ||
for (const k of storage.getKeys(`${key}.`, `${key}/`)) { | ||
storage.delete(k); | ||
} | ||
} else { | ||
storage.delete(key); | ||
} | ||
commit(); | ||
} | ||
|
||
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/env -S node -r esm | ||
|
||
import '@agoric/install-ses'; | ||
import process from 'process'; | ||
import { openSwingStore } from '@agoric/swing-store-lmdb'; | ||
|
||
const log = console.log; | ||
|
||
const out = process.stdout; | ||
function p(str) { | ||
out.write(str); | ||
out.write('\n'); | ||
} | ||
|
||
function usage() { | ||
log(` | ||
Command line: | ||
db-get-key.js [FLAGS] STATEDIR KEY | ||
FLAGS may be: | ||
--raw - just output the value(s) without adornment or key info | ||
--range - output values for all keys starting with \`\${KEY}.\` | ||
`); | ||
} | ||
|
||
function fail(message, printUsage) { | ||
if (message) { | ||
log(message); | ||
} | ||
if (printUsage) { | ||
usage(); | ||
} | ||
process.exit(1); | ||
} | ||
|
||
function run() { | ||
const argv = process.argv.slice(2); | ||
|
||
let raw = false; | ||
let range = false; | ||
while (argv[0] && argv[0].startsWith('-')) { | ||
const flag = argv.shift(); | ||
switch (flag) { | ||
case '--raw': | ||
raw = true; | ||
break; | ||
case '--range': | ||
range = true; | ||
break; | ||
default: | ||
fail(`invalid flag ${flag}`, true); | ||
break; | ||
} | ||
} | ||
if (argv.length !== 2) { | ||
fail('wrong number of args', true); | ||
} | ||
const stateDBDir = argv.shift(); | ||
const key = argv.shift(); | ||
|
||
const { storage } = openSwingStore(stateDBDir); | ||
|
||
function pkv(k) { | ||
const value = storage.get(k); | ||
if (raw) { | ||
p(value); | ||
} else { | ||
p(`${k} :: ${value}`); | ||
} | ||
} | ||
|
||
if (range) { | ||
for (const k of storage.getKeys(`${key}.`, `${key}/`)) { | ||
pkv(k); | ||
} | ||
} else { | ||
pkv(key); | ||
} | ||
} | ||
|
||
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env -S node -r esm | ||
|
||
import '@agoric/install-ses'; | ||
import process from 'process'; | ||
import { openSwingStore } from '@agoric/swing-store-lmdb'; | ||
|
||
const log = console.log; | ||
|
||
function usage() { | ||
log(` | ||
Command line: | ||
db-set-key.js STATEDIR KEY VALUE | ||
`); | ||
} | ||
|
||
function fail(message, printUsage) { | ||
if (message) { | ||
log(message); | ||
} | ||
if (printUsage) { | ||
usage(); | ||
} | ||
process.exit(1); | ||
} | ||
|
||
function run() { | ||
const argv = process.argv.slice(2); | ||
|
||
if (argv.length !== 3) { | ||
fail('wrong number of args', true); | ||
} | ||
const stateDBDir = argv.shift(); | ||
const key = argv.shift(); | ||
const value = argv.shift(); | ||
|
||
const { storage, commit } = openSwingStore(stateDBDir); | ||
|
||
storage.set(key, value); | ||
commit(); | ||
} | ||
|
||
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env -S node -r esm | ||
|
||
import '@agoric/install-ses'; | ||
import process from 'process'; | ||
import { openSwingStore } from '@agoric/swing-store-lmdb'; | ||
import bundleSource from '@agoric/bundle-source'; | ||
|
||
const log = console.log; | ||
|
||
function usage() { | ||
log(` | ||
Command line: | ||
replace-bundle.js BUNDLEORVATNAME STATEDIR SOURCEPATH | ||
`); | ||
} | ||
|
||
function fail(message, printUsage) { | ||
if (message) { | ||
log(message); | ||
} | ||
if (printUsage) { | ||
usage(); | ||
} | ||
process.exit(1); | ||
} | ||
|
||
async function run() { | ||
const argv = process.argv.slice(2); | ||
if (argv.length !== 3) { | ||
fail('wrong number of args', true); | ||
} | ||
|
||
let bundleName = argv.shift(); | ||
let bundleBundle = true; | ||
const stateDBDir = argv.shift(); | ||
const srcPath = argv.shift(); | ||
|
||
const { storage, commit } = openSwingStore(stateDBDir); | ||
log(`will use ${srcPath} in ${stateDBDir} for ${bundleName}`); | ||
|
||
if (bundleName === 'kernel') { | ||
bundleName = 'kernelBundle'; | ||
} else { | ||
const vatID = storage.get(`vat.name.${bundleName}`); | ||
if (vatID) { | ||
bundleName = `${vatID}.source`; | ||
} | ||
} | ||
if (bundleName === 'kernelBundle') { | ||
bundleBundle = false; | ||
} | ||
|
||
const oldBundleStr = storage.get(bundleName); | ||
log(`old bundle is ${oldBundleStr.length} bytes`); | ||
let bundle = await bundleSource(srcPath); | ||
if (bundleBundle) { | ||
bundle = { bundle }; | ||
} | ||
const newBundleStr = JSON.stringify(bundle); | ||
log(`new bundle is ${newBundleStr.length} bytes`); | ||
storage.set(bundleName, newBundleStr); | ||
commit(); | ||
log(`bundle ${bundleName} replaced`); | ||
} | ||
|
||
run().catch(console.error); |