Skip to content

Commit 7c33cd5

Browse files
committed
new approach
1 parent 0b10f41 commit 7c33cd5

2 files changed

Lines changed: 14 additions & 15 deletions

File tree

pulpcore/app/replica.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,10 @@ def distribution_extra_fields(self, repository, upstream_distribution):
174174
"""
175175
Return the fields that need to be updated/cleared on distributions for idempotence.
176176
177-
Note: repository_version is NOT included here. It is set atomically in
178-
finalize_replication after all syncs complete.
177+
Note: repository, publication, and repository_version are NOT included here.
178+
They are all updated atomically in finalize_replication after all syncs complete.
179179
"""
180180
return {
181-
"repository": None,
182-
"publication": None,
183181
"base_path": upstream_distribution["base_path"],
184182
}
185183

@@ -192,8 +190,6 @@ def create_or_update_distribution(self, repository, upstream_distribution):
192190
)
193191
if not self._is_managed(distro):
194192
return None
195-
# Clear repository and publication so they don't conflict when
196-
# finalize_replication sets repository_version atomically.
197193
needs_update = self.needs_update(distribution_data, distro)
198194
if needs_update:
199195
dispatch(
@@ -208,13 +204,8 @@ def create_or_update_distribution(self, repository, upstream_distribution):
208204
},
209205
)
210206
except self.distribution_model_cls.DoesNotExist:
211-
# Don't set repository or publication for new distributions —
212-
# repository_version will be set in finalize_replication after sync completes.
213-
create_data = {
214-
k: v for k, v in distribution_data.items() if k not in ("repository", "publication")
215-
}
207+
create_data = dict(distribution_data)
216208
create_data["name"] = upstream_distribution["name"]
217-
create_data["pulp_labels"] = distribution_data["pulp_labels"]
218209
dispatch(
219210
general_create,
220211
task_group=self.task_group,

pulpcore/app/tasks/replica.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,24 @@ def finalize_replication(server_pk, distro_repo_pairs):
124124
if task_group.tasks.exclude(pk=task.pk).exclude(state=TASK_STATES.COMPLETED).exists():
125125
raise Exception("Replication failed.")
126126

127-
# Atomically update all managed distributions to point to their repo's latest version.
127+
# Atomically update all managed distributions to point to their repo's latest version,
128+
# clearing any previous repository or publication references.
128129
with transaction.atomic():
129130
for distro_name, repo_pk in distro_repo_pairs:
130131
distro = Distribution.objects.get(name=distro_name, pulp_domain=server.pulp_domain)
131132
repo = Repository.objects.get(pk=repo_pk)
132133
latest_version = repo.latest_version()
133134
if latest_version:
134-
if distro.repository_version != latest_version:
135+
needs_update = (
136+
distro.repository_version != latest_version
137+
or distro.repository is not None
138+
or distro.publication is not None
139+
)
140+
if needs_update:
141+
distro.repository = None
142+
distro.publication = None
135143
distro.repository_version = latest_version
136-
distro.save(update_fields=["repository_version"])
144+
distro.save(update_fields=["repository", "publication", "repository_version"])
137145

138146
# Record timestamp of last successful replication.
139147
started_at = task_group.tasks.aggregate(Min("started_at"))["started_at__min"]

0 commit comments

Comments
 (0)