From 19be79a48fdc0334eb9bc1cd1a8b11744b773388 Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Mon, 8 Apr 2019 12:17:57 -0700 Subject: [PATCH] Restart program after resharding --- core/resharding.go | 4 ++-- node/node_handler.go | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/core/resharding.go b/core/resharding.go index c671ec2af..be6671ff4 100644 --- a/core/resharding.go +++ b/core/resharding.go @@ -22,9 +22,9 @@ const ( // FirstEpoch is the number of the first epoch. FirstEpoch = 1 // GenesisShardNum is the number of shard at genesis - GenesisShardNum = 4 + GenesisShardNum = 2 // GenesisShardSize is the size of each shard at genesis - GenesisShardSize = 50 + GenesisShardSize = 10 // CuckooRate is the percentage of nodes getting reshuffled in the second step of cuckoo resharding. CuckooRate = 0.1 ) diff --git a/node/node_handler.go b/node/node_handler.go index 2bb0e5f7a..12814e4d7 100644 --- a/node/node_handler.go +++ b/node/node_handler.go @@ -7,6 +7,8 @@ import ( "fmt" "math" "os" + "os/exec" + "syscall" "time" "github.com/harmony-one/harmony/core" @@ -22,7 +24,7 @@ import ( "github.com/harmony-one/harmony/api/service" "github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/crypto/pki" - nodeconfig "github.com/harmony-one/harmony/internal/configs/node" + "github.com/harmony-one/harmony/internal/configs/node" "github.com/harmony-one/harmony/internal/utils" "github.com/harmony-one/harmony/p2p" "github.com/harmony-one/harmony/p2p/host" @@ -579,8 +581,32 @@ func (node *Node) processEpochShardState(epochShardState *types.EpochShardState) utils.GetLogInstance().Info(fmt.Sprintf("[Resharded][epoch:%d] I stay at shard %d, %s", epoch, myShard, aboutLeader), "BlsPubKey", hex.EncodeToString(myBlsPubKey)) } else { utils.GetLogInstance().Info(fmt.Sprintf("[Resharded][epoch:%d] I got resharded to shard %d from shard %d, %s", epoch, myShard, node.blockchain.ShardID(), aboutLeader), "BlsPubKey", hex.EncodeToString(myBlsPubKey)) + + execFile, err := lookPath() + if err != nil { + utils.GetLogInstance().Crit("Failed to get program path when restarting program" , "error", err) + } + + utils.GetLogInstance().Info("Restarting program" , "args", os.Args, "env", os.Environ()) + err = syscall.Exec(execFile, os.Args, os.Environ()) + if err != nil { + utils.GetLogInstance().Crit("Failed to restart program after resharding" , "error", err) + } + os.Exit(0) } } else { utils.GetLogInstance().Info(fmt.Sprintf("[Resharded][epoch:%d] Somehow I got kicked out", epoch), "BlsPubKey", hex.EncodeToString(myBlsPubKey)) + os.Exit(0) } } + +func lookPath() (argv0 string, err error) { + argv0, err = exec.LookPath(os.Args[0]) + if nil != err { + return + } + if _, err = os.Stat(argv0); nil != err { + return + } + return +} \ No newline at end of file