-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
consul: Adding merge delegate to prevent mixing clusters
- Loading branch information
Showing
4 changed files
with
115 additions
and
2 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
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,56 @@ | ||
package consul | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/hashicorp/serf/serf" | ||
) | ||
|
||
// lanMergeDelegate is used to handle a cluster merge on the LAN gossip | ||
// 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) { | ||
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'", | ||
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'", | ||
m.Name, parts.Datacenter) | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
// 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) { | ||
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 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