Revision 7e7fa841
b/lib/constants.py | ||
---|---|---|
1 | 1 |
# |
2 | 2 |
# |
3 | 3 |
|
4 |
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Google Inc. |
|
4 |
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Google Inc.
|
|
5 | 5 |
# |
6 | 6 |
# This program is free software; you can redistribute it and/or modify |
7 | 7 |
# it under the terms of the GNU General Public License as published by |
... | ... | |
2194 | 2194 |
# TODO: make this a default and allow the value to be more configurable |
2195 | 2195 |
CONFD_MAX_CLOCK_SKEW = 2 * NODE_MAX_CLOCK_SKEW |
2196 | 2196 |
|
2197 |
# When we haven't reloaded the config for more than this amount of seconds, we |
|
2198 |
# force a test to see if inotify is betraying us. |
|
2199 |
CONFD_CONFIG_RELOAD_TIMEOUT = 60 |
|
2197 |
# When we haven't reloaded the config for more than this amount of |
|
2198 |
# seconds, we force a test to see if inotify is betraying us. Using a |
|
2199 |
# prime number to ensure we get less chance of 'same wakeup' with |
|
2200 |
# other processes. |
|
2201 |
CONFD_CONFIG_RELOAD_TIMEOUT = 17 |
|
2200 | 2202 |
|
2201 |
# If we receive more than one update in this amount of seconds, we move to
|
|
2202 |
# polling every RATELIMIT seconds, rather than relying on inotify, to be able
|
|
2203 |
# to serve more requests. |
|
2204 |
CONFD_CONFIG_RELOAD_RATELIMIT = 2 |
|
2203 |
# If we receive more than one update in this amount of microseconds,
|
|
2204 |
# we move to polling every RATELIMIT seconds, rather than relying on
|
|
2205 |
# inotify, to be able to serve more requests.
|
|
2206 |
CONFD_CONFIG_RELOAD_RATELIMIT = 250000
|
|
2205 | 2207 |
|
2206 | 2208 |
# Magic number prepended to all confd queries. |
2207 | 2209 |
# This allows us to distinguish different types of confd protocols and handle |
b/src/Ganeti/Confd/Server.hs | ||
---|---|---|
84 | 84 |
-- | Server state data type. |
85 | 85 |
data ServerState = ServerState |
86 | 86 |
{ reloadModel :: ReloadModel |
87 |
, reloadTime :: Integer |
|
87 |
, reloadTime :: Integer -- ^ Reload time (epoch) in microseconds
|
|
88 | 88 |
, reloadFStat :: FStat |
89 | 89 |
} |
90 | 90 |
|
... | ... | |
98 | 98 |
|
99 | 99 |
-- | Ratelimit timeout in microseconds. |
100 | 100 |
configReloadRatelimit :: Int |
101 |
configReloadRatelimit = C.confdConfigReloadRatelimit * 1000000
|
|
101 |
configReloadRatelimit = C.confdConfigReloadRatelimit |
|
102 | 102 |
|
103 |
-- | Ratelimit timeout in seconds, as an 'Integer'. |
|
104 |
reloadRatelimitSec :: Integer
|
|
105 |
reloadRatelimitSec = fromIntegral C.confdConfigReloadRatelimit
|
|
103 |
-- | Ratelimit timeout in microseconds, as an 'Integer'.
|
|
104 |
reloadRatelimit :: Integer |
|
105 |
reloadRatelimit = fromIntegral C.confdConfigReloadRatelimit |
|
106 | 106 |
|
107 | 107 |
-- | Initial poll round. |
108 | 108 |
initialPoll :: ReloadModel |
... | ... | |
351 | 351 |
onTimeoutTimer :: IO Bool -> FilePath -> CRef -> MVar ServerState -> IO () |
352 | 352 |
onTimeoutTimer inotiaction path cref state = do |
353 | 353 |
threadDelay configReloadTimeout |
354 |
logDebug "Watcher timer fired" |
|
354 | 355 |
modifyMVar_ state (onTimeoutInner path cref) |
355 | 356 |
_ <- inotiaction |
356 | 357 |
onTimeoutTimer inotiaction path cref state |
... | ... | |
372 | 373 |
-- notification. |
373 | 374 |
onReloadTimer :: IO Bool -> FilePath -> CRef -> MVar ServerState -> IO () |
374 | 375 |
onReloadTimer inotiaction path cref state = do |
376 |
logDebug "Reload timer fired" |
|
375 | 377 |
continue <- modifyMVar state (onReloadInner inotiaction path cref) |
376 | 378 |
when continue $ |
377 | 379 |
do threadDelay configReloadRatelimit |
... | ... | |
440 | 442 |
modifyMVar_ mstate $ \state -> |
441 | 443 |
if reloadModel state == ReloadNotify |
442 | 444 |
then do |
443 |
ctime <- getCurrentTime |
|
445 |
ctime <- getCurrentTimeUSec
|
|
444 | 446 |
(newfstat, _) <- safeUpdateConfig path (reloadFStat state) cref |
445 | 447 |
let state' = state { reloadFStat = newfstat, reloadTime = ctime } |
446 |
if abs (reloadTime state - ctime) < reloadRatelimitSec
|
|
448 |
if abs (reloadTime state - ctime) < reloadRatelimit |
|
447 | 449 |
then do |
448 | 450 |
mode <- moveToPolling "too many reloads" inotify path cref mstate |
449 | 451 |
return state' { reloadModel = mode } |
Also available in: Unified diff