Don't issue multiple merge requests for bundles
In I82848367bd6f191ec5ae5822a1f438070cde14e1 we avoided spawning merge jobs for non-live items. In Id533772f35ebbc76910398e0e0fa50a3abfceb52 we backed that out partially by spawning merge jobs for non-live items if they update the config (so we can create a layout). In I38925e5fd0ed5ff45aab17d108740345716fd478 we accepted that in the case of non-live items in a bundle that updated config, we would spawn multiple merge jobs and each one should be responsible for updating its own item. However, we can revisit the assumptions in Id533772f35ebbc76910398e0e0fa50a3abfceb52 which appears not to have taken bundles into consideration. A bundle should have the same files results for every item in the bundle, so, channeling the original spirit of I82848367bd6f191ec5ae5822a1f438070cde14e1, we can try to avoid spawning merge jobs for multiple items in a bundle. This is an alternate solution to the issue addressed by I38925e5fd0ed5ff45aab17d108740345716fd478 in that rather than accepting that we will receive multiple merge jobs in the case of a bundle with non-live items that each update config, we will instead receive only one merge job for the entire bundle regardless of whether they update config, or even whether they are live. This is accomplished by establishing a single "bundle item" for the bundle which is defined as the first live item in the bundle. This is the only item in the bundle that will spawn merge jobs. When the merge job for that item completes, all of the items in the bundle will be updated with the results. Change-Id: Icfe1f2a126eb13349b510107a305c6eef7b622fb
This commit is contained in:
1 parent
b8d813c4f9
commit
2436c1a5df
3 files changed
+44
-31
No files matched your search
@@ -1305,10 +1305,10 @@ class TestGerritCircularDependencies(ZuulTestCase):
|
||||
self.assertEqual(B.data["status"], "MERGED")
|
||||
self.assertEqual(C.data["status"], "MERGED")
|
||||
|
||||
def test_circular_config_change_merge_order(self):
|
||||
"""Regression tests to make sure that merge completed events
|
||||
which don't arrive in the same order as requested, don't cause
|
||||
any side-effects."""
|
||||
def test_circular_config_change_single_merge_job(self):
|
||||
"""Regression tests to make sure that a bundle with non-live
|
||||
config changes only spawns one merge job (so that we avoid
|
||||
problems with multiple jobs arriving in the wrong order)."""
|
||||
|
||||
define_job = textwrap.dedent(
|
||||
"""
|
||||
@@ -1344,11 +1344,8 @@ class TestGerritCircularDependencies(ZuulTestCase):
|
||||
self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
|
||||
self.waitUntilSettled()
|
||||
|
||||
# Release pending merge requests in reverse order to test that
|
||||
# there are no unintended side-effects.
|
||||
for merge_job in reversed(self.merger_api.queued()):
|
||||
self.merger_api.release(merge_job)
|
||||
self.waitUntilSettled()
|
||||
# Assert that there is a single merge job for the bundle.
|
||||
self.assertEqual(len(self.merger_api.queued()), 1)
|
||||
|
||||
self.hold_merge_jobs_in_queue = False
|
||||
self.merger_api.release()
|
||||
|
||||
+24
-18
@@ -1316,9 +1316,15 @@ class PipelineManager(metaclass=ABCMeta):
|
||||
|
||||
def scheduleMerge(self, item, files=None, dirs=None):
|
||||
log = item.annotateLogger(self.log)
|
||||
build_set = item.bundle_build_set
|
||||
if build_set.item is not item:
|
||||
# This is a bundle, but this isn't the bundle buildset.
|
||||
# Just say we're not ready and let the real one get
|
||||
# scheduled later.
|
||||
return False
|
||||
|
||||
log.debug("Scheduling merge for item %s (files: %s, dirs: %s)" %
|
||||
(item, files, dirs))
|
||||
build_set = item.current_build_set
|
||||
|
||||
# If the involved projects exclude unprotected branches we should also
|
||||
# exclude them from the merge and repo state except the branch of the
|
||||
@@ -1336,13 +1342,13 @@ class PipelineManager(metaclass=ABCMeta):
|
||||
|
||||
if isinstance(item.change, model.Change):
|
||||
self.sched.merger.mergeChanges(build_set.merger_items,
|
||||
item.current_build_set, files, dirs,
|
||||
build_set, files, dirs,
|
||||
precedence=self.pipeline.precedence,
|
||||
event=item.event,
|
||||
branches=branches)
|
||||
else:
|
||||
self.sched.merger.getRepoState(build_set.merger_items,
|
||||
item.current_build_set,
|
||||
build_set,
|
||||
precedence=self.pipeline.precedence,
|
||||
event=item.event,
|
||||
branches=branches)
|
||||
@@ -1985,21 +1991,21 @@ class PipelineManager(metaclass=ABCMeta):
|
||||
if isinstance(item.change, model.Tag):
|
||||
source.setChangeAttributes(
|
||||
item.change, containing_branches=event.item_in_branches)
|
||||
with build_set.activeContext(self.current_context):
|
||||
build_set.setMergeRepoState(event.repo_state)
|
||||
build_set.merge_state = build_set.COMPLETE
|
||||
if event.merged:
|
||||
build_set.commit = event.commit
|
||||
try:
|
||||
build_set.setFiles(event.files)
|
||||
except Exception:
|
||||
log.exception("Unable to set files for build set:")
|
||||
elif event.updated:
|
||||
build_set.commit = (item.change.newrev or
|
||||
'0000000000000000000000000000000000000000')
|
||||
if not build_set.commit:
|
||||
log.info("Unable to merge change %s" % item.change)
|
||||
item.setUnableToMerge(event.errors)
|
||||
for other_item in item.bundle_items:
|
||||
other_build_set = other_item.current_build_set
|
||||
with other_build_set.activeContext(self.current_context):
|
||||
other_build_set.setMergeRepoState(event.repo_state)
|
||||
other_build_set.merge_state = other_build_set.COMPLETE
|
||||
if event.merged:
|
||||
other_build_set.commit = event.commit
|
||||
other_build_set.setFiles(event.files)
|
||||
elif event.updated:
|
||||
other_build_set.commit = (
|
||||
item.change.newrev or
|
||||
'0000000000000000000000000000000000000000')
|
||||
if not other_build_set.commit:
|
||||
log.info("Unable to merge change %s" % item.change)
|
||||
item.setUnableToMerge(event.errors)
|
||||
|
||||
def _onGlobalRepoStateCompleted(self, event, build_set):
|
||||
item = build_set.item
|
||||
|
||||
+14
-4
@@ -4824,6 +4824,20 @@ class QueueItem(zkobject.ZKObject):
|
||||
return self.queue.pipeline
|
||||
return None
|
||||
|
||||
@property
|
||||
def bundle_build_set(self):
|
||||
if self.bundle:
|
||||
for item in self.bundle.items:
|
||||
if item.live:
|
||||
return item.current_build_set
|
||||
return self.current_build_set
|
||||
|
||||
@property
|
||||
def bundle_items(self):
|
||||
if self.bundle:
|
||||
return self.bundle.items
|
||||
return [self]
|
||||
|
||||
@classmethod
|
||||
def new(klass, context, **kw):
|
||||
obj = klass()
|
||||
@@ -5075,10 +5089,6 @@ class QueueItem(zkobject.ZKObject):
|
||||
yield item_ahead
|
||||
item_ahead = item_ahead.item_ahead
|
||||
|
||||
def getNonLiveItemsAhead(self):
|
||||
items = [item for item in self.items_ahead if not item.live]
|
||||
return reversed(items)
|
||||
|
||||
def haveAllJobsStarted(self):
|
||||
if not self.hasJobGraph():
|
||||
return False
|
||||
|
||||
Reference in new issue
Block a user