Merge ~cjwatson/launchpad:gina-reduce-transactions into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 2a865f4c418139c8c75e76f221a91808ee6fdcaf
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:gina-reduce-transactions
Merge into: launchpad:master
Diff against target: 61 lines (+17/-8)
2 files modified
lib/lp/soyuz/scripts/gina/runner.py (+7/-2)
lib/lp/soyuz/scripts/tests/test_gina.py (+10/-6)
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Ines Almeida Approve
Review via email: mp+445544@code.launchpad.net

Commit message

gina: Don't hold transactions while unpacking source packages

Description of the change

Some source packages are large, and unpacking them can be very slow (over ten minutes in some extreme cases). Ensure that we don't hold a transaction open while doing so, since that sometimes causes monitoring scripts that kill idle transactions to ruin our day.

To post a comment you must log in.
Revision history for this message
Ines Almeida (ines-almeida) wrote :

Makes sense.
Maybe add a comment in both places with a quick the explanation why adding TransactionFreeOperation is important there?

review: Approve
Revision history for this message
Jürgen Gmach (jugmac00) wrote :

Thanks, Colin. And good idea, Inês!

Revision history for this message
Jürgen Gmach (jugmac00) :
review: Approve
Revision history for this message
Colin Watson (cjwatson) wrote :

Sure - done.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/soyuz/scripts/gina/runner.py b/lib/lp/soyuz/scripts/gina/runner.py
2index effe12e..f7909bc 100644
3--- a/lib/lp/soyuz/scripts/gina/runner.py
4+++ b/lib/lp/soyuz/scripts/gina/runner.py
5@@ -13,6 +13,7 @@ import six
6 from zope.component import getUtility
7
8 from lp.registry.interfaces.pocket import PackagePublishingPocket
9+from lp.scripts.helpers import TransactionFreeOperation
10 from lp.services.config import config
11 from lp.services.features import getFeatureFlag
12 from lp.services.scripts import log
13@@ -192,8 +193,12 @@ def do_one_sourcepackage(distro, source, package_root, importer_handler):
14 # already exists in the database
15 log.info("%s already exists in the archive", source_data.package)
16 return
17- source_data.process_package(distro, package_root)
18- source_data.ensure_complete()
19+ importer_handler.commit()
20+ # Unpacking source packages can be slow, so don't hold a transaction
21+ # while doing so.
22+ with TransactionFreeOperation():
23+ source_data.process_package(distro, package_root)
24+ source_data.ensure_complete()
25 importer_handler.import_sourcepackage(source_data)
26 importer_handler.commit()
27
28diff --git a/lib/lp/soyuz/scripts/tests/test_gina.py b/lib/lp/soyuz/scripts/tests/test_gina.py
29index edff14e..967d917 100644
30--- a/lib/lp/soyuz/scripts/tests/test_gina.py
31+++ b/lib/lp/soyuz/scripts/tests/test_gina.py
32@@ -19,6 +19,7 @@ import lp.soyuz.scripts.gina.handlers
33 from lp.archiveuploader.tagfiles import parse_tagfile
34 from lp.registry.interfaces.pocket import PackagePublishingPocket
35 from lp.registry.interfaces.series import SeriesStatus
36+from lp.scripts.helpers import TransactionFreeOperation
37 from lp.services.database.constants import UTC_NOW
38 from lp.services.features.testing import FeatureFixture
39 from lp.services.log.logger import DevNullLogger
40@@ -754,12 +755,15 @@ class TestRunner(TestCaseWithFactory):
41 )
42
43 def import_and_get_versions():
44- import_sourcepackages(
45- series.distribution.name,
46- packages_map,
47- archive_root,
48- importer_handler,
49- )
50+ # Unpacking source packages can be slow, so ensure that we don't
51+ # hold a transaction while doing so.
52+ with TransactionFreeOperation.require():
53+ import_sourcepackages(
54+ series.distribution.name,
55+ packages_map,
56+ archive_root,
57+ importer_handler,
58+ )
59 return [
60 p.source_package_version
61 for p in series.main_archive.getPublishedSources(

Subscribers

People subscribed via source and target branches

to status/vote changes: