Merge lp:~cjwatson/launchpad/bmp-job-pruner into lp:launchpad

Proposed by Colin Watson
Status: Rejected
Rejected by: Colin Watson
Proposed branch: lp:~cjwatson/launchpad/bmp-job-pruner
Merge into: lp:launchpad
Diff against target: 111 lines (+66/-2)
2 files modified
lib/lp/scripts/garbo.py (+20/-1)
lib/lp/scripts/tests/test_garbo.py (+46/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/bmp-job-pruner
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Review via email: mp+362460@code.launchpad.net

Commit message

Prune old completed BranchMergeProposalJobs.

Description of the change

This accounts for about 3 million out of the 17 million Job rows on production, so it seems worth the effort of pruning.

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) :
review: Approve
Revision history for this message
Colin Watson (cjwatson) :
Revision history for this message
Guruprasad (lgp171188) wrote :

Colin, can this be merged?

Revision history for this message
Colin Watson (cjwatson) wrote :

Unmerged revisions

18866. By Colin Watson

Prune old completed BranchMergeProposalJobs.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/scripts/garbo.py'
--- lib/lp/scripts/garbo.py 2018-12-17 14:49:53 +0000
+++ lib/lp/scripts/garbo.py 2019-01-30 14:10:40 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2018 Canonical Ltd. This software is licensed under the1# Copyright 2009-2019 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Database garbage collection."""4"""Database garbage collection."""
@@ -1238,6 +1238,24 @@
1238 """1238 """
12391239
12401240
1241class BranchMergeProposalJobPruner(BulkPruner):
1242 """Prune `BranchMergeProposalJob`s that are in a final state and more
1243 than a month old.
1244
1245 When a BranchMergeProposalJob is completed, it gets set to a final
1246 state. These jobs should be pruned from the database after a month.
1247 """
1248 target_table_class = Job
1249 ids_to_prune_query = """
1250 SELECT DISTINCT Job.id
1251 FROM Job, BranchMergeProposalJob
1252 WHERE
1253 Job.id = BranchMergeProposalJob.job
1254 AND Job.date_finished < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'
1255 - CAST('30 days' AS interval)
1256 """
1257
1258
1241class SnapBuildJobPruner(BulkPruner):1259class SnapBuildJobPruner(BulkPruner):
1242 """Prune `SnapBuildJob`s that are in a final state and more than a month1260 """Prune `SnapBuildJob`s that are in a final state and more than a month
1243 old.1261 old.
@@ -1927,6 +1945,7 @@
1927 tunable_loops = [1945 tunable_loops = [
1928 AnswerContactPruner,1946 AnswerContactPruner,
1929 BranchJobPruner,1947 BranchJobPruner,
1948 BranchMergeProposalJobPruner,
1930 BugNotificationPruner,1949 BugNotificationPruner,
1931 BugWatchActivityPruner,1950 BugWatchActivityPruner,
1932 CodeImportEventPruner,1951 CodeImportEventPruner,
19331952
=== modified file 'lib/lp/scripts/tests/test_garbo.py'
--- lib/lp/scripts/tests/test_garbo.py 2018-12-17 14:49:53 +0000
+++ lib/lp/scripts/tests/test_garbo.py 2019-01-30 14:10:40 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2018 Canonical Ltd. This software is licensed under the1# Copyright 2009-2019 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Test the database garbage collector."""4"""Test the database garbage collector."""
@@ -61,6 +61,7 @@
61 BranchJob,61 BranchJob,
62 BranchUpgradeJob,62 BranchUpgradeJob,
63 )63 )
64from lp.code.model.branchmergeproposaljob import BranchMergeProposalJob
64from lp.code.model.codeimportevent import CodeImportEvent65from lp.code.model.codeimportevent import CodeImportEvent
65from lp.code.model.codeimportresult import CodeImportResult66from lp.code.model.codeimportresult import CodeImportResult
66from lp.code.model.diff import Diff67from lp.code.model.diff import Diff
@@ -957,6 +958,50 @@
957 switch_dbuser('testadmin')958 switch_dbuser('testadmin')
958 self.assertEqual(store.find(BranchJob).count(), 1)959 self.assertEqual(store.find(BranchJob).count(), 1)
959960
961 def test_BranchMergeProposalJobPruner(self):
962 # Garbo should remove jobs completed over 30 days ago.
963 switch_dbuser('testadmin')
964 store = IMasterStore(Job)
965
966 bmp = self.factory.makeBranchMergeProposal()
967 bmp_job = removeSecurityProxy(bmp.next_preview_diff_job)
968 bmp_job.job.date_finished = THIRTY_DAYS_AGO
969
970 self.assertEqual(
971 store.find(
972 BranchMergeProposalJob,
973 BranchMergeProposalJob.branch_merge_proposal ==
974 bmp.id).count(),
975 1)
976
977 self.runDaily()
978
979 switch_dbuser('testadmin')
980 self.assertEqual(
981 store.find(
982 BranchMergeProposalJob,
983 BranchMergeProposalJob.branch_merge_proposal ==
984 bmp.id).count(),
985 0)
986
987 def test_BranchMergeProposalJobPruner_doesnt_prune_recent_jobs(self):
988 # Check to make sure the garbo doesn't remove jobs that aren't more
989 # than thirty days old.
990 switch_dbuser('testadmin')
991 store = IMasterStore(Job)
992
993 bmp = self.factory.makeBranchMergeProposal()
994 bmp_job = removeSecurityProxy(bmp.next_preview_diff_job)
995 bmp_job.job.date_finished = THIRTY_DAYS_AGO
996
997 bmp2 = self.factory.makeBranchMergeProposal()
998 self.assertIsNotNone(bmp2.next_preview_diff_job)
999
1000 self.runDaily()
1001
1002 switch_dbuser('testadmin')
1003 self.assertEqual(store.find(BranchMergeProposalJob).count(), 1)
1004
960 def test_GitJobPruner(self):1005 def test_GitJobPruner(self):
961 # Garbo should remove jobs completed over 30 days ago.1006 # Garbo should remove jobs completed over 30 days ago.
962 switch_dbuser('testadmin')1007 switch_dbuser('testadmin')