Merge ~ilasc/launchpad:repack-for-zero-candidates into launchpad:master

Proposed by Ioana Lasc
Status: Merged
Approved by: Ioana Lasc
Approved revision: 25cdb06b8fc2703f0baea6dbe26cea149d6a5706
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~ilasc/launchpad:repack-for-zero-candidates
Merge into: launchpad:master
Diff against target: 78 lines (+40/-7)
2 files modified
lib/lp/code/scripts/repackgitrepository.py (+10/-7)
lib/lp/code/scripts/tests/test_repack_git_repositories.py (+30/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+401868@code.launchpad.net

Commit message

Handle zero candidates in repack job

Description of the change

This MP attempts to fix 2 issues:

1: When we have zero repository candidates for repacks with the previous code we were getting:

File "lib/lp/code/scripts/repackgitrepository.py", line 103, in __call__
    self.start_at = repackable_repos[-1].id
IndexError: list index out of range

2: We were not logging in the right place the final count of repacks requested per job run. Moved that log statement to "isDone()".

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/code/scripts/repackgitrepository.py b/lib/lp/code/scripts/repackgitrepository.py
2index e0ec646..1ae66f5 100644
3--- a/lib/lp/code/scripts/repackgitrepository.py
4+++ b/lib/lp/code/scripts/repackgitrepository.py
5@@ -53,8 +53,14 @@ class RepackTunableLoop(TunableLoop):
6 def isDone(self):
7 # we stop at maximum 1000 or when we have no repositories
8 # that are valid repack candidates
9- return (self.findRepackCandidates().is_empty() or
10- self.num_repacked + self.maximum_chunk_size >= self.targets)
11+ result = (self.findRepackCandidates().is_empty() or
12+ self.num_repacked + self.maximum_chunk_size >= self.targets)
13+ if result and not self.dry_run:
14+ self.logger.info(
15+ 'Requested a total of %d automatic git repository repacks '
16+ 'in this run of the Automated Repack Job.'
17+ % self.num_repacked)
18+ return result
19
20 def __call__(self, chunk_size):
21 repackable_repos = list(self.findRepackCandidates()[:chunk_size])
22@@ -100,13 +106,10 @@ class RepackTunableLoop(TunableLoop):
23 'out of the %d qualifying for repack.'
24 % (counter, len(repackable_repos)))
25
26- self.start_at = repackable_repos[-1].id
27+ if repackable_repos:
28+ self.start_at = repackable_repos[-1].id
29
30 if not self.dry_run:
31 transaction.commit()
32- self.logger.info(
33- 'Requested a total of %d automatic git repository repacks '
34- 'in this run of the Automated Repack Job.'
35- % self.num_repacked)
36 else:
37 transaction.abort()
38diff --git a/lib/lp/code/scripts/tests/test_repack_git_repositories.py b/lib/lp/code/scripts/tests/test_repack_git_repositories.py
39index 19f1b2b..53a77c5 100644
40--- a/lib/lp/code/scripts/tests/test_repack_git_repositories.py
41+++ b/lib/lp/code/scripts/tests/test_repack_git_repositories.py
42@@ -156,6 +156,36 @@ class TestRequestGitRepack(TestCaseWithFactory):
43 self.assertEqual("/repo/%s/repack" % repo[i].getInternalPath(),
44 self.turnip_server.app.contents[i])
45
46+ def test_auto_repack_zero_repackCandidates(self):
47+ self.makeTurnipServer()
48+ repo = []
49+ for i in range(2):
50+ repo.append(self.factory.makeGitRepository())
51+ repo[i] = removeSecurityProxy(repo[i])
52+ repo[i].loose_object_count = 3
53+ repo[i].pack_count = 2
54+ transaction.commit()
55+
56+ # zero candidates
57+ # assert on the log contents and the content that makes it to Turnip
58+ (ret, out, err) = run_script('cronscripts/repack_git_repositories.py')
59+ self.assertIn(
60+ 'Requested a total of 0 automatic git repository repacks in this '
61+ 'run of the Automated Repack Job.', err)
62+ self.assertEqual([],
63+ self.turnip_server.app.contents)
64+
65+ # exactly one candidate
66+ repo[0].loose_object_count = 7000
67+ repo[0].pack_count = 43
68+ transaction.commit()
69+ (ret, out, err) = run_script('cronscripts/repack_git_repositories.py')
70+ self.assertIn(
71+ 'Requested a total of 1 automatic git repository repacks in '
72+ 'this run of the Automated Repack Job.', err)
73+ self.assertEqual("/repo/%s/repack" % repo[0].getInternalPath(),
74+ self.turnip_server.app.contents[0])
75+
76 def test_auto_repack_loop_throttle(self):
77 repacker = RepackTunableLoop(self.log, None)
78 # We throttle at 7 for this test, we use a limit

Subscribers

People subscribed via source and target branches

to status/vote changes: