mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-13 16:32:56 +00:00
Startup continues to be slow, work towards to alleviate it. Summary of changes: - pretty the functional improvements from #4366 into `utils::completion::{Completion, Barrier}` - extend "initial load completion" usage up to tenant background tasks - previously only global background tasks - spawn_blocking the tenant load directory traversal - demote some logging - remove some unwraps - propagate some spans to `spawn_blocking` Runtime effects should be major speedup to loading, but after that, the `BACKGROUND_RUNTIME` will be blocked for a long time (minutes). Possible follow-ups: - complete initial tenant sizes before allowing background tasks to block the `BACKGROUND_RUNTIME`
34 lines
866 B
Rust
34 lines
866 B
Rust
use std::sync::Arc;
|
|
|
|
use tokio::sync::{mpsc, Mutex};
|
|
|
|
/// While a reference is kept around, the associated [`Barrier::wait`] will wait.
|
|
///
|
|
/// Can be cloned, moved and kept around in futures as "guard objects".
|
|
#[derive(Clone)]
|
|
pub struct Completion(mpsc::Sender<()>);
|
|
|
|
/// Barrier will wait until all clones of [`Completion`] have been dropped.
|
|
#[derive(Clone)]
|
|
pub struct Barrier(Arc<Mutex<mpsc::Receiver<()>>>);
|
|
|
|
impl Barrier {
|
|
pub async fn wait(self) {
|
|
self.0.lock().await.recv().await;
|
|
}
|
|
|
|
pub async fn maybe_wait(barrier: Option<Barrier>) {
|
|
if let Some(b) = barrier {
|
|
b.wait().await
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Create new Guard and Barrier pair.
|
|
pub fn channel() -> (Completion, Barrier) {
|
|
let (tx, rx) = mpsc::channel::<()>(1);
|
|
let rx = Mutex::new(rx);
|
|
let rx = Arc::new(rx);
|
|
(Completion(tx), Barrier(rx))
|
|
}
|