Refactor locking code in lease tidy; add ending debug statements

This commit is contained in:
vishalnayak 2017-04-27 16:22:19 -04:00
parent d8e91ef616
commit 72d05cd8dd
2 changed files with 15 additions and 9 deletions

View File

@ -123,6 +123,15 @@ func (c *Core) stopExpiration() error {
func (m *ExpirationManager) Tidy() error {
var tidyErrors *multierror.Error
if !atomic.CompareAndSwapInt64(&m.tidyLock, 0, 1) {
m.logger.Debug("expiration: tidy operation on leases is already in progress")
return fmt.Errorf("tidy operation on leases is already in progress")
}
defer atomic.CompareAndSwapInt64(&m.tidyLock, 1, 0)
m.logger.Debug("expiration: beginning tidy operation on leases")
// Create a cache to keep track of looked up tokens
tokenCache := make(map[string]bool)
i := 0
@ -191,17 +200,12 @@ func (m *ExpirationManager) Tidy() error {
}
}
if atomic.CompareAndSwapInt64(&m.tidyLock, 0, 1) {
m.logger.Debug("expiration: beginning tidy operation on leases")
defer atomic.CompareAndSwapInt64(&m.tidyLock, 1, 0)
if err := logical.ScanView(m.idView, tidyFunc); err != nil {
return err
}
} else {
m.logger.Debug("expiration: tidy operation on leases is already in progress")
return fmt.Errorf("tidy operation on leases is already in progress")
if err := logical.ScanView(m.idView, tidyFunc); err != nil {
return err
}
m.logger.Debug("expiration: ending tidy operation on leases")
return tidyErrors.ErrorOrNil()
}

View File

@ -1239,6 +1239,8 @@ func (ts *TokenStore) handleTidy(req *logical.Request, data *framework.FieldData
}
}
ts.logger.Debug("token_store: ending tidy operation on tokens")
return nil, tidyErrors.ErrorOrNil()
}