mirror of https://github.com/status-im/consul.git
agent: adding ability to pause syncing
This commit is contained in:
parent
d64fda8d45
commit
01b1104175
|
@ -6,6 +6,7 @@ import (
|
|||
"log"
|
||||
"reflect"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -24,6 +25,10 @@ type syncStatus struct {
|
|||
// and checks. We used it to perform anti-entropy with the
|
||||
// catalog representation
|
||||
type localState struct {
|
||||
// paused is used to check if we are paused. Must be the first
|
||||
// element due to a go bug.
|
||||
paused int32
|
||||
|
||||
sync.Mutex
|
||||
logger *log.Logger
|
||||
|
||||
|
@ -66,6 +71,23 @@ func (l *localState) changeMade() {
|
|||
}
|
||||
}
|
||||
|
||||
// Pause is used to pause state syncronization, this can be
|
||||
// used to make batch changes
|
||||
func (l *localState) Pause() {
|
||||
atomic.StoreInt32(&l.paused, 1)
|
||||
}
|
||||
|
||||
// Unpause is used to resume state syncronization
|
||||
func (l *localState) Unpause() {
|
||||
atomic.StoreInt32(&l.paused, 0)
|
||||
l.changeMade()
|
||||
}
|
||||
|
||||
// isPaused is used to check if we are paused
|
||||
func (l *localState) isPaused() bool {
|
||||
return atomic.LoadInt32(&l.paused) == 1
|
||||
}
|
||||
|
||||
// AddService is used to add a service entry to the local state.
|
||||
// This entry is persistent and the agent will make a best effort to
|
||||
// ensure it is registered
|
||||
|
@ -200,6 +222,10 @@ SYNC:
|
|||
case <-aeTimer:
|
||||
goto SYNC
|
||||
case <-l.triggerCh:
|
||||
// Skip the sync if we are paused
|
||||
if l.isPaused() {
|
||||
continue
|
||||
}
|
||||
if err := l.syncChanges(); err != nil {
|
||||
l.logger.Printf("[ERR] agent: failed to sync changes: %v", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue