LGTM

On Thu, Mar 6, 2014 at 2:37 PM, Klaus Aehlig <[email protected]> wrote:

> Provide a task that periodically checks for all locks
> owners whether they are still alive. If not, it cleans
> up their locks.
>
> Signed-off-by: Klaus Aehlig <[email protected]>
> ---
>  src/Ganeti/WConfd/DeathDetection.hs | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
>
> diff --git a/src/Ganeti/WConfd/DeathDetection.hs
> b/src/Ganeti/WConfd/DeathDetection.hs
> index 54a7cdc..2c7ecec 100644
> --- a/src/Ganeti/WConfd/DeathDetection.hs
> +++ b/src/Ganeti/WConfd/DeathDetection.hs
> @@ -32,14 +32,20 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor,
> Boston, MA
>
>  module Ganeti.WConfd.DeathDetection
>    ( isDead
> +  , cleanupLocksTask
>    ) where
>
> +import Control.Concurrent (threadDelay)
>  import Control.Monad
>  import System.Directory
>  import System.IO
>  import System.Posix.IO
>
>  import Ganeti.BasicTypes
> +import qualified Ganeti.Constants as C
> +import qualified Ganeti.Locking.Allocation as L
> +import Ganeti.Logging.Lifted (logDebug, logInfo)
> +import Ganeti.WConfd.Monad
>
>  -- | Detect whether a the process identified by the given path
>  -- does not exist any more. This function never fails and only
> @@ -54,3 +60,21 @@ isDead fpath = fmap (isOk :: Result () -> Bool) .
> runResultT . liftIO $ do
>      fd <- handleToFd handle
>      setLock fd (ReadLock, AbsoluteSeek, 0, 0)
>      closeFd fd
> +
> +-- | Interval to run clean-up tasks in microseconds
> +cleanupInterval :: Int
> +cleanupInterval = C.wconfdDeathdetectionIntervall * 1000000
> +
> +-- | Thread periodically cleaning up locks of lock owners that died.
> +cleanupLocksTask :: WConfdMonadInt ()
> +cleanupLocksTask = forever . runResultT $ do
> +  logDebug "Death detection timer fired"
> +  owners <- liftM L.lockOwners readLockAllocation
> +  logDebug $ "Current lock owners: " ++ show owners
> +  let cleanupIfDead owner@(_, fpath) = do
> +        died <- liftIO (isDead fpath)
> +        when died $ do
> +          logInfo $ show owner ++ " died, releasing locks"
> +          modifyLockAllocation_ (`L.freeLocks` owner)
> +  mapM_ cleanupIfDead owners
> +  liftIO $ threadDelay cleanupInterval
> --
> 1.9.0.279.gdc9e3eb
>
>

Reply via email to