|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
package consul
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"log"
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/serf/serf"
|
|
|
|
|
)
|
|
|
|
@ -10,47 +10,41 @@ import (
|
|
|
|
|
// ring. We check that the peers are in the same datacenter and abort the
|
|
|
|
|
// merge if there is a mis-match.
|
|
|
|
|
type lanMergeDelegate struct {
|
|
|
|
|
logger *log.Logger
|
|
|
|
|
dc string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (md *lanMergeDelegate) NotifyMerge(members []*serf.Member) (cancel bool) {
|
|
|
|
|
func (md *lanMergeDelegate) NotifyMerge(members []*serf.Member) error {
|
|
|
|
|
for _, m := range members {
|
|
|
|
|
ok, dc := isConsulNode(*m)
|
|
|
|
|
if ok {
|
|
|
|
|
if dc != md.dc {
|
|
|
|
|
md.logger.Printf("[WARN] consul: Canceling cluster merge, member '%s' part of wrong datacenter '%s'",
|
|
|
|
|
return fmt.Errorf("Member '%s' part of wrong datacenter '%s'",
|
|
|
|
|
m.Name, dc)
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ok, parts := isConsulServer(*m)
|
|
|
|
|
if ok && parts.Datacenter != md.dc {
|
|
|
|
|
md.logger.Printf("[WARN] consul: Canceling cluster merge, member '%s' part of wrong datacenter '%s'",
|
|
|
|
|
return fmt.Errorf("Member '%s' part of wrong datacenter '%s'",
|
|
|
|
|
m.Name, parts.Datacenter)
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// wanMergeDelegate is used to handle a cluster merge on the WAN gossip
|
|
|
|
|
// ring. We check that the peers are server nodes and abort the merge
|
|
|
|
|
// otherwise.
|
|
|
|
|
type wanMergeDelegate struct {
|
|
|
|
|
logger *log.Logger
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (md *wanMergeDelegate) NotifyMerge(members []*serf.Member) (cancel bool) {
|
|
|
|
|
func (md *wanMergeDelegate) NotifyMerge(members []*serf.Member) error {
|
|
|
|
|
for _, m := range members {
|
|
|
|
|
ok, _ := isConsulServer(*m)
|
|
|
|
|
if !ok {
|
|
|
|
|
md.logger.Printf("[WARN] consul: Canceling cluster merge, member '%s' is not a server",
|
|
|
|
|
m.Name)
|
|
|
|
|
return true
|
|
|
|
|
return fmt.Errorf("Member '%s' is not a server", m.Name)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|