Fix interaction between down instances and nodes
authorIustin Pop <iustin@google.com>
Sun, 22 Mar 2009 10:40:58 +0000 (11:40 +0100)
committerIustin Pop <iustin@google.com>
Sun, 22 Mar 2009 10:40:58 +0000 (11:40 +0100)
If an instance is down, it's memory is not reflected in the node used
memory, and thus the node free memory is higher than the actual value.
This patch deducts the memory for such instances from the node free
memory, allowing a correct calculation for such cases.

Ganeti/HTools/Cluster.hs
Ganeti/HTools/Node.hs
hscan.hs

index 07d7c8e..73c814a 100644 (file)
@@ -792,15 +792,20 @@ nodeImem node il =
 -- | Check cluster data for consistency
 checkData :: NodeList -> InstanceList -> NameList -> NameList
           -> ([String], NodeList)
-checkData nl il ktn kti =
+checkData nl il ktn _ =
     Container.mapAccum
         (\ msgs node ->
              let nname = fromJust $ lookup (Node.idx node) ktn
-                 delta_mem = (truncate $ Node.t_mem node) -
-                             (Node.n_mem node) -
-                             (Node.f_mem node) -
-                             (nodeImem node il)
-                 newn = Node.setXmem node delta_mem
+                 nilst = map (flip Container.find $ il) (Node.plist node)
+                 dilst = filter (not . Instance.running) nilst
+                 adj_mem = sum . map Instance.mem $ dilst
+                 delta_mem = (truncate $ Node.t_mem node)
+                             - (Node.n_mem node)
+                             - (Node.f_mem node)
+                             - (nodeImem node il)
+                             + adj_mem
+                 newn = Node.setFmem (Node.setXmem node delta_mem)
+                        (Node.f_mem node - adj_mem)
                  umsg = if delta_mem > 16
                         then (printf "node %s has %6d MB of unaccounted \
                                      \memory "
index c18b21b..cbc2117 100644 (file)
@@ -16,6 +16,7 @@ module Ganeti.HTools.Node
     , setIdx
     , setOffline
     , setXmem
+    , setFmem
     -- * Instance (re)location
     , removePri
     , removeSec
@@ -98,6 +99,10 @@ setOffline t val = t { offline = val }
 setXmem :: Node -> Int -> Node
 setXmem t val = t { x_mem = val }
 
+-- | Sets the free memory
+setFmem :: Node -> Int -> Node
+setFmem t val = t { f_mem = val }
+
 -- | Given the rmem, free memory and disk, computes the failn1 status.
 computeFailN1 :: Int -> Int -> Int -> Bool
 computeFailN1 new_rmem new_mem new_dsk =
index 37f72b0..e9c2981 100644 (file)
--- a/hscan.hs
+++ b/hscan.hs
@@ -162,9 +162,9 @@ main = do
                           idata = fromRight inst_data
                           (nl, il, csf, ktn, kti) =
                               Cluster.loadData ndata idata
-                      putStrLn $ printCluster nl il ktn kti
+                          (_, fix_nl) = Cluster.checkData nl il ktn kti
+                      putStrLn $ printCluster fix_nl il ktn kti
                       when (optShowNodes opts) $ do
-                           let (_, fix_nl) = Cluster.checkData nl il ktn kti
                            putStr $ Cluster.printNodes ktn fix_nl
                       let ndata = serializeNodes nl csf ktn
                           idata = serializeInstances il csf ktn kti