-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rust SDK: introduce MsgSender
builder-like interface for logging data
#1037
Changes from 10 commits
b6b35c6
49dff86
9ff9882
060dc01
15b669f
58b205c
b04cee1
048520c
4613d96
257470d
43c0b5e
6403be7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,51 +66,44 @@ impl DataStore { | |
/// If the bundle doesn't carry a payload for the cluster key, one will be auto-generated | ||
/// based on the length of the components in the payload, in the form of an array of | ||
/// monotonically increasing u64s going from `0` to `N-1`. | ||
pub fn insert(&mut self, bundle: &MsgBundle) -> WriteResult<()> { | ||
pub fn insert(&mut self, msg: &MsgBundle) -> WriteResult<()> { | ||
// TODO(cmc): kind & insert_id need to somehow propagate through the span system. | ||
self.insert_id += 1; | ||
|
||
let MsgBundle { | ||
msg_id, | ||
entity_path: ent_path, | ||
time_point, | ||
components, | ||
} = bundle; | ||
components: bundles, | ||
} = msg; | ||
|
||
if components.is_empty() { | ||
if bundles.is_empty() { | ||
return Ok(()); | ||
} | ||
|
||
crate::profile_function!(); | ||
|
||
let ent_path_hash = ent_path.hash(); | ||
let nb_rows = components[0].value.len(); | ||
let nb_rows = bundles[0].nb_rows(); | ||
|
||
// Effectively the same thing as having a non-unit length batch, except it's really not | ||
// worth more than an assertion since: | ||
// - A) `MsgBundle` should already guarantee this | ||
// - B) this limitation should be gone soon enough | ||
debug_assert!( | ||
bundle | ||
.components | ||
.iter() | ||
.map(|bundle| bundle.name) | ||
.all_unique(), | ||
msg.components.iter().map(|bundle| bundle.name).all_unique(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's a bit weird to refer both to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TL;DR: this is all in dire need of a terminology pass; at the moment I don't know of any good solution here.
The root of the issue is that I guess we'll clean all of this when we implement support for batch insertions. |
||
"cannot insert same component multiple times, this is equivalent to multiple rows", | ||
); | ||
// Batches cannot contain more than 1 row at the moment. | ||
if nb_rows != 1 { | ||
return Err(WriteError::MoreThanOneRow(nb_rows)); | ||
} | ||
// Components must share the same number of rows. | ||
if !components | ||
.iter() | ||
.all(|bundle| bundle.value.len() == nb_rows) | ||
{ | ||
if !bundles.iter().all(|bundle| bundle.nb_rows() == nb_rows) { | ||
return Err(WriteError::MismatchedRows( | ||
components | ||
bundles | ||
.iter() | ||
.map(|bundle| (bundle.name, bundle.value.len())) | ||
.map(|bundle| (bundle.name, bundle.nb_rows())) | ||
.collect(), | ||
)); | ||
} | ||
|
@@ -123,12 +116,12 @@ impl DataStore { | |
.map(|(timeline, time)| (timeline.name(), timeline.typ().format(*time))) | ||
.collect::<Vec<_>>(), | ||
entity = %ent_path, | ||
components = ?components.iter().map(|bundle| &bundle.name).collect::<Vec<_>>(), | ||
components = ?bundles.iter().map(|bundle| &bundle.name).collect::<Vec<_>>(), | ||
nb_rows, | ||
"insertion started..." | ||
); | ||
|
||
let cluster_comp_pos = components | ||
let cluster_comp_pos = bundles | ||
.iter() | ||
.find_position(|bundle| bundle.name == self.cluster_key) | ||
.map(|(pos, _)| pos); | ||
|
@@ -138,7 +131,7 @@ impl DataStore { | |
|
||
// TODO(#589): support for batched row component insertions | ||
for row_nr in 0..nb_rows { | ||
self.insert_timeless_row(row_nr, cluster_comp_pos, components, &mut row_indices)?; | ||
self.insert_timeless_row(row_nr, cluster_comp_pos, bundles, &mut row_indices)?; | ||
} | ||
|
||
let index = self | ||
|
@@ -155,7 +148,7 @@ impl DataStore { | |
time_point, | ||
row_nr, | ||
cluster_comp_pos, | ||
components, | ||
bundles, | ||
&mut row_indices, | ||
)?; | ||
} | ||
|
@@ -212,7 +205,7 @@ impl DataStore { | |
.iter() | ||
.filter(|bundle| bundle.name != self.cluster_key) | ||
{ | ||
let ComponentBundle { name, value: rows } = bundle; | ||
let (name, rows) = (bundle.name, bundle.value()); | ||
|
||
// Unwrapping a ListArray is somewhat costly, especially considering we're just | ||
// gonna rewrap it again in a minute... so we'd rather just slice it to a list of | ||
|
@@ -224,13 +217,12 @@ impl DataStore { | |
// So use the fact that `rows` is always of unit-length for now. | ||
let rows_single = rows; | ||
|
||
// TODO(#440): support for splats | ||
let nb_instances = rows_single.get_child_length(0); | ||
if nb_instances != cluster_len { | ||
return Err(WriteError::MismatchedInstances { | ||
cluster_comp: self.cluster_key, | ||
cluster_comp_nb_instances: cluster_len, | ||
key: *name, | ||
key: name, | ||
nb_instances, | ||
}); | ||
} | ||
|
@@ -240,13 +232,13 @@ impl DataStore { | |
.entry(bundle.name) | ||
.or_insert_with(|| { | ||
PersistentComponentTable::new( | ||
*name, | ||
name, | ||
ListArray::<i32>::get_child_type(rows_single.data_type()), | ||
) | ||
}); | ||
|
||
let row_idx = table.push(rows_single.as_ref()); | ||
row_indices.insert(*name, row_idx); | ||
row_indices.insert(name, row_idx); | ||
} | ||
|
||
Ok(()) | ||
|
@@ -285,7 +277,7 @@ impl DataStore { | |
.iter() | ||
.filter(|bundle| bundle.name != self.cluster_key) | ||
{ | ||
let ComponentBundle { name, value: rows } = bundle; | ||
let (name, rows) = (bundle.name, bundle.value()); | ||
|
||
// Unwrapping a ListArray is somewhat costly, especially considering we're just | ||
// gonna rewrap it again in a minute... so we'd rather just slice it to a list of | ||
|
@@ -303,20 +295,20 @@ impl DataStore { | |
return Err(WriteError::MismatchedInstances { | ||
cluster_comp: self.cluster_key, | ||
cluster_comp_nb_instances: cluster_len, | ||
key: *name, | ||
key: name, | ||
nb_instances, | ||
}); | ||
} | ||
|
||
let table = self.components.entry(bundle.name).or_insert_with(|| { | ||
ComponentTable::new( | ||
*name, | ||
name, | ||
ListArray::<i32>::get_child_type(rows_single.data_type()), | ||
) | ||
}); | ||
|
||
let row_idx = table.push(&self.config, time_point, rows_single.as_ref()); | ||
row_indices.insert(*name, row_idx); | ||
row_indices.insert(name, row_idx); | ||
} | ||
|
||
Ok(()) | ||
|
@@ -349,7 +341,7 @@ impl DataStore { | |
|
||
let cluster_comp = &components[cluster_comp_pos]; | ||
let data = cluster_comp | ||
.value | ||
.value() | ||
.as_any() | ||
.downcast_ref::<ListArray<i32>>() | ||
.unwrap() | ||
|
@@ -367,7 +359,7 @@ impl DataStore { | |
|
||
( | ||
len, | ||
ClusterData::UserData(cluster_comp.value.clone() /* shallow */), | ||
ClusterData::UserData(cluster_comp.value().to_boxed() /* shallow */), | ||
) | ||
} else { | ||
// The caller has not specified any cluster component, and so we'll have to generate | ||
|
@@ -378,7 +370,7 @@ impl DataStore { | |
// share the same length at this point anyway. | ||
let len = components | ||
.first() | ||
.map_or(0, |comp| comp.value.get_child_length(0)); | ||
.map_or(0, |comp| comp.value().get_child_length(0)); | ||
|
||
if let Some(row_idx) = self.cluster_comp_cache.get(&len) { | ||
// Cache hit! Re-use that row index. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't
components
a more descriptive name?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, see above.