Revision d316b880 src/Ganeti/Confd/Server.hs

b/src/Ganeti/Confd/Server.hs
93 93
maxIdlePollRounds = 3
94 94

  
95 95
-- | Reload timeout in microseconds.
96
configReloadTimeout :: Int
97
configReloadTimeout = C.confdConfigReloadTimeout * 1000000
96
watchInterval :: Int
97
watchInterval = C.confdConfigReloadTimeout * 1000000
98 98

  
99 99
-- | Ratelimit timeout in microseconds.
100
configReloadRatelimit :: Int
101
configReloadRatelimit = C.confdConfigReloadRatelimit
100
pollInterval :: Int
101
pollInterval = C.confdConfigReloadRatelimit
102 102

  
103 103
-- | Ratelimit timeout in microseconds, as an 'Integer'.
104 104
reloadRatelimit :: Integer
......
263 263
moveToPolling msg inotify path cref mstate = do
264 264
  logInfo $ "Moving to polling mode: " ++ msg
265 265
  let inotiaction = addNotifier inotify path cref mstate
266
  _ <- forkIO $ onReloadTimer inotiaction path cref mstate
266
  _ <- forkIO $ onPollTimer inotiaction path cref mstate
267 267
  return initialPoll
268 268

  
269 269
-- | Helper function for logging transition into inotify mode.
......
332 332
-- $watcher
333 333
-- We have three threads/functions that can mutate the server state:
334 334
--
335
-- 1. the long-interval watcher ('onTimeoutTimer')
335
-- 1. the long-interval watcher ('onWatcherTimer')
336 336
--
337
-- 2. the polling watcher ('onReloadTimer')
337
-- 2. the polling watcher ('onPollTimer')
338 338
--
339 339
-- 3. the inotify event handler ('onInotify')
340 340
--
......
348 348
-- | Long-interval reload watcher.
349 349
--
350 350
-- This is on top of the inotify-based triggered reload.
351
onTimeoutTimer :: IO Bool -> FilePath -> CRef -> MVar ServerState -> IO ()
352
onTimeoutTimer inotiaction path cref state = do
353
  threadDelay configReloadTimeout
351
onWatcherTimer :: IO Bool -> FilePath -> CRef -> MVar ServerState -> IO ()
352
onWatcherTimer inotiaction path cref state = do
353
  threadDelay watchInterval
354 354
  logDebug "Watcher timer fired"
355
  modifyMVar_ state (onTimeoutInner path cref)
355
  modifyMVar_ state (onWatcherInner path cref)
356 356
  _ <- inotiaction
357
  onTimeoutTimer inotiaction path cref state
357
  onWatcherTimer inotiaction path cref state
358 358

  
359
-- | Inner onTimeout handler.
359
-- | Inner onWatcher handler.
360 360
--
361 361
-- This mutates the server state under a modifyMVar_ call. It never
362 362
-- changes the reload model, just does a safety reload and tried to
363 363
-- re-establish the inotify watcher.
364
onTimeoutInner :: FilePath -> CRef -> ServerState -> IO ServerState
365
onTimeoutInner path cref state  = do
364
onWatcherInner :: FilePath -> CRef -> ServerState -> IO ServerState
365
onWatcherInner path cref state  = do
366 366
  (newfstat, _) <- safeUpdateConfig path (reloadFStat state) cref
367 367
  return state { reloadFStat = newfstat }
368 368

  
......
371 371
-- This is only active when we're in polling mode; it will
372 372
-- automatically exit when it detects that the state has changed to
373 373
-- notification.
374
onReloadTimer :: IO Bool -> FilePath -> CRef -> MVar ServerState -> IO ()
375
onReloadTimer inotiaction path cref state = do
376
  threadDelay configReloadRatelimit
377
  logDebug "Reload timer fired"
378
  continue <- modifyMVar state (onReloadInner inotiaction path cref)
374
onPollTimer :: IO Bool -> FilePath -> CRef -> MVar ServerState -> IO ()
375
onPollTimer inotiaction path cref state = do
376
  threadDelay pollInterval
377
  logDebug "Poll timer fired"
378
  continue <- modifyMVar state (onPollInner inotiaction path cref)
379 379
  if continue
380
    then onReloadTimer inotiaction path cref state
380
    then onPollTimer inotiaction path cref state
381 381
    else logDebug "Inotify watch active, polling thread exiting"
382 382

  
383
-- | Inner onReload handler.
383
-- | Inner onPoll handler.
384 384
--
385 385
-- This again mutates the state under a modifyMVar call, and also
386 386
-- returns whether the thread should continue or not.
387
onReloadInner :: IO Bool -> FilePath -> CRef -> ServerState
387
onPollInner :: IO Bool -> FilePath -> CRef -> ServerState
388 388
              -> IO (ServerState, Bool)
389
onReloadInner _ _ _ state@(ServerState { reloadModel = ReloadNotify } ) =
389
onPollInner _ _ _ state@(ServerState { reloadModel = ReloadNotify } ) =
390 390
  return (state, False)
391
onReloadInner inotiaction path cref
392
              state@(ServerState { reloadModel = ReloadPoll pround } ) = do
391
onPollInner inotiaction path cref
392
            state@(ServerState { reloadModel = ReloadPoll pround } ) = do
393 393
  (newfstat, reload) <- safeUpdateConfig path (reloadFStat state) cref
394 394
  let state' = state { reloadFStat = newfstat }
395 395
  -- compute new poll model based on reload data; however, failure to
......
545 545
        (\state -> return state { reloadModel = initialPoll })
546 546
  hmac <- getClusterHmac
547 547
  -- fork the timeout timer
548
  _ <- forkIO $ onTimeoutTimer inotiaction conf_file cref statemvar
548
  _ <- forkIO $ onWatcherTimer inotiaction conf_file cref statemvar
549 549
  -- fork the polling timer
550 550
  unless has_inotify $ do
551
    _ <- forkIO $ onReloadTimer inotiaction conf_file cref statemvar
551
    _ <- forkIO $ onPollTimer inotiaction conf_file cref statemvar
552 552
    return ()
553 553
  -- launch the queryd listener
554 554
  _ <- forkIO $ runQueryD query_data (configReader cref)

Also available in: Unified diff