Due to the still existing configuration lock, modifications to the configuration can temporarily be impossible. Therefore, most configuration-modifying function return a Boolean indicating whether the change was carried out. Add a utility function to retry that change until it succeeds.
Signed-off-by: Klaus Aehlig <[email protected]> --- src/Ganeti/WConfd/Client.hs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Ganeti/WConfd/Client.hs b/src/Ganeti/WConfd/Client.hs index a477907..5272b68 100644 --- a/src/Ganeti/WConfd/Client.hs +++ b/src/Ganeti/WConfd/Client.hs @@ -38,13 +38,18 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. module Ganeti.WConfd.Client where +import Control.Concurrent (threadDelay) import Control.Exception.Lifted (bracket) +import Control.Monad (unless) +import Control.Monad.IO.Class (liftIO) -import Ganeti.THH.HsRPC +import Ganeti.BasicTypes (runResultT, GenericResult(..)) import Ganeti.Constants import Ganeti.JSON (unMaybeForJSON) import Ganeti.Locking.Locks (ClientId) import Ganeti.Objects (ConfigData) +import qualified Ganeti.Path as Path +import Ganeti.THH.HsRPC import Ganeti.UDSServer (ConnectConfig(..), Client, connectClient) import Ganeti.WConfd.Core (exportedFunctions) @@ -86,3 +91,14 @@ withLockedConfig :: ClientId withLockedConfig c shared = -- Unlock config even if something throws. bracket (waitLockConfig c shared) (const $ unlockConfig c) + + +-- | Try an RPC until no errors occur and the result is true. +runModifyRpc :: RpcClientMonad Bool -> IO () +runModifyRpc action = do + res <- runResultT $ do + wconfdClient <- liftIO $ getWConfdClient =<< Path.defaultWConfdSocket + runRpcClient action wconfdClient + unless (res == Ok True) $ do + threadDelay 100000 -- sleep 0.1 seconds + runModifyRpc action -- 2.4.3.573.g4eafbef
