From e0d3b8ebdc7eea01c979cb2af0dd876b58de0ff5 Mon Sep 17 00:00:00 2001 From: John Spray Date: Thu, 19 Oct 2023 18:42:03 +0100 Subject: [PATCH] noisy completion --- libs/utils/src/completion.rs | 38 ++++++++++++++++++++++++++++---- pageserver/src/bin/pageserver.rs | 4 ++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/libs/utils/src/completion.rs b/libs/utils/src/completion.rs index e2e84dd0ee..d6797e5fe3 100644 --- a/libs/utils/src/completion.rs +++ b/libs/utils/src/completion.rs @@ -1,12 +1,36 @@ -use std::sync::Arc; +use std::sync::{atomic::AtomicI32, 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<()>); +pub struct Completion { + sender: mpsc::Sender<()>, + refcount: Arc, +} + +impl Clone for Completion { + fn clone(&self) -> Self { + let i = self + .refcount + .fetch_add(1, std::sync::atomic::Ordering::SeqCst); + tracing::info!("Completion::clone[{:p}]: {i}", &(*self.refcount)); + Self { + sender: self.sender.clone(), + refcount: self.refcount.clone(), + } + } +} + +impl Drop for Completion { + fn drop(&mut self) { + let i = self + .refcount + .fetch_sub(1, std::sync::atomic::Ordering::SeqCst); + tracing::info!("Completion::drop[{:p}]: {i}", &(*self.refcount)); + } +} /// Barrier will wait until all clones of [`Completion`] have been dropped. #[derive(Clone)] @@ -45,5 +69,11 @@ 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)) + ( + Completion { + sender: tx, + refcount: Arc::new(AtomicI32::new(1)), + }, + Barrier(rx), + ) } diff --git a/pageserver/src/bin/pageserver.rs b/pageserver/src/bin/pageserver.rs index 9518266467..c1304b8707 100644 --- a/pageserver/src/bin/pageserver.rs +++ b/pageserver/src/bin/pageserver.rs @@ -363,6 +363,10 @@ fn start_pageserver( let (background_jobs_can_start, background_jobs_barrier) = utils::completion::channel(); let (tenants_can_start, tenants_can_start_barrier) = utils::completion::channel(); + tracing::info!("init_remote_done_tx:"); + let c = init_remote_done_tx.clone(); + drop(c); + let order = pageserver::InitializationOrder { initial_tenant_load_remote: Some(init_done_tx), initial_tenant_load: Some(init_remote_done_tx),