Merge lp:~jtv/launchpad/bug-824553 into lp:launchpad

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Robert Collins
Approved revision: no longer in the source branch.
Merged at revision: 13727
Proposed branch: lp:~jtv/launchpad/bug-824553
Merge into: lp:launchpad
Diff against target: 87 lines (+18/-15)
2 files modified
lib/lp/archivepublisher/scripts/publish_ftpmaster.py (+8/-7)
lib/lp/archivepublisher/tests/test_publish_ftpmaster.py (+10/-8)
To merge this branch: bzr merge lp:~jtv/launchpad/bug-824553
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Review via email: mp+71823@code.launchpad.net

Commit message

[r=lifeless][bug=824553] Create all indexes for a new distroseries at once.

Description of the change

= Summary =

When publish-ftpmaster perceives a new distroseries, instead of doing its normal work it will create the series' initial indexes.

It does that with one separate publish-distro script run per suite. This is wasteful: a lot of work is repeated for every suite that needs to be done only once.

== Proposed fix ==

Instead, pass the full list of suites to publish-distro. It accepts multiple instances of the -s <suite> argument.

== Pre-implementation notes ==

I neglected to have a pre-implementation call about this. The bug specified what needed doing with great clarity and in sufficient detail.

== Implementation details ==

This may mean more repeated work if initial indexing should fail and have to be re-done on the next run. But why optimize for failure?

== Tests ==

{{{
./bin/test -vvc lp.archivepublisher.tests.test_publish_ftpmaster
}}}

== Demo and Q/A ==

Create a new Ubuntu distroseries (STOP! I MEANT ON A TEST SERVER, YOU FOOL!) and run publish-ftpmaster with -d ubuntu. It'll churn for a while. In the Ubuntu archive (e.g. /srv/launchpad.net/ubuntu-archive/ubuntu) you'll see marker files named ".created-indexes-for-<series><pocket-suffix> for each of its pockets.

Well, you probably won't. But if you had remembered to "ls -a" then you almost definitely would.

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/archivepublisher/scripts/publish_ftpmaster.py
  lib/lp/archivepublisher/tests/test_publish_ftpmaster.py

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

Looks like the MarkIndexCreationComplete call might want to be pushed down into the layer you call into.

review: Approve
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Hmm good point. Unfortunately that layer doesn't have the intelligence to know that it's creating the indexes, so bundling index creation with marker creation more tightly would require yet a further layer. Probably not quite worth the trouble just yet.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/archivepublisher/scripts/publish_ftpmaster.py'
2--- lib/lp/archivepublisher/scripts/publish_ftpmaster.py 2011-08-15 10:50:57 +0000
3+++ lib/lp/archivepublisher/scripts/publish_ftpmaster.py 2011-08-18 04:13:36 +0000
4@@ -295,11 +295,13 @@
5 "Indexes for %s were created on %s.\n"
6 % (suite, datetime.now(utc)))
7
8- def createIndexes(self, distribution, suite):
9- """Create archive indexes for `distroseries`."""
10- self.logger.info("Creating archive indexes for %s.", suite)
11- self.runPublishDistro(distribution, args=['-A'], suites=[suite])
12- self.markIndexCreationComplete(distribution, suite)
13+ def createIndexes(self, distribution, suites):
14+ """Create archive indexes for `suites` of `distroseries`."""
15+ self.logger.info(
16+ "Creating archive indexes for %s.", ', '.join(suites))
17+ self.runPublishDistro(distribution, args=['-A'], suites=suites)
18+ for suite in suites:
19+ self.markIndexCreationComplete(distribution, suite)
20
21 def processAccepted(self, distribution):
22 """Run the process-accepted script."""
23@@ -573,8 +575,7 @@
24 for series in distribution.series:
25 suites_needing_indexes = self.listSuitesNeedingIndexes(series)
26 if len(suites_needing_indexes) > 0:
27- for suite in suites_needing_indexes:
28- self.createIndexes(distribution, suite)
29+ self.createIndexes(distribution, suites_needing_indexes)
30 # Don't try to do too much in one run. Leave the rest
31 # of the work for next time.
32 return
33
34=== modified file 'lib/lp/archivepublisher/tests/test_publish_ftpmaster.py'
35--- lib/lp/archivepublisher/tests/test_publish_ftpmaster.py 2011-08-15 23:25:16 +0000
36+++ lib/lp/archivepublisher/tests/test_publish_ftpmaster.py 2011-08-18 04:13:36 +0000
37@@ -931,7 +931,7 @@
38 script.markIndexCreationComplete = FakeMethod()
39 script.runPublishDistro = FakeMethod()
40 suite = get_a_suite(series)
41- script.createIndexes(distro, suite)
42+ script.createIndexes(distro, [suite])
43 self.assertEqual(
44 [((distro, suite), {})], script.markIndexCreationComplete.calls)
45
46@@ -946,7 +946,7 @@
47 script.markIndexCreationComplete = FakeMethod()
48 script.runPublishDistro = FakeMethod(failure=Boom("Sorry!"))
49 try:
50- script.createIndexes(series.distribution, get_a_suite(series))
51+ script.createIndexes(series.distribution, [get_a_suite(series)])
52 except:
53 pass
54 self.assertEqual([], script.markIndexCreationComplete.calls)
55@@ -999,16 +999,18 @@
56
57 def test_script_calls_createIndexes_for_new_series(self):
58 # If the script's main() finds a distroseries that needs its
59- # indexes created, it calls createIndexes on that distroseries.
60+ # indexes created, it calls createIndexes on that distroseries,
61+ # passing it all of the series' suite names.
62 distro = self.makeDistroWithPublishDirectory()
63 series = self.makeDistroSeriesNeedingIndexes(distribution=distro)
64 script = self.makeScript(distro)
65 script.createIndexes = FakeMethod()
66 script.main()
67- expected_calls = [
68- ((distro, series.getSuite(pocket)), {})
69- for pocket in pocketsuffix.iterkeys()]
70- self.assertContentEqual(expected_calls, script.createIndexes.calls)
71+ [((given_distro, given_suites), kwargs)] = script.createIndexes.calls
72+ self.assertEqual(distro, given_distro)
73+ self.assertContentEqual(
74+ [series.getSuite(pocket) for pocket in pocketsuffix.iterkeys()],
75+ given_suites)
76
77 def test_createIndexes_ignores_other_series(self):
78 # createIndexes does not accidentally also touch other
79@@ -1022,7 +1024,7 @@
80 self.createIndexesMarkerDir(script, series)
81 suite = get_a_suite(series)
82
83- script.createIndexes(distro, suite)
84+ script.createIndexes(distro, [suite])
85
86 args, kwargs = script.runPublishDistro.calls[0]
87 self.assertEqual([suite], kwargs['suites'])