Skip to main content

laminar_db/db/topology/
target_preparation.rs

1//! Publish target preparation only from a retained image and observed runtime owners.
2
3use std::time::Duration;
4
5use laminar_core::cluster::control::{TopologyAdmissionStatus, TopologyError};
6
7use super::{DbError, LaminarDB, PreparedTopologyRestore};
8
9impl LaminarDB {
10    /// Certify this database's private exact-root target after observing parent retirement.
11    /// Reuses the existing terminal lifecycle even on retry, then publishes one exact-process
12    /// receipt through the configured controller. The caller cannot supply a termination flag,
13    /// root, process identity or receipt. The target remains unstarted and the parent cut,
14    /// namespace and catalog remain held. This does not commit or activate the target.
15    ///
16    /// The total cooperative deadline is 45 seconds. Unresolved runtime owners remain in the DB;
17    /// the image stays owned by the caller. A cancelled/uncertain append may have succeeded:
18    /// query operation status and retry this same image. Dropping an image never releases intake.
19    /// The durable receipt is historical evidence, not a promise that this image is still resident.
20    ///
21    /// # Errors
22    /// Rejects foreign/stale images, authority/recovery faults and unobserved termination.
23    pub async fn certify_cluster_topology_target_preparation(
24        &self,
25        image: &mut PreparedTopologyRestore,
26    ) -> Result<TopologyAdmissionStatus, DbError> {
27        tokio::time::timeout(Duration::from_secs(45), async {
28            self.retire_cluster_topology_parent(image).await?;
29            let controller = self.cluster_controller.lock().clone().ok_or_else(|| {
30                TopologyError::Protocol(
31                    "target preparation requires the configured controller".into(),
32                )
33            })?;
34            let status = controller
35                .certify_topology_target_preparation(&image.input)
36                .await?;
37            self.validate_topology_retirement_input(&image.input)
38                .await?;
39            Ok(status)
40        })
41        .await
42        .map_err(|_| TopologyError::Contended)?
43    }
44}