Log when command-line peer list overridden by persisted list
Reworked interface to router so we split setting up the initial list from beginning to make connections - we shouldn't do that until after router.Start().
This commit is contained in:
1 parent
ba8926a6ea
commit
b064bcce49
4 files changed
+46
-21
No files matched your search
+5
-2
@@ -127,7 +127,6 @@ func main() {
|
||||
}
|
||||
|
||||
Log.Println("Command line options:", options())
|
||||
Log.Println("Command line peers:", peers)
|
||||
|
||||
if prof != "" {
|
||||
p := *profile.CPUProfile
|
||||
@@ -169,6 +168,10 @@ func main() {
|
||||
router := weave.NewNetworkRouter(config, networkConfig, name, nickName, overlay, db)
|
||||
Log.Println("Our name is", router.Ourself)
|
||||
|
||||
if peers, err = router.InitialPeers(peers); err != nil {
|
||||
Log.Fatal("Unable to get initial peer set: ", err)
|
||||
}
|
||||
|
||||
var dockerCli *docker.Client
|
||||
if dockerAPI != "" {
|
||||
dc, err := docker.NewClient(dockerAPI)
|
||||
@@ -215,7 +218,7 @@ func main() {
|
||||
}
|
||||
|
||||
router.Start()
|
||||
if errors := router.SetInitialPeers(peers); len(errors) > 0 {
|
||||
if errors := router.InitiateConnections(peers, false); len(errors) > 0 {
|
||||
Log.Fatal(ErrorMessages(errors))
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -14,18 +14,16 @@ func (router *NetworkRouter) HandleHTTP(muxRouter *mux.Router) {
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, fmt.Sprint("unable to parse form: ", err), http.StatusBadRequest)
|
||||
}
|
||||
if errors := router.ConnectionMaker.InitiateConnections(r.Form["peer"], r.FormValue("replace") == "true"); len(errors) > 0 {
|
||||
if errors := router.InitiateConnections(r.Form["peer"], r.FormValue("replace") == "true"); len(errors) > 0 {
|
||||
http.Error(w, common.ErrorMessages(errors), http.StatusBadRequest)
|
||||
}
|
||||
router.persistPeers()
|
||||
})
|
||||
|
||||
muxRouter.Methods("POST").Path("/forget").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, fmt.Sprint("unable to parse form: ", err), http.StatusBadRequest)
|
||||
}
|
||||
router.ConnectionMaker.ForgetConnections(r.Form["peer"])
|
||||
router.persistPeers()
|
||||
router.ForgetConnections(r.Form["peer"])
|
||||
})
|
||||
|
||||
}
|
||||
@@ -217,11 +217,40 @@ func (router *NetworkRouter) persistPeers() {
|
||||
}
|
||||
}
|
||||
|
||||
func (router *NetworkRouter) SetInitialPeers(peers []string) []error {
|
||||
// Load is a no-op if persistence entry has never been saved
|
||||
if err := router.db.Load(peersIdent, &peers); err != nil {
|
||||
return []error{err}
|
||||
func (router *NetworkRouter) InitiateConnections(peers []string, replace bool) []error {
|
||||
errors := router.ConnectionMaker.InitiateConnections(peers, replace)
|
||||
router.persistPeers()
|
||||
return errors
|
||||
}
|
||||
|
||||
func (router *NetworkRouter) ForgetConnections(peers []string) {
|
||||
router.ConnectionMaker.ForgetConnections(peers)
|
||||
router.persistPeers()
|
||||
}
|
||||
|
||||
func (router *NetworkRouter) InitialPeers(peers []string) ([]string, error) {
|
||||
var storedPeers []string
|
||||
if err := router.db.Load(peersIdent, &storedPeers); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Println("Initiating connections to peers:", peers)
|
||||
return router.ConnectionMaker.InitiateConnections(peers, false)
|
||||
|
||||
if storedPeers != nil && !equal(peers, storedPeers) {
|
||||
log.Println("Overriding initial peer list with stored list:", storedPeers)
|
||||
peers = storedPeers
|
||||
} else {
|
||||
log.Println("Initial set of peers:", peers)
|
||||
}
|
||||
return peers, nil
|
||||
}
|
||||
|
||||
func equal(a, b []string) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
for i, v := range a {
|
||||
if v != b[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -14,7 +14,7 @@ launch_router_with_db() {
|
||||
run_on $HOST1 "sudo rm -f /tmp/test162-*"
|
||||
run_on $HOST2 "sudo rm -f /tmp/test162-*"
|
||||
|
||||
launch_router_with_db $HOST1
|
||||
launch_router_with_db $HOST1 $HOST2
|
||||
launch_router_with_db $HOST2 $HOST1
|
||||
|
||||
start_container $HOST1 --name=c1
|
||||
@@ -31,13 +31,8 @@ start_container $HOST2 --name=c3
|
||||
C3=$(container_ip $HOST2 c3)
|
||||
assert_raises "[ $C3 != $C1 ]"
|
||||
|
||||
stop_router_on $HOST2
|
||||
|
||||
# Now start HOST1 with HOST2 down and see if it hangs when we launch a container
|
||||
launch_router_with_db $HOST1 $HOST2
|
||||
start_container $HOST1 --name=c4
|
||||
C4=$(container_ip $HOST1 c4)
|
||||
assert_raises "[ $C4 != $C1 ]"
|
||||
assert_raises "[ $C4 != $C3 ]"
|
||||
# Restart HOST1 and see if it remembers to connect to HOST2
|
||||
launch_router_with_db $HOST1
|
||||
assert_raises "exec_on $HOST2 c2 $PING $C1"
|
||||
|
||||
end_suite
|
||||
Reference in new issue
Block a user