20260413_2 并行化架构优化第一阶段,apnic 串行98s->并行74s,传输层任务并行,同repo内发布点串行
This commit is contained in:
@@ -95,6 +95,13 @@ pub trait PublicationPointRunner {
|
||||
&self,
|
||||
ca: &CaInstanceHandle,
|
||||
) -> Result<PublicationPointRunResult, String>;
|
||||
|
||||
fn prefetch_discovered_children(
|
||||
&self,
|
||||
_children: &[DiscoveredChildCaInstance],
|
||||
) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
@@ -198,6 +205,12 @@ pub fn run_tree_serial_audit(
|
||||
.cmp(&b.discovered_from.child_ca_certificate_rsync_uri)
|
||||
})
|
||||
});
|
||||
if let Err(e) = runner.prefetch_discovered_children(&children) {
|
||||
warnings.push(
|
||||
Warning::new(format!("prefetch discovered children failed: {e}"))
|
||||
.with_context(&ca.manifest_rsync_uri),
|
||||
);
|
||||
}
|
||||
for child in children {
|
||||
queue.push_back(QueuedCaInstance {
|
||||
id: next_id,
|
||||
@@ -221,3 +234,109 @@ pub fn run_tree_serial_audit(
|
||||
publication_points,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use crate::audit::{DiscoveredFrom, PublicationPointAudit};
|
||||
use crate::validation::objects::{ObjectsOutput, ObjectsStats};
|
||||
|
||||
use super::{
|
||||
CaInstanceHandle, DiscoveredChildCaInstance, PublicationPointRunResult,
|
||||
PublicationPointRunner, TreeRunConfig, run_tree_serial_audit,
|
||||
};
|
||||
|
||||
fn sample_handle(manifest: &str) -> CaInstanceHandle {
|
||||
CaInstanceHandle {
|
||||
depth: 0,
|
||||
tal_id: "arin".to_string(),
|
||||
parent_manifest_rsync_uri: None,
|
||||
ca_certificate_der: vec![1, 2, 3],
|
||||
ca_certificate_rsync_uri: None,
|
||||
effective_ip_resources: None,
|
||||
effective_as_resources: None,
|
||||
rsync_base_uri: "rsync://example.test/repo/".to_string(),
|
||||
manifest_rsync_uri: manifest.to_string(),
|
||||
publication_point_rsync_uri: "rsync://example.test/repo/".to_string(),
|
||||
rrdp_notification_uri: None,
|
||||
}
|
||||
}
|
||||
|
||||
struct PrefetchRecordingRunner {
|
||||
seen_prefetch_children: Arc<Mutex<Vec<String>>>,
|
||||
}
|
||||
|
||||
impl PublicationPointRunner for PrefetchRecordingRunner {
|
||||
fn prefetch_discovered_children(
|
||||
&self,
|
||||
children: &[DiscoveredChildCaInstance],
|
||||
) -> Result<(), String> {
|
||||
let mut seen = self
|
||||
.seen_prefetch_children
|
||||
.lock()
|
||||
.expect("prefetch lock poisoned");
|
||||
seen.extend(
|
||||
children
|
||||
.iter()
|
||||
.map(|child| child.handle.manifest_rsync_uri.clone()),
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn run_publication_point(
|
||||
&self,
|
||||
ca: &CaInstanceHandle,
|
||||
) -> Result<PublicationPointRunResult, String> {
|
||||
let children = if ca.manifest_rsync_uri.ends_with("root.mft") {
|
||||
vec![DiscoveredChildCaInstance {
|
||||
handle: sample_handle("rsync://example.test/repo/child.mft"),
|
||||
discovered_from: DiscoveredFrom {
|
||||
parent_manifest_rsync_uri: ca.manifest_rsync_uri.clone(),
|
||||
child_ca_certificate_rsync_uri: "rsync://example.test/repo/child.cer"
|
||||
.to_string(),
|
||||
child_ca_certificate_sha256_hex: "00".repeat(32),
|
||||
},
|
||||
}]
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
|
||||
Ok(PublicationPointRunResult {
|
||||
source: crate::validation::manifest::PublicationPointSource::Fresh,
|
||||
snapshot: None,
|
||||
warnings: Vec::new(),
|
||||
objects: ObjectsOutput {
|
||||
vrps: Vec::new(),
|
||||
aspas: Vec::new(),
|
||||
router_keys: Vec::new(),
|
||||
local_outputs_cache: Vec::new(),
|
||||
warnings: Vec::new(),
|
||||
stats: ObjectsStats::default(),
|
||||
audit: Vec::new(),
|
||||
},
|
||||
audit: PublicationPointAudit::default(),
|
||||
discovered_children: children,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_tree_serial_audit_invokes_prefetch_hook_for_discovered_children() {
|
||||
let seen = Arc::new(Mutex::new(Vec::new()));
|
||||
let runner = PrefetchRecordingRunner {
|
||||
seen_prefetch_children: Arc::clone(&seen),
|
||||
};
|
||||
let out = run_tree_serial_audit(
|
||||
sample_handle("rsync://example.test/repo/root.mft"),
|
||||
&runner,
|
||||
&TreeRunConfig::default(),
|
||||
)
|
||||
.expect("tree run");
|
||||
assert_eq!(out.tree.instances_processed, 2);
|
||||
assert_eq!(
|
||||
seen.lock().expect("lock").as_slice(),
|
||||
["rsync://example.test/repo/child.mft"]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user