Skip to content

Commit d7b5867

Browse files
authored
Fix code talking about "views" instead of subscribers (#4591)
_Starting to cherry-pick some of the stuff buried in my caching branch_ Trivial.
1 parent 832da05 commit d7b5867

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

crates/re_arrow_store/src/store_event.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ mod tests {
498498
assert!(event.cells.contains_key(&store.cluster_key()));
499499

500500
let (events, _) = store.gc(&GarbageCollectionOptions::gc_everything());
501-
assert!(events.len() == 1);
501+
assert_eq!(1, events.len());
502502
assert!(events[0].cells.contains_key(&store.cluster_key()));
503503
}
504504

@@ -515,7 +515,7 @@ mod tests {
515515
assert!(!event.cells.contains_key(&store.cluster_key()));
516516

517517
let (events, _) = store.gc(&GarbageCollectionOptions::gc_everything());
518-
assert!(events.len() == 1);
518+
assert_eq!(1, events.len());
519519
assert!(!events[0].cells.contains_key(&store.cluster_key()));
520520
}
521521

crates/re_arrow_store/src/store_subscriber.rs

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type SharedStoreSubscriber = RwLock<Box<dyn StoreSubscriber>>;
1313
//
1414
// TODO(#4204): StoreSubscriber should require SizeBytes so they can be part of memstats.
1515
pub trait StoreSubscriber: std::any::Any + Send + Sync {
16-
/// Arbitrary name for the view.
16+
/// Arbitrary name for the subscriber.
1717
///
1818
/// Does not need to be unique.
1919
fn name(&self) -> String;
@@ -36,7 +36,7 @@ pub trait StoreSubscriber: std::any::Any + Send + Sync {
3636

3737
/// The core of this trait: get notified of changes happening in all [`DataStore`]s.
3838
///
39-
/// This will be called automatically by the [`DataStore`] itself if the view has been
39+
/// This will be called automatically by the [`DataStore`] itself if the subscriber has been
4040
/// registered: [`DataStore::register_subscriber`].
4141
/// Or you might want to feed it [`StoreEvent`]s manually, depending on your use case.
4242
///
@@ -72,65 +72,67 @@ impl DataStore {
7272
/// ## Scope
7373
///
7474
/// Registered [`StoreSubscriber`]s are global scope: they get notified of all events from all
75-
/// existing [`DataStore`]s, including [`DataStore`]s created after the view was registered.
75+
/// existing [`DataStore`]s, including [`DataStore`]s created after the subscriber was registered.
7676
///
7777
/// Use [`StoreEvent::store_id`] to identify the source of an event.
7878
///
7979
/// ## Late registration
8080
///
81-
/// Views must be registered before a store gets created to guarantee that no events were
82-
/// missed.
81+
/// Subscribers must be registered before a store gets created to guarantee that no events
82+
/// were missed.
8383
///
8484
/// [`StoreEvent::event_id`] can be used to identify missing events.
8585
///
8686
/// ## Ordering
8787
///
88-
/// The order in which registered views are notified is undefined and will likely become
88+
/// The order in which registered subscribers are notified is undefined and will likely become
8989
/// concurrent in the future.
9090
///
91-
/// If you need a specific order across multiple views, embed them into an orchestrating view.
91+
/// If you need a specific order across multiple subscribers, embed them into an orchestrating
92+
/// subscriber.
9293
//
9394
// TODO(cmc): send a compacted snapshot to late registerers for bootstrapping
94-
pub fn register_subscriber(view: Box<dyn StoreSubscriber>) -> StoreSubscriberHandle {
95-
let mut views = SUBSCRIBERS.write();
96-
views.push(RwLock::new(view));
97-
StoreSubscriberHandle(views.len() as u32 - 1)
95+
pub fn register_subscriber(subscriber: Box<dyn StoreSubscriber>) -> StoreSubscriberHandle {
96+
let mut subscribers = SUBSCRIBERS.write();
97+
subscribers.push(RwLock::new(subscriber));
98+
StoreSubscriberHandle(subscribers.len() as u32 - 1)
9899
}
99100

100-
/// Passes a reference to the downcasted view to the given callback.
101+
/// Passes a reference to the downcasted subscriber to the given callback.
101102
///
102-
/// Returns `None` if the view doesn't exist or downcasting failed.
103+
/// Returns `None` if the subscriber doesn't exist or downcasting failed.
103104
pub fn with_subscriber<V: StoreSubscriber, T, F: FnMut(&V) -> T>(
104105
StoreSubscriberHandle(handle): StoreSubscriberHandle,
105106
mut f: F,
106107
) -> Option<T> {
107-
let views = SUBSCRIBERS.read();
108-
views.get(handle as usize).and_then(|view| {
109-
let view = view.read();
110-
view.as_any().downcast_ref::<V>().map(&mut f)
108+
let subscribers = SUBSCRIBERS.read();
109+
subscribers.get(handle as usize).and_then(|subscriber| {
110+
let subscriber = subscriber.read();
111+
subscriber.as_any().downcast_ref::<V>().map(&mut f)
111112
})
112113
}
113114

114-
/// Passes a mutable reference to the downcasted view to the given callback.
115+
/// Passes a mutable reference to the downcasted subscriber to the given callback.
115116
///
116-
/// Returns `None` if the view doesn't exist or downcasting failed.
117+
/// Returns `None` if the subscriber doesn't exist or downcasting failed.
117118
pub fn with_subscriber_mut<V: StoreSubscriber, T, F: FnMut(&mut V) -> T>(
118119
StoreSubscriberHandle(handle): StoreSubscriberHandle,
119120
mut f: F,
120121
) -> Option<T> {
121-
let views = SUBSCRIBERS.read();
122-
views.get(handle as usize).and_then(|view| {
123-
let mut view = view.write();
124-
view.as_any_mut().downcast_mut::<V>().map(&mut f)
122+
let subscribers = SUBSCRIBERS.read();
123+
subscribers.get(handle as usize).and_then(|subscriber| {
124+
let mut subscriber = subscriber.write();
125+
subscriber.as_any_mut().downcast_mut::<V>().map(&mut f)
125126
})
126127
}
127128

128-
/// Called by [`DataStore`]'s mutating methods to notify view subscribers of upcoming events.
129+
/// Called by [`DataStore`]'s mutating methods to notify subscriber subscribers of upcoming events.
129130
pub(crate) fn on_events(events: &[StoreEvent]) {
130-
let views = SUBSCRIBERS.read();
131+
re_tracing::profile_function!();
132+
let subscribers = SUBSCRIBERS.read();
131133
// TODO(cmc): might want to parallelize at some point.
132-
for view in views.iter() {
133-
view.write().on_events(events);
134+
for subscriber in subscribers.iter() {
135+
subscriber.write().on_events(events);
134136
}
135137
}
136138
}

0 commit comments

Comments
 (0)