47b744f1c0
ipfs-cluster-service now has a migration subcommand that upgrades persistant state snapshots with an out-of-date format version to the newest version of raft state. If all cluster members shutdown with consistent state, upgrade ipfs-cluster, and run the state upgrade command, the new version of cluster will be compatible with persistent storage. ipfs-cluster now validates its persistent state upon loading it and exits with a clear error in the case the state format version is not up to date. Raft snapshotting is enforced on all shutdowns and the json backup is no longer run. This commit makes use of recent changes to libp2p-raft allowing raft states to implement their own marshaling strategies. Now mapstate handles the logic for its (de)serialization. In the interest of supporting various potential upgrade formats the state serialization begins with a varint (right now one byte) describing the version. Some go tests are modified and a go test is added to cover new ipfs-cluster raft snapshot reading functions. Sharness tests are added to cover the state upgrade command.
35 lines
1.3 KiB
Bash
Executable File
35 lines
1.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
test_description="Test service state upgrade v1 -> v2 and v2 -> v2"
|
|
IPFS_OUTPUT="/dev/stderr" # change for debugging
|
|
|
|
. lib/test-lib.sh
|
|
|
|
test_ipfs_init
|
|
cleanup test_clean_ipfs
|
|
test_cluster_init
|
|
test_confirm_v1State
|
|
cleanup test_clean_cluster
|
|
|
|
# Make a pin and shutdown to force a snapshot. Modify snapshot files to specify
|
|
# a snapshot of v1 state pinning "test" (it's easier than taking a new one each
|
|
# time with the correct metadata). Upgrade state, check that the correct
|
|
# pin cid is in the state
|
|
test_expect_success IPFS,CLUSTER,V1STATE,JQ "cluster-service loads v1 state correctly" '
|
|
cid=`docker exec ipfs sh -c "echo test | ipfs add -q"` &&
|
|
cid2=`docker exec ipfs sh -c "echo testing | ipfs add -q"` &&
|
|
ipfs-cluster-ctl pin add "$cid2" &&
|
|
cluster_kill &&
|
|
sleep 15 &&
|
|
SNAP_DIR=`find test-config/ipfs-cluster-data/snapshots/ -maxdepth 1 -mindepth 1 | head -n 1` &&
|
|
cp v1State "$SNAP_DIR/state.bin" &&
|
|
cat "$SNAP_DIR/meta.json" | jq --arg CRC "$V1_CRC" '"'"'.CRC = $CRC'"'"' > tmp.json &&
|
|
cp tmp.json "$SNAP_DIR/meta.json" &&
|
|
ipfs-cluster-service --debug --config "test-config" state upgrade &&
|
|
cluster_start &&
|
|
ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid" &&
|
|
ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED"
|
|
'
|
|
|
|
test_done
|