Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/loader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
common::scheduler::Scheduler,
loader::zone::EnqueuedRefresh,
util::AbortOnDrop,
zone::{Zone, ZoneByPtr, ZoneHandle},
zone::{Zone, ZoneByPtr, ZoneHandle, instance::LoadedInstanceID},
};

mod server;
Expand Down Expand Up @@ -131,13 +131,14 @@ impl Default for Loader {
#[tracing::instrument(
level = "debug",
skip_all,
fields(zone = %zone.name, source = ?source),
fields(zone = %zone.name, source = ?source, ?id),
)]
async fn refresh(
zone: Arc<Zone>,
source: Source,
refresh: EnqueuedRefresh,
mut builder: LoadedZoneBuilder,
id: LoadedInstanceID,
center: Arc<Center>,
metrics: Arc<ActiveLoadMetrics>,
) {
Expand Down Expand Up @@ -231,6 +232,7 @@ async fn refresh(
);

// Cancel the load from the perspective of zone storage.
handle.state.instances.abandon_load(id);
handle.storage().abandon_load(builder);
}

Expand All @@ -249,7 +251,8 @@ async fn refresh(
unreachable!("source-specific loading succeeded and must have filled 'builder'")
});

handle.storage().finish_load(built);
// TODO: Update something in 'handle.state.instances'?
handle.storage().finish_load(built, id);
}

Err(err) => {
Expand All @@ -259,6 +262,7 @@ async fn refresh(
);

// Cancel the load from the perspective of zone storage.
handle.state.instances.abandon_load(id);
handle.storage().abandon_load(builder);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/loader/zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,14 @@ impl LoaderZoneHandle<'_> {
fn start(&mut self, refresh: EnqueuedRefresh, builder: LoadedZoneBuilder) {
let source = self.state.loader.source.clone();
let metrics = Arc::new(ActiveLoadMetrics::begin(source.clone()));
let id = self.state.instances.start_load();

let handle = tokio::task::spawn(super::refresh(
self.zone.clone(),
source,
refresh,
builder,
id,
self.center.clone(),
metrics.clone(),
));
Expand Down
10 changes: 6 additions & 4 deletions src/signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use tracing::error;

use crate::{
center::{Center, halt_zone},
zone::{HistoricalEvent, Zone, ZoneHandle},
zone::{HistoricalEvent, Zone, ZoneHandle, instance::SignedInstanceID},
};

pub mod zone;
Expand All @@ -48,12 +48,13 @@ pub mod zone;
#[tracing::instrument(
level = "debug",
skip_all,
fields(zone = %zone.name, ?trigger),
fields(zone = %zone.name, ?trigger, ?id),
)]
async fn sign(
center: Arc<Center>,
zone: Arc<Zone>,
mut builder: SignedZoneBuilder,
id: SignedInstanceID,
trigger: SigningTrigger,
) {
let (status, _permits) = center.signer.wait_to_sign(&zone).await;
Expand All @@ -65,7 +66,7 @@ async fn sign(
move || {
let result = center
.signer
.sign_zone(&center, &zone, &mut builder, trigger, status);
.sign_zone(&center, &zone, &mut builder, id, trigger, status);
(result, builder)
}
})
Expand All @@ -84,12 +85,13 @@ async fn sign(
match result {
Ok(()) => {
let built = builder.finish().unwrap_or_else(|_| unreachable!());
handle.storage().finish_sign(built);
handle.storage().finish_sign(built, id);
status.status.finish(true);
status.current_action = "Finished".to_string();
}
Err(error) => {
error!("Signing failed: {error}");
handle.state.instances.abandon_sign(id);
handle.storage().abandon_sign(builder);
status.status.finish(false);
status.current_action = "Aborted".to_string();
Expand Down
12 changes: 9 additions & 3 deletions src/signer/zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
center::Center,
signer::{ResigningTrigger, SigningTrigger},
util::BackgroundTasks,
zone::{Zone, ZoneHandle, ZoneState},
zone::{Zone, ZoneHandle, ZoneState, instance::LoadedInstanceID},
};

//----------- SignerZoneHandle -------------------------------------------------
Expand Down Expand Up @@ -48,9 +48,9 @@ impl SignerZoneHandle<'_> {
#[tracing::instrument(
level = "trace",
skip_all,
fields(zone = %self.zone.name)
fields(zone = %self.zone.name, ?loaded_id)
)]
pub fn enqueue_new_sign(&mut self, builder: SignedZoneBuilder) {
pub fn enqueue_new_sign(&mut self, builder: SignedZoneBuilder, loaded_id: LoadedInstanceID) {
info!("Enqueuing a sign operation");

assert!(
Expand All @@ -70,13 +70,15 @@ impl SignerZoneHandle<'_> {
// moment, this queue is opaque and is handled within the asynchronous
// task.

let id = self.state.instances.start_new_sign(loaded_id);
let span = tracing::Span::none();
self.state.signer.ongoing.spawn(
span,
super::sign(
self.center.clone(),
self.zone.clone(),
builder,
id,
SigningTrigger::Load,
),
);
Expand Down Expand Up @@ -145,13 +147,15 @@ impl SignerZoneHandle<'_> {

assert!(self.state.signer.enqueued_new_sign.is_none());

let id = self.state.instances.start_resign();
let span = tracing::Span::none();
self.state.signer.ongoing.spawn(
span,
super::sign(
self.center.clone(),
self.zone.clone(),
builder,
id,
SigningTrigger::Resign(trigger),
),
);
Expand Down Expand Up @@ -218,13 +222,15 @@ impl SignerZoneHandle<'_> {
// add the operation to the queue before starting the re-sign. If the
// queue is too full to start the operation yet, leave it enqueued.

let id = self.state.instances.start_resign();
let span = tracing::Span::none();
self.state.signer.ongoing.spawn(
span,
super::sign(
self.center.clone(),
self.zone.clone(),
builder,
id,
SigningTrigger::Resign(trigger),
),
);
Expand Down
23 changes: 18 additions & 5 deletions src/units/zone_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use crate::daemon::SocketProvider;
use crate::manager::Terminated;
use crate::manager::record_zone_event;
use crate::util::AbortOnDrop;
use crate::zone::instance::{LoadedInstanceID, SignedInstanceID};
use crate::zone::{
HistoricalEvent, SignedZoneVersionState, UnsignedZoneVersionState, Zone, ZoneHandle,
ZoneVersionReviewState,
Expand Down Expand Up @@ -321,7 +322,11 @@ impl ZoneServer {
center: &Arc<Center>,
zone: &Arc<Zone>,
zone_serial: Serial,
// TODO: Split up the function into a loaded and signed variant.
loaded_id: Option<LoadedInstanceID>,
signed_id: Option<SignedInstanceID>,
) -> Option<Result<(), Terminated>> {
let _ = signed_id; // TODO
let unit_name = self.unit_name();
let zone_type = match self.source {
Source::Unsigned => "unsigned",
Expand Down Expand Up @@ -367,7 +372,7 @@ impl ZoneServer {
"[{unit_name}]: Cannot promote unsigned zone '{zone_name}' to the signable set of zones: {err}"
);
} else {
self.on_unsigned_zone_approved(center, zone, zone_serial);
self.on_unsigned_zone_approved(center, zone, loaded_id.unwrap());
}
}
Source::Signed => {
Expand Down Expand Up @@ -528,17 +533,16 @@ impl ZoneServer {
&self,
center: &Arc<Center>,
zone: &Arc<Zone>,
zone_serial: Serial,
id: LoadedInstanceID,
) {
let _ = zone_serial; // TODO
let mut state = zone.state.lock().unwrap();
ZoneHandle {
zone,
state: &mut state,
center,
}
.storage()
.approve_loaded();
.approve_loaded(id);
}

fn on_signed_zone_approved(&self, center: &Arc<Center>, zone: &Arc<Zone>, zone_serial: Serial) {
Expand Down Expand Up @@ -599,6 +603,8 @@ impl ZoneServer {
// Look up the version of the zone being reviewed.
match self.source {
Source::Unsigned => {
// TODO: Make the reviewer pass the ID.
let id;
{
let mut zone_state = zone.state.lock().unwrap();
let Some(version) = zone_state.unsigned.get_mut(&zone_serial) else {
Expand All @@ -622,14 +628,21 @@ impl ZoneServer {
}

version.review = new_review_state;
id = match zone_state.instances.upcoming {
Some(
crate::zone::instance::UpcomingInstance::Loading { id }
| crate::zone::instance::UpcomingInstance::ReviewingLoaded { id },
) => id,
_ => unreachable!(),
}
}
if matches!(decision, ZoneReviewDecision::Approve) {
info!(
"Unsigned zone '{zone_name}' with serial {zone_serial} has been approved."
);
match Self::promote_zone_to_signable(center.clone(), zone_name) {
Ok(()) => {
self.on_unsigned_zone_approved(center, zone, zone_serial);
self.on_unsigned_zone_approved(center, zone, id);
}
Err(err) => {
error!(
Expand Down
4 changes: 4 additions & 0 deletions src/units/zone_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ use crate::util::{
AbortOnDrop, serialize_duration_as_secs, serialize_instant_as_duration_secs,
serialize_opt_duration_as_secs,
};
use crate::zone::instance::SignedInstanceID;
use crate::zone::{HistoricalEvent, HistoricalEventType, PipelineMode, Zone, ZoneHandle};

// Re-signing zones before signatures expire works as follows:
Expand Down Expand Up @@ -314,6 +315,7 @@ impl ZoneSigner {
center: &Arc<Center>,
zone: &Arc<Zone>,
builder: &mut SignedZoneBuilder,
id: SignedInstanceID,
trigger: SigningTrigger,
status: Arc<RwLock<SigningStatusPerZone>>,
) -> Result<(), SignerError> {
Expand Down Expand Up @@ -907,6 +909,8 @@ impl ZoneSigner {
center,
zone,
domain::base::Serial(serial.into()),
None,
Some(id),
);

Ok(())
Expand Down
Loading
Loading