diff --git a/drivers/cleanup.py b/drivers/cleanup.py index 9fbd3c4ad..5a22544c0 100755 --- a/drivers/cleanup.py +++ b/drivers/cleanup.py @@ -1957,7 +1957,7 @@ def _coalesce(self, vdi): self.deleteVDI(vdi) class CoalesceTracker: - GRACE_ITERATIONS = 1 + GRACE_ITERATIONS = 2 MAX_ITERATIONS_NO_PROGRESS = 3 MAX_ITERATIONS = 10 MAX_INCREASE_FROM_MINIMUM = 1.2 @@ -1973,10 +1973,9 @@ def __init__(self, sr): self.startSize = None self.finishSize = None self.sr = sr + self.grace_remaining = self.GRACE_ITERATIONS def abortCoalesce(self, prevSize, curSize): - res = False - self.its += 1 self.history.append(self.HISTORY_STRING.format(its=self.its, initSize=prevSize, @@ -1993,33 +1992,38 @@ def abortCoalesce(self, prevSize, curSize): if prevSize < self.minSize: self.minSize = prevSize + if self.its == 1: + # Skip evaluating conditions on first iteration + return False + if prevSize < curSize: self.itsNoProgress += 1 Util.log("No progress, attempt:" " {attempt}".format(attempt=self.itsNoProgress)) util.fistpoint.activate("cleanup_tracker_no_progress", self.sr.uuid) - if (not res) and (self.its > self.MAX_ITERATIONS): + if self.its > self.MAX_ITERATIONS: max = self.MAX_ITERATIONS self.reason = \ "Max iterations ({max}) exceeded".format(max=max) - res = True + return True - if (not res) and (self.itsNoProgress > - self.MAX_ITERATIONS_NO_PROGRESS): + if self.itsNoProgress > self.MAX_ITERATIONS_NO_PROGRESS: max = self.MAX_ITERATIONS_NO_PROGRESS self.reason = \ "No progress made for {max} iterations".format(max=max) - res = True + return True maxSizeFromMin = self.MAX_INCREASE_FROM_MINIMUM * self.minSize - if (self.its > self.GRACE_ITERATIONS and - (not res) and (curSize > maxSizeFromMin)): - self.reason = "Unexpected bump in size," \ - " compared to minimum achieved" - res = True + if curSize > maxSizeFromMin: + self.grace_remaining -= 1 + if self.grace_remaining == 0: + self.reason = "Unexpected bump in size," \ + " compared to minimum achieved" + + return True - return res + return False def printReasoning(self): Util.log("Aborted coalesce") diff --git a/tests/test_cleanup.py b/tests/test_cleanup.py index a26831807..96448b55e 100644 --- a/tests/test_cleanup.py +++ b/tests/test_cleanup.py @@ -1299,14 +1299,17 @@ def test_leafCoalesceTracker(self): expectedHistory = [ "Iteration: 1 -- Initial size 100 --> Final size 100", "Iteration: 2 -- Initial size 100 --> Final size 121", + "Iteration: 3 -- Initial size 100 --> Final size 141", ] expectedReason = "Unexpected bump in size," \ " compared to minimum achieved" res = tracker.abortCoalesce(100, 100) self.assertFalse(res) res = tracker.abortCoalesce(100, 121) + self.assertFalse(res) + res = tracker.abortCoalesce(100, 141) self.autopsyTracker(tracker, res, expectedHistory, - expectedReason, 100, 121, 100) + expectedReason, 100, 141, 100) def test_leafCoaleesceTracker_too_many_iterations(self): sr = create_cleanup_sr(self.xapi_mock) @@ -1343,10 +1346,11 @@ def test_leafCoalesceTracker_getting_bigger(self): "Iteration: 1 -- Initial size 100 --> Final size 101", "Iteration: 2 -- Initial size 100 --> Final size 101", "Iteration: 3 -- Initial size 100 --> Final size 101", - "Iteration: 4 -- Initial size 100 --> Final size 101" + "Iteration: 4 -- Initial size 100 --> Final size 101", + "Iteration: 5 -- Initial size 100 --> Final size 101" ] expectedReason = "No progress made for 3 iterations" - self.exerciseTracker(tracker, 100, 101, 3, expectedHistory, + self.exerciseTracker(tracker, 100, 101, 4, expectedHistory, expectedReason, 100, 101, 100) def runAbortable(self, func, ret, ns, abortTest, pollInterval, timeOut):