Cleans up state management for remote deletes from local state.

Fixes #2125.
This commit is contained in:
James Phillips 2016-09-21 16:52:43 -07:00
parent 6f0a3b9bf5
commit c8ce41f459
No known key found for this signature in database
GPG Key ID: 77183E682AC5FC11
1 changed files with 7 additions and 8 deletions

View File

@ -26,8 +26,7 @@ const (
// syncStatus is used to represent the difference between
// the local and remote state, and if action needs to be taken
type syncStatus struct {
remoteDelete bool // Should this be deleted from the server
inSync bool // Is this in sync with the server
inSync bool // Is this in sync with the server
}
// localState is used to represent the node's services,
@ -177,7 +176,7 @@ func (l *localState) RemoveService(serviceID string) {
delete(l.services, serviceID)
delete(l.serviceTokens, serviceID)
l.serviceStatus[serviceID] = syncStatus{remoteDelete: true}
l.serviceStatus[serviceID] = syncStatus{inSync: false}
l.changeMade()
}
@ -237,7 +236,7 @@ func (l *localState) RemoveCheck(checkID types.CheckID) {
delete(l.checks, checkID)
delete(l.checkTokens, checkID)
delete(l.checkCriticalTime, checkID)
l.checkStatus[checkID] = syncStatus{remoteDelete: true}
l.checkStatus[checkID] = syncStatus{inSync: false}
l.changeMade()
}
@ -434,7 +433,7 @@ func (l *localState) setSyncState() error {
// If we don't have the service locally, deregister it
existing, ok := l.services[id]
if !ok {
l.serviceStatus[id] = syncStatus{remoteDelete: true}
l.serviceStatus[id] = syncStatus{inSync: false}
continue
}
@ -472,7 +471,7 @@ func (l *localState) setSyncState() error {
if id == consul.SerfCheckID {
continue
}
l.checkStatus[id] = syncStatus{remoteDelete: true}
l.checkStatus[id] = syncStatus{inSync: false}
continue
}
@ -521,7 +520,7 @@ func (l *localState) syncChanges() error {
// Sync the services
for id, status := range l.serviceStatus {
if status.remoteDelete {
if _, ok := l.services[id]; !ok {
if err := l.deleteService(id); err != nil {
return err
}
@ -536,7 +535,7 @@ func (l *localState) syncChanges() error {
// Sync the checks
for id, status := range l.checkStatus {
if status.remoteDelete {
if _, ok := l.checks[id]; !ok {
if err := l.deleteCheck(id); err != nil {
return err
}