Track actors globally (eventually for reflection/introspection)

This commit is contained in:
Tony Garnock-Jones 2021-10-05 12:39:28 +02:00
parent 6fb1db4f6b
commit 2a7606d626
1 changed files with 8 additions and 9 deletions

View File

@ -506,8 +506,10 @@ preserves_schema::support::lazy_static! {
}; };
#[doc(hidden)] #[doc(hidden)]
pub static ref ACCOUNTS: RwLock<Map<u64, (tracing::Span, Arc<AtomicI64>)>> = pub static ref ACCOUNTS: RwLock<Map<u64, (tracing::Span, Arc<AtomicI64>)>> = Default::default();
RwLock::new(Map::new());
#[doc(hidden)]
pub static ref ACTORS: RwLock<Map<ActorId, (tracing::Span, ActorRef)>> = Default::default();
} }
impl TryFrom<&AnyValue> for Synced { impl TryFrom<&AnyValue> for Synced {
@ -1476,13 +1478,8 @@ impl Actor {
root: root.facet_id, root: root.facet_id,
}; };
st.facet_nodes.insert(root.facet_id, root); st.facet_nodes.insert(root.facet_id, root);
Actor { let ac_ref = ActorRef { actor_id, state: Arc::new(Mutex::new(ActorState::Running(st))) };
rx, Actor { rx, ac_ref }
ac_ref: ActorRef {
actor_id,
state: Arc::new(Mutex::new(ActorState::Running(st))),
},
}
} }
fn link(self, t_parent: &mut Activation) -> Self { fn link(self, t_parent: &mut Activation) -> Self {
@ -1506,6 +1503,7 @@ impl Actor {
name: tracing::Span, name: tracing::Span,
boot: F, boot: F,
) -> ActorHandle { ) -> ActorHandle {
ACTORS.write().insert(self.ac_ref.actor_id, (name.clone(), self.ac_ref.clone()));
name.record("actor_id", &self.ac_ref.actor_id); name.record("actor_id", &self.ac_ref.actor_id);
tokio::spawn(async move { tokio::spawn(async move {
tracing::trace!("start"); tracing::trace!("start");
@ -1744,6 +1742,7 @@ impl<T: Any + Send> Drop for Field<T> {
impl Drop for Actor { impl Drop for Actor {
fn drop(&mut self) { fn drop(&mut self) {
self.rx.close(); self.rx.close();
ACTORS.write().remove(&self.ac_ref.actor_id);
tracing::trace!(actor_id = ?self.ac_ref.actor_id, "Actor::drop"); tracing::trace!(actor_id = ?self.ac_ref.actor_id, "Actor::drop");
} }
} }