mirror of https://github.com/hashicorp/consul
Revert "local state: update documentation of updateSyncState"
This reverts commit e86521e637
.
pull/3607/merge
parent
648b4da4f8
commit
c6e441dd60
|
@ -525,7 +525,6 @@ func (l *State) CriticalCheckStates() map[types.CheckID]*CheckState {
|
||||||
func (l *State) Metadata() map[string]string {
|
func (l *State) Metadata() map[string]string {
|
||||||
l.RLock()
|
l.RLock()
|
||||||
defer l.RUnlock()
|
defer l.RUnlock()
|
||||||
|
|
||||||
m := make(map[string]string)
|
m := make(map[string]string)
|
||||||
for k, v := range l.metadata {
|
for k, v := range l.metadata {
|
||||||
m[k] = v
|
m[k] = v
|
||||||
|
@ -536,7 +535,7 @@ func (l *State) Metadata() map[string]string {
|
||||||
// updateSyncState does a read of the server state, and updates
|
// updateSyncState does a read of the server state, and updates
|
||||||
// the local sync status as appropriate
|
// the local sync status as appropriate
|
||||||
func (l *State) updateSyncState() error {
|
func (l *State) updateSyncState() error {
|
||||||
// Get all checks and services from the master
|
// 1. get all checks and services from the master
|
||||||
req := structs.NodeSpecificRequest{
|
req := structs.NodeSpecificRequest{
|
||||||
Datacenter: l.config.Datacenter,
|
Datacenter: l.config.Datacenter,
|
||||||
Node: l.config.NodeName,
|
Node: l.config.NodeName,
|
||||||
|
@ -553,7 +552,7 @@ func (l *State) updateSyncState() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create useful data structures for traversal
|
// 2. create useful data structures for traversal
|
||||||
remoteServices := make(map[string]*structs.NodeService)
|
remoteServices := make(map[string]*structs.NodeService)
|
||||||
if out1.NodeServices != nil {
|
if out1.NodeServices != nil {
|
||||||
remoteServices = out1.NodeServices.Services
|
remoteServices = out1.NodeServices.Services
|
||||||
|
@ -564,13 +563,12 @@ func (l *State) updateSyncState() error {
|
||||||
remoteChecks[rc.CheckID] = rc
|
remoteChecks[rc.CheckID] = rc
|
||||||
}
|
}
|
||||||
|
|
||||||
// Traverse all checks, services and the node info to determine
|
// 3. perform sync
|
||||||
// which entries need to be updated on or removed from the server
|
|
||||||
|
|
||||||
l.Lock()
|
l.Lock()
|
||||||
defer l.Unlock()
|
defer l.Unlock()
|
||||||
|
|
||||||
// Check if node info needs syncing
|
// sync node info
|
||||||
if out1.NodeServices == nil || out1.NodeServices.Node == nil ||
|
if out1.NodeServices == nil || out1.NodeServices.Node == nil ||
|
||||||
out1.NodeServices.Node.ID != l.config.NodeID ||
|
out1.NodeServices.Node.ID != l.config.NodeID ||
|
||||||
!reflect.DeepEqual(out1.NodeServices.Node.TaggedAddresses, l.config.TaggedAddresses) ||
|
!reflect.DeepEqual(out1.NodeServices.Node.TaggedAddresses, l.config.TaggedAddresses) ||
|
||||||
|
@ -578,30 +576,25 @@ func (l *State) updateSyncState() error {
|
||||||
l.nodeInfoInSync = false
|
l.nodeInfoInSync = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check which services need syncing
|
// sync services
|
||||||
|
|
||||||
// Look for local services that do not exist remotely and mark them for
|
// sync local services that do not exist remotely
|
||||||
// syncing so that they will be pushed to the server later
|
|
||||||
for id, s := range l.services {
|
for id, s := range l.services {
|
||||||
if remoteServices[id] == nil {
|
if remoteServices[id] == nil {
|
||||||
s.InSync = false
|
s.InSync = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Traverse the list of services from the server.
|
|
||||||
// Remote services which do not exist locally have been deregistered.
|
|
||||||
// Otherwise, check whether the two definitions are still in sync.
|
|
||||||
for id, rs := range remoteServices {
|
for id, rs := range remoteServices {
|
||||||
|
// If we don't have the service locally, deregister it
|
||||||
ls := l.services[id]
|
ls := l.services[id]
|
||||||
if ls == nil {
|
if ls == nil {
|
||||||
// The consul service is managed automatically and does
|
// The consul service is created automatically and does
|
||||||
// not need to be deregistered
|
// not need to be deregistered.
|
||||||
if id == structs.ConsulServiceID {
|
if id == structs.ConsulServiceID {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark a remote service that does not exist locally as deleted so
|
|
||||||
// that it will be removed on the server later.
|
|
||||||
l.services[id] = &ServiceState{Deleted: true}
|
l.services[id] = &ServiceState{Deleted: true}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -621,22 +614,19 @@ func (l *State) updateSyncState() error {
|
||||||
ls.InSync = ls.Service.IsSame(rs)
|
ls.InSync = ls.Service.IsSame(rs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check which checks need syncing
|
// sync checks
|
||||||
|
|
||||||
// Look for local checks that do not exist remotely and mark them for
|
// sync local checks which do not exist remotely
|
||||||
// syncing so that they will be pushed to the server later
|
|
||||||
for id, c := range l.checks {
|
for id, c := range l.checks {
|
||||||
if remoteChecks[id] == nil {
|
if remoteChecks[id] == nil {
|
||||||
c.InSync = false
|
c.InSync = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Traverse the list of checks from the server.
|
|
||||||
// Remote checks which do not exist locally have been deregistered.
|
|
||||||
// Otherwise, check whether the two definitions are still in sync.
|
|
||||||
for id, rc := range remoteChecks {
|
for id, rc := range remoteChecks {
|
||||||
lc := l.checks[id]
|
lc := l.checks[id]
|
||||||
|
|
||||||
|
// If we don't have the check locally, deregister it
|
||||||
if lc == nil {
|
if lc == nil {
|
||||||
// The Serf check is created automatically and does not
|
// The Serf check is created automatically and does not
|
||||||
// need to be deregistered.
|
// need to be deregistered.
|
||||||
|
@ -645,8 +635,6 @@ func (l *State) updateSyncState() error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark a remote check that does not exist locally as deleted so
|
|
||||||
// that it will be removed on the server later.
|
|
||||||
l.checks[id] = &CheckState{Deleted: true}
|
l.checks[id] = &CheckState{Deleted: true}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -704,8 +692,8 @@ func (l *State) SyncFull() error {
|
||||||
return l.SyncChanges()
|
return l.SyncChanges()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SyncChanges pushes checks, services and node info data which has been
|
// SyncChanges is used to scan the status our local services and checks
|
||||||
// marked out of sync or deleted to the server.
|
// and update any that are out of sync with the server
|
||||||
func (l *State) SyncChanges() error {
|
func (l *State) SyncChanges() error {
|
||||||
l.Lock()
|
l.Lock()
|
||||||
defer l.Unlock()
|
defer l.Unlock()
|
||||||
|
@ -715,7 +703,6 @@ func (l *State) SyncChanges() error {
|
||||||
// API works.
|
// API works.
|
||||||
|
|
||||||
// Sync the services
|
// Sync the services
|
||||||
// (logging happens in the helper methods)
|
|
||||||
for id, s := range l.services {
|
for id, s := range l.services {
|
||||||
var err error
|
var err error
|
||||||
switch {
|
switch {
|
||||||
|
@ -724,15 +711,13 @@ func (l *State) SyncChanges() error {
|
||||||
case !s.InSync:
|
case !s.InSync:
|
||||||
err = l.syncService(id)
|
err = l.syncService(id)
|
||||||
default:
|
default:
|
||||||
l.logger.Printf("[DEBUG] agent: Service %q in sync", id)
|
l.logger.Printf("[DEBUG] agent: Service '%s' in sync", id)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sync the checks
|
|
||||||
// (logging happens in the helper methods)
|
|
||||||
for id, c := range l.checks {
|
for id, c := range l.checks {
|
||||||
var err error
|
var err error
|
||||||
switch {
|
switch {
|
||||||
|
@ -745,7 +730,7 @@ func (l *State) SyncChanges() error {
|
||||||
}
|
}
|
||||||
err = l.syncCheck(id)
|
err = l.syncCheck(id)
|
||||||
default:
|
default:
|
||||||
l.logger.Printf("[DEBUG] agent: Check %q in sync", id)
|
l.logger.Printf("[DEBUG] agent: Check '%s' in sync", id)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -754,11 +739,15 @@ func (l *State) SyncChanges() error {
|
||||||
|
|
||||||
// Now sync the node level info if we need to, and didn't do any of
|
// Now sync the node level info if we need to, and didn't do any of
|
||||||
// the other sync operations.
|
// the other sync operations.
|
||||||
if l.nodeInfoInSync {
|
if !l.nodeInfoInSync {
|
||||||
l.logger.Printf("[DEBUG] agent: Node info in sync")
|
if err := l.syncNodeInfo(); err != nil {
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
return l.syncNodeInfo()
|
} else {
|
||||||
|
l.logger.Printf("[DEBUG] agent: Node info in sync")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadMetadata loads node metadata fields from the agent config and
|
// LoadMetadata loads node metadata fields from the agent config and
|
||||||
|
|
Loading…
Reference in New Issue