mirror of https://github.com/status-im/consul.git
consul: Rename to LAN/WAN instead of Local/Remote
This commit is contained in:
parent
7fbd8ba370
commit
b8bc9d2027
|
@ -12,9 +12,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
serfLocalSnapshot = "serf/local.snapshot"
|
serfLANSnapshot = "serf/local.snapshot"
|
||||||
serfRemoteSnapshot = "serf/remote.snapshot"
|
serfWANSnapshot = "serf/remote.snapshot"
|
||||||
raftState = "raft/"
|
raftState = "raft/"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server is Consul server which manages the service discovery,
|
// Server is Consul server which manages the service discovery,
|
||||||
|
@ -22,13 +22,13 @@ const (
|
||||||
type Server struct {
|
type Server struct {
|
||||||
config *Config
|
config *Config
|
||||||
|
|
||||||
// eventChLocal is used to receive events from the
|
// eventChLAN is used to receive events from the
|
||||||
// serfLocal cluster
|
// serf cluster in the datacenter
|
||||||
eventChLocal chan serf.Event
|
eventChLAN chan serf.Event
|
||||||
|
|
||||||
// eventChRemote is used to receive events from the
|
// eventChWAN is used to receive events from the
|
||||||
// serfRemote cluster
|
// serf cluster that spans datacenters
|
||||||
eventChRemote chan serf.Event
|
eventChWAN chan serf.Event
|
||||||
|
|
||||||
// fsm is the state machine used with Raft to provide
|
// fsm is the state machine used with Raft to provide
|
||||||
// strong consistency.
|
// strong consistency.
|
||||||
|
@ -43,13 +43,13 @@ type Server struct {
|
||||||
raftStore *raft.SQLiteStore
|
raftStore *raft.SQLiteStore
|
||||||
raftTransport *raft.NetworkTransport
|
raftTransport *raft.NetworkTransport
|
||||||
|
|
||||||
// serfLocal is the Serf cluster maintained inside the DC
|
// serfLAN is the Serf cluster maintained inside the DC
|
||||||
// which contains all the DC nodes
|
// which contains all the DC nodes
|
||||||
serfLocal *serf.Serf
|
serfLAN *serf.Serf
|
||||||
|
|
||||||
// serfRemote is the Serf cluster maintained between DC's
|
// serfWAN is the Serf cluster maintained between DC's
|
||||||
// which SHOULD only consist of Consul servers
|
// which SHOULD only consist of Consul servers
|
||||||
serfRemote *serf.Serf
|
serfWAN *serf.Serf
|
||||||
|
|
||||||
shutdown bool
|
shutdown bool
|
||||||
shutdownCh chan struct{}
|
shutdownCh chan struct{}
|
||||||
|
@ -74,30 +74,32 @@ func NewServer(config *Config) (*Server, error) {
|
||||||
|
|
||||||
// Create server
|
// Create server
|
||||||
s := &Server{
|
s := &Server{
|
||||||
config: config,
|
config: config,
|
||||||
eventChLocal: make(chan serf.Event, 256),
|
eventChLAN: make(chan serf.Event, 256),
|
||||||
eventChRemote: make(chan serf.Event, 256),
|
eventChWAN: make(chan serf.Event, 256),
|
||||||
logger: logger,
|
logger: logger,
|
||||||
shutdownCh: make(chan struct{}),
|
shutdownCh: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the Serf listeners to prevent a deadlock
|
// Start the Serf listeners to prevent a deadlock
|
||||||
go s.localEventHandler()
|
go s.lanEventHandler()
|
||||||
go s.remoteEventHandler()
|
go s.wanEventHandler()
|
||||||
|
|
||||||
// Initialize the local Serf
|
// Initialize the lan Serf
|
||||||
var err error
|
var err error
|
||||||
s.serfLocal, err = s.setupSerf(config.SerfLocalConfig, s.eventChLocal, serfLocalSnapshot)
|
s.serfLAN, err = s.setupSerf(config.SerfLocalConfig,
|
||||||
|
s.eventChLAN, serfLANSnapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.Shutdown()
|
s.Shutdown()
|
||||||
return nil, fmt.Errorf("Failed to start local serf: %v", err)
|
return nil, fmt.Errorf("Failed to start lan serf: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the remote Serf
|
// Initialize the wan Serf
|
||||||
s.serfRemote, err = s.setupSerf(config.SerfRemoteConfig, s.eventChRemote, serfRemoteSnapshot)
|
s.serfWAN, err = s.setupSerf(config.SerfRemoteConfig,
|
||||||
|
s.eventChWAN, serfWANSnapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.Shutdown()
|
s.Shutdown()
|
||||||
return nil, fmt.Errorf("Failed to start remote serf: %v", err)
|
return nil, fmt.Errorf("Failed to start wan serf: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the Raft server
|
// Initialize the Raft server
|
||||||
|
@ -193,14 +195,14 @@ func (s *Server) Shutdown() error {
|
||||||
s.shutdown = true
|
s.shutdown = true
|
||||||
close(s.shutdownCh)
|
close(s.shutdownCh)
|
||||||
|
|
||||||
if s.serfLocal != nil {
|
if s.serfLAN != nil {
|
||||||
s.serfLocal.Shutdown()
|
s.serfLAN.Shutdown()
|
||||||
s.serfLocal = nil
|
s.serfLAN = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.serfRemote != nil {
|
if s.serfWAN != nil {
|
||||||
s.serfRemote.Shutdown()
|
s.serfWAN.Shutdown()
|
||||||
s.serfRemote = nil
|
s.serfWAN = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.raft != nil {
|
if s.raft != nil {
|
||||||
|
@ -214,10 +216,26 @@ func (s *Server) Shutdown() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// localEventHandler is used to handle events from the local Serf cluster
|
// lanEventHandler is used to handle events from the lan Serf cluster
|
||||||
func (s *Server) localEventHandler() {
|
func (s *Server) lanEventHandler() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case e := <-s.eventChLAN:
|
||||||
|
s.logger.Printf("[INFO] LAN Event: %v", e)
|
||||||
|
case <-s.shutdownCh:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// remoteEventHandler is used to handle events from the remote Serf cluster
|
// wanEventHandler is used to handle events from the wan Serf cluster
|
||||||
func (s *Server) remoteEventHandler() {
|
func (s *Server) wanEventHandler() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case e := <-s.eventChWAN:
|
||||||
|
s.logger.Printf("[INFO] WAN Event: %v", e)
|
||||||
|
case <-s.shutdownCh:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue