mirror of https://github.com/shunfei/cronsun
csctl: remove old node info when upgrade to v0.3.0
parent
064218734f
commit
f34a3da05e
|
@ -31,7 +31,7 @@ var UpgradeCmd = &cobra.Command{
|
||||||
ea.Exit("invalid version number")
|
ea.Exit("invalid version number")
|
||||||
}
|
}
|
||||||
|
|
||||||
nodesById := getIPMapper(ea)
|
nodesById := getIPMapper(ea, prever)
|
||||||
if prever < "0.3.0" {
|
if prever < "0.3.0" {
|
||||||
fmt.Println("upgrading data to version 0.3.0")
|
fmt.Println("upgrading data to version 0.3.0")
|
||||||
if to_0_3_0(ea, nodesById) {
|
if to_0_3_0(ea, nodesById) {
|
||||||
|
@ -48,7 +48,7 @@ var UpgradeCmd = &cobra.Command{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func getIPMapper(ea *ExitAction) map[string]*cronsun.Node {
|
func getIPMapper(ea *ExitAction, prever string) map[string]*cronsun.Node {
|
||||||
nodes, err := cronsun.GetNodes()
|
nodes, err := cronsun.GetNodes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ea.Exit("failed to fetch nodes from MongoDB: %s", err.Error())
|
ea.Exit("failed to fetch nodes from MongoDB: %s", err.Error())
|
||||||
|
@ -61,6 +61,9 @@ func getIPMapper(ea *ExitAction) map[string]*cronsun.Node {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if prever < "0.3.0" {
|
||||||
|
n.RmOldInfo()
|
||||||
|
}
|
||||||
ipMapper[n.IP] = n
|
ipMapper[n.IP] = n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
7
node.go
7
node.go
|
@ -102,7 +102,6 @@ func RemoveNode(query interface{}) error {
|
||||||
return mgoDB.WithC(Coll_Node, func(c *mgo.Collection) error {
|
return mgoDB.WithC(Coll_Node, func(c *mgo.Collection) error {
|
||||||
return c.Remove(query)
|
return c.Remove(query)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ISNodeAlive(id string) (bool, error) {
|
func ISNodeAlive(id string) (bool, error) {
|
||||||
|
@ -155,3 +154,9 @@ func (n *Node) Down() {
|
||||||
log.Errorf(err.Error())
|
log.Errorf(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RmOldInfo remove old version(< 0.3.0) node info
|
||||||
|
func (n *Node) RmOldInfo() {
|
||||||
|
RemoveNode(bson.M{"_id": n.IP})
|
||||||
|
DefalutClient.Delete(conf.Config.Node + n.IP)
|
||||||
|
}
|
||||||
|
|
|
@ -3,10 +3,7 @@ package node
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"gopkg.in/mgo.v2/bson"
|
|
||||||
|
|
||||||
"github.com/shunfei/cronsun"
|
"github.com/shunfei/cronsun"
|
||||||
"github.com/shunfei/cronsun/conf"
|
|
||||||
"github.com/shunfei/cronsun/log"
|
"github.com/shunfei/cronsun/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -25,15 +22,9 @@ func (n *Node) executCsctlCmd(key, value []byte) error {
|
||||||
|
|
||||||
switch cmd.Cmd {
|
switch cmd.Cmd {
|
||||||
case cronsun.NodeCmdRmOld:
|
case cronsun.NodeCmdRmOld:
|
||||||
n.rmOld()
|
n.Node.RmOldInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("%s execute csctl command[%s] success", n.String(), cmd.Cmd.String())
|
log.Infof("%s execute csctl command[%s] success", n.String(), cmd.Cmd.String())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) rmOld() {
|
|
||||||
// remove old version(< 0.3.0) node info
|
|
||||||
cronsun.RemoveNode(bson.M{"_id": n.IP})
|
|
||||||
cronsun.DefalutClient.Delete(conf.Config.Node + n.IP)
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue