-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
314 additions
and
35 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 |
---|---|---|
|
@@ -407,3 +407,4 @@ func parsePIDFromMultiaddr(addr ma.Multiaddr) string { | |
} | ||
return pidstr | ||
} | ||
|
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
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,91 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
|
||
"fmt" | ||
"os" | ||
|
||
"github.com/urfave/cli" | ||
|
||
peer "github.com/libp2p/go-libp2p-peer" | ||
|
||
ipfscluster "github.com/ipfs/ipfs-cluster" | ||
"github.com/ipfs/ipfs-cluster/state/mapstate" | ||
"github.com/ipfs/ipfs-cluster/consensus/raft" | ||
) | ||
|
||
|
||
func upgrade(c *cli.Context) error { | ||
if c.NArg() < 1 || c.NArg() > 2 { | ||
return fmt.Errorf("Usage: <BACKUP-FILE-PATH> [RAFT-DATA-DIR]") | ||
} | ||
//Load configs | ||
cfg, clusterCfg, _, _, consensusCfg, _, _, _ := makeConfigs() | ||
err := cfg.LoadJSONFromFile(configPath) | ||
if err != nil { | ||
return err | ||
} | ||
backupFilePath := c.Args().First() | ||
var raftDataPath string | ||
if c.NArg() == 1 { | ||
raftDataPath = consensusCfg.DataFolder | ||
} else { | ||
raftDataPath = c.Args().Get(1) | ||
} | ||
|
||
//Migrate backup to new state | ||
backup, err := os.Open(backupFilePath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer backup.Close() | ||
r := bufio.NewReader(backup) | ||
newState := mapstate.NewMapState() | ||
err = newState.Restore(r) | ||
if err != nil { | ||
return err | ||
} | ||
//Record peers of cluster | ||
var peers []peer.ID | ||
for _, m := range clusterCfg.Peers { | ||
pid, _, err := ipfscluster.MultiaddrSplit(m) | ||
if err != nil { | ||
return err | ||
} | ||
peers = append(peers, pid) | ||
} | ||
peers = append(peers, clusterCfg.ID) | ||
//Reset raft state to a snapshot of the new migrated state | ||
err = raft.SnapshotReset(newState, consensusCfg, raftDataPath, peers) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
|
||
func needsUpdate(cfg *ipfscluster.Config, cCfg *raft.Config) bool { | ||
state := mapstate.NewMapState() | ||
r, err := raft.ExistingStateReader(cCfg) // Note direct dependence on raft here | ||
if err == nil { //err != nil no snapshots so skip check | ||
storedV, err := state.GetVersion(r) | ||
if storedV != state.Version || err != nil { | ||
logger.Error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") | ||
logger.Error("Raft state is in a non-supported version") | ||
err = state.Restore(r) | ||
if err == nil { | ||
err = ipfscluster.BackupState(cfg, state) | ||
if err == nil { | ||
logger.Error("An updated backup of this state has been saved") | ||
logger.Error("to baseDir/backups. To setup state for use") | ||
logger.Error("run ipfs-cluster-service migration on the latest backup") | ||
} | ||
logger.Error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") | ||
return true | ||
} | ||
} | ||
} | ||
return false | ||
} |
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
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,39 @@ | ||
#! /bin/sh | ||
|
||
test_description="Test service migration v1 -> v2 and v2 -> v2" | ||
|
||
. lib/test-lib.sh | ||
|
||
test_ipfs_init | ||
cleanup test_clean_ipfs | ||
test_cluster_init | ||
test_create_v1State | ||
cleanup test_clean_cluster | ||
|
||
test_expect_success IPFS,CLUSTER "cluster-service state preserved by migration" ' | ||
cid=`docker exec ipfs sh -c "echo test | ipfs add -q"` && | ||
ipfs-cluster-ctl pin add "$cid" &> test4 && sleep 2 && | ||
kill -1 $CLUSTER_D_PID && sleep 30 && | ||
export BACKUP_FILE=$( ls test-config/backups/ | head -n 1) && | ||
ipfs-cluster-service --config "test-config" state upgrade "test-config/backups/""$BACKUP_FILE" "test-config/ipfs-cluster-data" && | ||
echo "successful state upgrade" && | ||
ipfs-cluster-service --config "test-config" >"$IPFS_OUTPUT" 2>&1 & | ||
export CLUSTER_D_PID=$! && | ||
sleep 30 && | ||
ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid" && | ||
ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED" | ||
' | ||
|
||
test_expect_success IPFS,CLUSTER,V1STATE "cluster-service loads v1 state correctly" ' | ||
cid=`docker exec ipfs sh -c "echo test | ipfs add -q"` && | ||
kill -1 $CLUSTER_D_PID && sleep 30 && | ||
ipfs-cluster-service --config "test-config" state upgrade "test-config/v1State" "test-config/ipfs-cluster-data" && | ||
ipfs-cluster-service --config "test-config" >"$IPFS_OUTPUT" 2>&1 & | ||
export CLUSTER_D_PID=$! && | ||
sleep 30 && | ||
ipfs-cluster-ctl pin ls "$cid" | grep -q "$cid" && | ||
ipfs-cluster-ctl status "$cid" | grep -q -i "PINNED" | ||
kill -1 $CLUSTER_D_PID | ||
' | ||
|
||
test_done |
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
Oops, something went wrong.