MCPcopy Create free account
hub / github.com/f0rr0/oliphaunt / seed_wasix_module_cache

Function seed_wasix_module_cache

src/pglite/postgres_mod.rs:2607–2645  ·  view source on GitHub ↗
(
    runtime: &TokioRuntime,
    engine: &Engine,
    module_cache: &Arc<SharedCache>,
    wasm_path: &Path,
    artifact_name: &str,
    label: &str,
)

Source from the content-addressed store, hash-verified

2605}
2606
2607fn seed_wasix_module_cache(
2608 runtime: &TokioRuntime,
2609 engine: &Engine,
2610 module_cache: &Arc<SharedCache>,
2611 wasm_path: &Path,
2612 artifact_name: &str,
2613 label: &str,
2614) -> Result<()> {
2615 let wasm = {
2616 let _phase = timing::phase("wasix.seed_side_module.read_wasm");
2617 fs::read(wasm_path).with_context(|| format!("read WASIX module {}", wasm_path.display()))?
2618 };
2619 let module_hash = {
2620 let _phase = timing::phase("wasix.seed_side_module.module_hash");
2621 ModuleHash::new(&wasm)
2622 };
2623 let seed_key = format!("{artifact_name}:{}:{module_hash}", aot::engine_identity());
2624 let mut seeded_side_modules = SEEDED_SIDE_MODULES
2625 .get_or_init(|| Mutex::new(HashSet::new()))
2626 .lock()
2627 .expect("seeded side module cache poisoned");
2628 if seeded_side_modules.contains(&seed_key) {
2629 return Ok(());
2630 }
2631
2632 // Keep the process-wide seed check and SharedCache write atomic. Wasmer's
2633 // shared cache is global to all concurrent PGlite instances in this process.
2634 let module = {
2635 let _phase = timing::phase("wasix.seed_side_module.load_aot");
2636 aot::load_artifact_module(engine, artifact_name)?
2637 };
2638 {
2639 let _phase = timing::phase("wasix.seed_side_module.save_cache");
2640 block_on_tokio_runtime(runtime, module_cache.save(module_hash, engine, &module))
2641 .with_context(|| format!("seed Wasmer module cache for {label} ({module_hash})"))?;
2642 }
2643 seeded_side_modules.insert(seed_key);
2644 Ok(())
2645}
2646
2647fn block_on_tokio_runtime<F, T>(runtime: &TokioRuntime, future: F) -> T
2648where

Callers 2

run_split_initdbFunction · 0.85
seed_side_module_cacheFunction · 0.85

Calls 4

phaseFunction · 0.85
load_artifact_moduleFunction · 0.85
block_on_tokio_runtimeFunction · 0.85
insertMethod · 0.80

Tested by

no test coverage detected