Verify: add N+1 Memory redundancy verification
authorGuido Trotter <ultrotter@google.com>
Thu, 10 Apr 2008 17:04:01 +0000 (17:04 +0000)
committerGuido Trotter <ultrotter@google.com>
Thu, 10 Apr 2008 17:04:01 +0000 (17:04 +0000)
For every node we check that we can host all the instances it's currently
secondary for belonging to the same primary. This ensures that if a node fails
all its instances can fit on their secondary node. The code only works when
failover is forced to go to the secondary node, and cannot go to an arbitrary
node in the cluster, which is the case in Ganeti 1.2.

Reviewed-by: iustinp

lib/cmdlib.py

index 674e413..6bb48f8 100644 (file)
@@ -745,6 +745,34 @@ class LUVerifyCluster(NoHooksLU):
           bad = True
     return bad
 
           bad = True
     return bad
 
+  def _VerifyNPlusOneMemory(self, node_info, instance_cfg, feedback_fn):
+    """Verify N+1 Memory Resilience.
+
+    Check that if one single node dies we can still start all the instances it
+    was primary for.
+
+    """
+    bad = False
+
+    for node, nodeinfo in node_info.iteritems():
+      # This code checks that every node which is now listed as secondary has
+      # enough memory to host all instances it is supposed to should a single
+      # other node in the cluster fail.
+      # FIXME: not ready for failover to an arbitrary node
+      # FIXME: does not support file-backed instances
+      # WARNING: we currently take into account down instances as well as up
+      # ones, considering that even if they're down someone might want to start
+      # them even in the event of a node failure.
+      for prinode, instances in nodeinfo['sinst-by-pnode'].iteritems():
+        needed_mem = 0
+        for instance in instances:
+          needed_mem += instance_cfg[instance].memory
+        if nodeinfo['mfree'] < needed_mem:
+          feedback_fn("  - ERROR: not enough memory on node %s to accomodate"
+                      " failovers should node %s fail" % (node, prinode))
+          bad = True
+    return bad
+
   def CheckPrereq(self):
     """Check prerequisites.
 
   def CheckPrereq(self):
     """Check prerequisites.
 
@@ -900,6 +928,15 @@ class LUVerifyCluster(NoHooksLU):
                                          feedback_fn)
     bad = bad or result
 
                                          feedback_fn)
     bad = bad or result
 
+    feedback_fn("* Verifying N+1 Memory redundancy")
+    result = self._VerifyNPlusOneMemory(node_info, instance_cfg, feedback_fn)
+    bad = bad or result
+
+    feedback_fn("* Other Notes")
+    if i_non_redundant:
+      feedback_fn("  - NOTICE: %d non-redundant instance(s) found."
+                  % len(i_non_redundant))
+
     return int(bad)
 
 
     return int(bad)