From 43e9a7b6c45ad698c8925761f9f4931edc98c0ae Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Thu, 21 Jul 2011 21:45:46 +1000 Subject: [PATCH] IP allocation simulation - add -H/-S options for hard/soft imbalance limit. An imbalance exceeding the hard limit, as specified by -H (and defaulting to 1), now causes termination when -x is specified. Imbalances exceeding the soft limit, as specified by -S (and defaulting to 1), are counted and printed in the statistics summary. A side-effect is that imbalances less than 2 are no longer rounded down to 0, since we want to see them in the stats. Signed-off-by: Martin Schwenke (This used to be ctdb commit b5e9a4c50eedb8cc786c52af06352788ca25f51e) --- ctdb/tests/takeover/ctdb_takeover.py | 32 +++++++++++++++++++--------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/ctdb/tests/takeover/ctdb_takeover.py b/ctdb/tests/takeover/ctdb_takeover.py index 00966c3f08d..bcc132a2e9c 100755 --- a/ctdb/tests/takeover/ctdb_takeover.py +++ b/ctdb/tests/takeover/ctdb_takeover.py @@ -82,7 +82,13 @@ def process_args(extra_options=[]): parser.add_option("-x", "--exit", action="store_true", dest="exit", default=False, - help="exit on the 1st gratuitous IP move") + help="exit on the 1st gratuitous IP move or IP imbalance") + parser.add_option("-H", "--hard-imbalance-limit", + action="store", type="int", dest="hard_limit", default=1, + help="exceeding this limit causes termination [default: %default]") + parser.add_option("-S", "--soft-imbalance-limit", + action="store", type="int", dest="soft_limit", default=1, + help="exceeding this limit increments a counter [default: %default]") (options, args) = parser.parse_args() @@ -219,6 +225,7 @@ class Cluster(object): self.ip_moves = [] self.grat_ip_moves = [] self.imbalance = [] + self.imbalance_count = 0 self.events = -1 self.num_unhealthy = [] @@ -234,12 +241,13 @@ class Cluster(object): def print_statistics(self): print_begin("STATISTICS") - print "Events: %6d" % self.events - print "Total IP moves: %6d" % sum(self.ip_moves) - print "Gratuitous IP moves: %6d" % sum(self.grat_ip_moves) - print "Max imbalance: %6d" % max(self.imbalance) - print "Final imbalance: %6d" % self.imbalance[-1] - print "Maximum unhealthy: %6d" % max(self.num_unhealthy) + print "Events: %6d" % self.events + print "Total IP moves: %6d" % sum(self.ip_moves) + print "Gratuitous IP moves: %6d" % sum(self.grat_ip_moves) + print "Max imbalance: %6d" % max(self.imbalance) + print "Final imbalance: %6d" % self.imbalance[-1] + print "Soft imbalance count: %6d" % self.imbalance_count + print "Maximum unhealthy: %6d" % max(self.num_unhealthy) print_end() def find_pnn_with_ip(self, ip): @@ -349,8 +357,8 @@ class Cluster(object): continue i = maxnum - minnum - if maxnum - minnum < 2: - i = 0 + #if i < 2: + # i = 0 imbalance = max([imbalance, i]) return imbalance @@ -688,6 +696,9 @@ class Cluster(object): imbalance = self.calculate_imbalance() self.imbalance.append(imbalance) + if imbalance > options.soft_limit: + self.imbalance_count += 1 + if options.balance: print_begin("IMBALANCE") print imbalance @@ -705,4 +716,5 @@ class Cluster(object): self.prev = None self.prev = copy.deepcopy(self) - return grat_ip_moves + return grat_ip_moves or \ + imbalance > options.hard_limit -- 2.34.1