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

State dir cleanup #7606

Merged
merged 3 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions docs/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,6 @@ Description: When nonempty, create pretend prepopulated tokens like "moola" and

Lifetime: until chain is mature enough not to need any pretend tokens

## LMDB_MAP_SIZE

Affects: cosmic-swingset

Purpose: set the minimum size limit for swing-store's LMDB key-value store

Description: default is `2147483648` (2GB), and you need to set higher if you
receive `Error: MDB_MAP_FULL: Environment mapsize limit reached`

Can always be increased, and does not decrease once a transaction has been
written with the new mapSize.

Lifetime: until we no longer use LMDB in swing-store

## OTEL_EXPORTER_PROMETHEUS_PORT

Affects: cosmic-swingset
Expand All @@ -134,12 +120,6 @@ BRIDGE_TARGET=http://localhost:3001 make BASE_PORT=8002 scenario3-run

Lifetime: smart wallet transition period

## SOLO_LMDB_MAP_SIZE

Affects: solo

Same as `LMDB_MAP_SIZE`, but for solo instead of chain.

## SOLO_MNEMONIC

Affects: solo init
Expand Down
4 changes: 2 additions & 2 deletions packages/SwingSet/docs/how-to-replay.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ By modifying the replay tool, you can control how the replay is performed:
Suppose you have an agoric chain node (validator or non-voting fullnode) that keeps its state in `~/.ag-chain-cosmos/`. After stopping the node (so the database is not being modified during read), the following invocation will extract a list of vatIDs to choose from:

```
$ node extract-transcript-from-kerneldb.js ~/.ag-chain-cosmos/data/ag-cosmos-chain-state
$ node extract-transcript-from-kerneldb.js ~/.ag-chain-cosmos/data/agoric

all vats:
v1 : bank (26464 deliveries)
Expand Down Expand Up @@ -55,7 +55,7 @@ v24 : (dynamic) {"managerType":"xs-worker"} (1 deliveries)
To replay the "zoe" vat, first extract the transcript:

```
$ node extract-transcript-from-kerneldb.js ~/.ag-chain-cosmos/data/ag-cosmos-chain-state zoe
$ node extract-transcript-from-kerneldb.js ~/.ag-chain-cosmos/data/agoric zoe

extracting transcript for vat v11 into transcript-v11.sst
29905 transcript entries
Expand Down
4 changes: 2 additions & 2 deletions packages/SwingSet/misc-tools/db-dump.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function usage() {
Command line:
db-dump.js STATEDIR

where STATEDIR is e.g. ~/.ag-chain-cosmos/data/ag-cosmos-chain-state
and contains data.mdb
where STATEDIR is e.g. ~/.ag-chain-cosmos/data/agoric
and contains swingstore.sqlite

Dumps the entire kerneldb to stdout, in the form of JSON lines [key, value]
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ if (!dirPath) {
}

if (!isSwingStore(dirPath)) {
throw Error(`${dirPath} does not appear to be a swingstore (no ./data.mdb)`);
throw Error(
`${dirPath} does not appear to be a swingstore (no ./swingstore.sqlite)`,
);
}

const {
Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/src/chain-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default async function main(progname, args, { env, homedir, agcc }) {
'home',
`${homedir}/.ag-chain-cosmos`,
);
const stateDBDir = `${cosmosHome}/data/ag-cosmos-chain-state`;
const stateDBDir = `${cosmosHome}/data/agoric`;
fs.mkdirSync(stateDBDir, { recursive: true });

// console.log('Have AG_COSMOS', agcc);
Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/src/export-kernel-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export const main = async (
`${processValue.getFlag(
'home',
`${homedir}/.ag-chain-cosmos`,
Copy link
Member

Choose a reason for hiding this comment

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

While we're at it, this default location has changed, too.

Suggested change
`${homedir}/.ag-chain-cosmos`,
`${homedir}/.agd`,

)}/data/ag-cosmos-chain-state`;
)}/data/agoric`;

const stateDirStat = await fs.stat(stateDir);
if (!stateDirStat.isDirectory()) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/src/import-kernel-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export const main = async (
`${processValue.getFlag(
'home',
`${homedir}/.ag-chain-cosmos`,
Copy link
Member

Choose a reason for hiding this comment

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

Here too.

)}/data/ag-cosmos-chain-state`;
)}/data/agoric`;

const stateDirStat = await fs.stat(stateDir);
if (!stateDirStat.isDirectory()) {
Expand Down
54 changes: 1 addition & 53 deletions packages/deployment/scripts/capture-integration-results.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,60 +12,8 @@ mkdir -p "$RESULTSDIR"

home=/home/ag-chain-cosmos/.ag-chain-cosmos

for node in validator{0,1}; do
"$thisdir/setup.sh" ssh "$node" cat "$home/data/swingstore-trace" > "$RESULTSDIR/$node-swingstore-trace" || true
done

ret=0
"$thisdir/../../../scripts/process-integration-swingstore-traces.sh" "$RESULTSDIR" || ret=$?

failedtest=${1:-"unknown"}

if [ -f "$RESULTSDIR/divergent_snapshots" ]; then
if [ -s "$RESULTSDIR/validator-swingstore-trace.diff" ]; then
cat "$RESULTSDIR/validator-swingstore-trace.diff" | cut -c -80 || true
echo "Error: Swingstore trace mismatch between validators"
fi

if [ -f "$RESULTSDIR/monitor-vs-validator-swingstore-trace.diff" ] && \
[ -s "$RESULTSDIR/monitor-vs-validator-swingstore-trace.diff" ]
then
cat "$RESULTSDIR/monitor-vs-validator-swingstore-trace.diff" | cut -c -80 || true
echo "Error: Swingstore trace mismatch between loadgen monitor and validators"
fi

# Snapshot divergences were found, fail the test after capturing results
# TODO: uncomment once transient divergences are solved
# ret=1
# failedtest=true
fi

for node in validator{0,1}; do
"$thisdir/setup.sh" ssh "$node" cat "$home/config/genesis.json" > "$RESULTSDIR/$node-genesis.json" || true
"$thisdir/setup.sh" ssh "$node" cat "$home/data/chain.slog" > "$RESULTSDIR/$node.slog" || \
"$thisdir/setup.sh" ssh "$node" cat "$home/data/ag-cosmos-chain-state/flight-recorder.bin" > "$RESULTSDIR/$node-flight-recorder.bin" || true
if [ "$failedtest" != "false" ]; then
"$thisdir/setup.sh" ssh "$node" cat "$home/data/kvstore-trace" > "$RESULTSDIR/$node-kvstore-trace" || true
"$thisdir/setup.sh" ssh "$node" tar -cz -C "$home/data/xsnap-trace" . > "$RESULTSDIR/$node-xsnap-trace.tgz" || true
mkdir -p "$RESULTSDIR/$node-xs-snapshots" && "$thisdir/setup.sh" ssh "$node" tar -c -C "$home/data/ag-cosmos-chain-state/xs-snapshots" . | tar -x -C "$RESULTSDIR/$node-xs-snapshots" || true
fi
done

if [ "$failedtest" = "false" ]; then
rm -f $RESULTSDIR/validator*-swingstore-trace || true
rm -rf $RESULTSDIR/chain-stage-*-kvstore-trace \
$RESULTSDIR/chain-stage-*-storage.* \
$RESULTSDIR/chain-stage-*-swingstore-trace \
$RESULTSDIR/chain-stage-*-xsnap-trace || true
rm -rf $RESULTSDIR/client-stage-*-storage.* \
$RESULTSDIR/client-stage-*-swingstore-trace \
$RESULTSDIR/client-stage-*-xsnap-trace || true
fi

for trace in $RESULTSDIR/chain-stage-*-xsnap-trace $RESULTSDIR/client-stage-*-xsnap-trace; do
[ -d "$trace" ] || continue
tar -cz -C "$trace" -f "$trace.tgz" . || continue
rm -rf "$trace" || true
"$thisdir/setup.sh" ssh "$node" cat "$home/data/agoric/flight-recorder.bin" > "$RESULTSDIR/$node-flight-recorder.bin" || true
done

exit $ret
161 changes: 1 addition & 160 deletions scripts/process-integration-results.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,170 +15,11 @@ clean_slog() {
jq -cr 'del(.time, .monotime, .dr[2].timestamps, .memoryUsage, .heapStats, .statsTime, .compressSeconds, .rawSaveSeconds, .dbSaveSeconds)'
}

"$thisdir/process-integration-swingstore-traces.sh" "$RESULTSDIR"

# [ -f "$RESULTSDIR/divergent_snapshots" ] || exit 0

cd "$RESULTSDIR"

to_backup="divergent_snapshots divergent_snapshot_vats validator-swingstore-trace.diff"
to_backup=""
to_delete=""

[ -f monitor-vs-validator-swingstore-trace.diff ] && to_backup="$to_backup monitor-vs-validator-swingstore-trace.diff"

# TODO: handle vat suspension (aka same vatID, multiple workers)
(mkdir -p validator0-xsnap-trace && cd $_ && tar -xzf ../$_.tgz && for v in *; do [ -d $v -a ! -h $v ] && ln -sf -T $v $(jq -r '.name | split(":") | .[0]' $v/00000-options.json) ; done; true)
(mkdir -p validator1-xsnap-trace && cd $_ && tar -xzf ../$_.tgz && for v in *; do [ -d $v -a ! -h $v ] && ln -sf -T $v $(jq -r '.name | split(":") | .[0]' $v/00000-options.json) ; done; true)
[ "x${DEBUG-}" = "x1" ] && set +x
for v in validator0-xsnap-trace/v*; do
[ -d $v ] || continue
for file in $v/*; do
file2=validator1${file#validator0}
[ ${file%-snapshot.dat} = $file -o ! -f $file2 ] && diff -U0 $file $file2 2>&1 || true
done
done | grep -v "No newline at end of file" > validator-xsnap-trace.diff || true
[ "x${DEBUG-}" = "x1" ] && set -x
to_backup="$to_backup validator-xsnap-trace.diff"
to_delete="$to_delete validator0-xsnap-trace validator1-xsnap-trace"

for stage_trace in chain-stage-*-xsnap-trace.tgz; do
[ -f "$stage_trace" ] || continue
stage_trace=${stage_trace%".tgz"}
mkdir -p $stage_trace
to_delete="$to_delete $stage_trace"
tar -xz -C "$stage_trace" -f "$stage_trace.tgz" || continue
(cd $stage_trace && for v in *; do [ -d $v -a ! -h $v ] && ln -sf -T $v $(jq -r '.name | split(":") | .[0]' $v/00000-options.json) ; done; true)
done

[ "x${DEBUG-}" = "x1" ] && set +x
for v in validator0-xsnap-trace/v*; do
v=${v#validator0-xsnap-trace/}
i=1
s=-1
while true; do
s=$(( s + 1 ))
[ -d chain-stage-$s-xsnap-trace ] || break
[ -d chain-stage-$s-xsnap-trace/$v ] || continue
last_snapshot="$(echo chain-stage-$s-xsnap-trace/$v/*-snapshot.dat)"
last_snapshot="${last_snapshot##* }"
other_chain_trace=0
ns=$s
while true; do
ns=$(( ns + 1 ))
[ -d chain-stage-$ns-xsnap-trace ] || break
if [ -d chain-stage-$ns-xsnap-trace/$v ]; then
other_chain_trace=1
break
fi
done
if [ $other_chain_trace -eq 1 ]; then
if [ -f $last_snapshot ]; then
last_snapshot="${last_snapshot#chain-stage-$s-xsnap-trace/$v/}"
last_snapshot="${last_snapshot%-snapshot.dat}"
last_snapshot=$(( 10#$last_snapshot ))
else
continue
fi
else
last_snapshot=999999
fi
j=$(jq -r 'if .snapshot == null then 1 else 2 end' chain-stage-$s-xsnap-trace/$v/00000-options.json)
while [ $j -le $last_snapshot ]; do
printf -v pi "%05d" $i
file="$(echo validator0-xsnap-trace/$v/$pi-*)"
file=${file##*/}
[ -f validator0-xsnap-trace/$v/$file ] || break
printf -v pj "%05d" $j
file2="$(echo chain-stage-$s-xsnap-trace/$v/$pj-*)"
file2=${file2##*/}
[ -f chain-stage-$s-xsnap-trace/$v/$file2 ] || break
[ ${file%-snapshot.dat} = $file -a ${file2%-snapshot.dat} = $file2 ] && diff -U0 validator0-xsnap-trace/$v/$file chain-stage-$s-xsnap-trace/$v/$file2 2>&1 || true
i=$(( 1 + i ))
j=$(( 1 + j ))
done
done
done | grep -v "No newline at end of file" > monitor-vs-validator-xsnap-trace.diff || true
[ "x${DEBUG-}" = "x1" ] && set -x
grep -e '^--- validator' <(cat validator-xsnap-trace.diff monitor-vs-validator-xsnap-trace.diff) | cut -d '/' -f 2 | uniq > divergent_xsnap_trace_vats || true

to_backup="$to_backup monitor-vs-validator-xsnap-trace.diff divergent_xsnap_trace_vats"

mkdir -p "xs-snapshots"
cp -a validator0-xs-snapshots/* "xs-snapshots/" || true
cp -a validator1-xs-snapshots/* "xs-snapshots/" || true
for s in chain-*-storage.tar.xz; do
[ -f "$s" ] || continue
tar -C "xs-snapshots/" -xJf $s --wildcards '**/xs-snapshots/*.gz' --transform='s/.*\///'
done
to_delete="$to_delete xs-snapshots"

snapshots=""
for trace in chain-*-swingstore-trace validator*-swingstore-trace; do
[ -f "$trace" ] || continue
snapshots_dir=${trace%"-swingstore-trace"}-snapshots
mkdir -p $snapshots_dir
to_delete="$to_delete $snapshots_dir"
for v in $({ grep -E 'set local\.v[0-9]+\.lastSnapshot' $trace || true; } | cut -d ' ' -f 2 | cut -d '.' -f 2 | sort | uniq ); do
mkdir -p $snapshots_dir/$v
if grep -q -e "^$v\$" <(cat divergent_snapshot_vats divergent_xsnap_trace_vats); then
to_backup="$to_backup $snapshots_dir/$v"
v_divergent=1
else
v_divergent=0
fi
while read -r parsed; do
set $parsed
[ $v_divergent -eq 1 ] && snapshots="$snapshots $1"
ln -sf -T ../../xs-snapshots/$1 $snapshots_dir/$v/$2
done < <({ grep "set local.$v.lastSnapshot" $trace || true; } | \
cut -d ' ' -f 3 | \
jq -src '[.[] | [.startPos.itemCount, .snapshotID] ] | to_entries[] | [.value[1], " ", (1 + .key | tostring | length | if . >= 3 then "" else "0" * (3 - .) end), (1 + .key | tostring), "-", (.value[0] | tostring)] | join("")' \
)
done
done

gunzip -f xs-snapshots/*.gz || true
to_backup="$to_backup $(for h in $snapshots $(<divergent_snapshots); do
[ -f xs-snapshots/$h ] && echo xs-snapshots/$h || true
done | sort | uniq)"

for trace in *-xsnap-trace; do
[ -d "$trace" ] || continue
snapshots_dir=${trace%"-xsnap-trace"}-snapshots
for v in $trace/v*; do
[ -h "$v" ] || continue
v=${v#"$trace/"}
if grep -q -e "^$v\$" <(cat divergent_snapshot_vats divergent_xsnap_trace_vats); then
v_divergent=1
to_backup="$to_backup $trace/$v $trace/$(readlink $trace/$v)"
else
v_divergent=0
fi
if [ -f $trace/$v/00000-options.json ]; then
snapshot_tmp_file="$(jq -r '.snapshot | select (.!=null)' $trace/$v/00000-options.json)"
snapshot_tmp_file="${snapshot_tmp_file##*/}"
snapshot="${snapshot_tmp_file%%-*}"
if [ ! -z "$snapshot_tmp_file" ]; then
ln -sf -T $snapshot xs-snapshots/$snapshot_tmp_file
[ $v_divergent -eq 1 ] && to_backup="$to_backup xs-snapshots/$snapshot_tmp_file"
fi
fi

set $(echo $snapshots_dir/$v/*)
for trace_command in $(echo $trace/$v/*-snapshot.dat); do
[ -f $trace_command ] || continue
[ $# -gt 0 ] || exit 1
snapshot_tmp_file="$(<$trace_command)"
snapshot_tmp_file="${snapshot_tmp_file##*/}"
snapshot=$(readlink $1)
snapshot="${snapshot##*/}"
shift
ln -sf -T $snapshot xs-snapshots/$snapshot_tmp_file
[ $v_divergent -eq 1 ] && to_backup="$to_backup xs-snapshots/$snapshot_tmp_file"
done
done
done

diff <(cat validator0.slog | clean_slog) <(cat validator1.slog | clean_slog) > validator-slog.diff || true
to_backup="$to_backup validator-slog.diff"

Expand Down
52 changes: 0 additions & 52 deletions scripts/process-integration-swingstore-traces.sh

This file was deleted.