Skip to content

Commit 6aa4af5

Browse files
committed
commit repos to the database first, then hand off
1 parent a113221 commit 6aa4af5

File tree

2 files changed

+18
-46
lines changed

2 files changed

+18
-46
lines changed

nexus/src/app/update/mod.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use nexus_db_model::TufRepoDescription;
1111
use nexus_db_queries::authz;
1212
use nexus_db_queries::context::OpContext;
1313
use omicron_common::api::external::{
14-
Error, SemverVersion, TufRepoInsertResponse,
14+
Error, SemverVersion, TufRepoInsertResponse, TufRepoInsertStatus,
1515
};
1616
use omicron_common::update::ArtifactId;
1717
use update_common::artifacts::ArtifactsWithPlan;
@@ -56,29 +56,31 @@ impl super::Nexus {
5656
ArtifactsWithPlan::from_stream(body, Some(file_name), &self.log)
5757
.await
5858
.map_err(|error| error.to_http_error())?;
59+
// Now store the artifacts in the database.
5960
let tuf_repo_description = TufRepoDescription::from_external(
6061
artifacts_with_plan.description().clone(),
6162
);
62-
// Move the `ArtifactsWithPlan`, which carries with it the
63-
// `Utf8TempDir`s storing the artifacts, into the artifact replication
64-
// background task. This is done before the database insert because if
65-
// this fails, we shouldn't record the artifacts in the database.
66-
self.tuf_artifact_replication_tx
67-
.send(artifacts_with_plan)
68-
.await
69-
.map_err(|err| {
70-
Error::internal_error(&format!(
71-
"failed to send artifacts for replication: {err}"
72-
))
73-
})?;
74-
// Now store the artifacts in the database.
7563
let response = self
7664
.db_datastore
7765
.update_tuf_repo_insert(opctx, tuf_repo_description)
7866
.await
7967
.map_err(HttpError::from)?;
80-
// Finally, immediately activate the artifact replication task.
81-
self.background_tasks.task_tuf_artifact_replication.activate();
68+
69+
// If we inserted a new repository, move the `ArtifactsWithPlan` (which
70+
// carries with it the `Utf8TempDir`s storing the artifacts) into the
71+
// artifact replication background task, then immediately activate the
72+
// task.
73+
if response.status == TufRepoInsertStatus::Inserted {
74+
self.tuf_artifact_replication_tx
75+
.send(artifacts_with_plan)
76+
.await
77+
.map_err(|err| {
78+
Error::internal_error(&format!(
79+
"failed to send artifacts for replication: {err}"
80+
))
81+
})?;
82+
self.background_tasks.task_tuf_artifact_replication.activate();
83+
}
8284

8385
Ok(response.into_external())
8486
}

nexus/tests/integration_tests/updates.rs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,6 @@ async fn test_repo_upload() -> Result<()> {
195195
"initial description matches fetched description"
196196
);
197197

198-
// Even though the repository already exists, the artifacts are sent to the
199-
// replication task ahead of database insertion. The task should have run
200-
// once, found nothing to do, and deleted the artifacts.
201-
let status =
202-
wait_tuf_artifact_replication_step(&cptestctx.internal_client).await;
203-
eprintln!("{status:?}");
204-
assert_eq!(status.requests_ok, 0);
205-
assert_eq!(status.requests_outstanding, 0);
206-
assert_eq!(status.local_repos, 0);
207-
208198
// Upload a new repository with the same system version but a different
209199
// version for one of the components. This will produce a different hash,
210200
// which should return an error.
@@ -232,16 +222,6 @@ async fn test_repo_upload() -> Result<()> {
232222
)?;
233223
}
234224

235-
// Even though the repository was rejected, the artifacts are sent to the
236-
// replication task ahead of database insertion. The task should have run
237-
// once, found nothing to do, and deleted the artifacts.
238-
let status =
239-
wait_tuf_artifact_replication_step(&cptestctx.internal_client).await;
240-
eprintln!("{status:?}");
241-
assert_eq!(status.requests_ok, 0);
242-
assert_eq!(status.requests_outstanding, 0);
243-
assert_eq!(status.local_repos, 0);
244-
245225
// Upload a new repository with a different system version and different
246226
// contents (but same version) for an artifact.
247227
{
@@ -268,16 +248,6 @@ async fn test_repo_upload() -> Result<()> {
268248
)?;
269249
}
270250

271-
// Even though the repository was rejected, the artifacts are sent to the
272-
// replication task ahead of database insertion. The task should have run
273-
// once, found nothing to do, and deleted the artifacts.
274-
let status =
275-
wait_tuf_artifact_replication_step(&cptestctx.internal_client).await;
276-
eprintln!("{status:?}");
277-
assert_eq!(status.requests_ok, 0);
278-
assert_eq!(status.requests_outstanding, 0);
279-
assert_eq!(status.local_repos, 0);
280-
281251
// Upload a new repository with a different system version but no other
282252
// changes. This should be accepted.
283253
{

0 commit comments

Comments
 (0)