Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions nominal-streaming/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,31 @@ impl SeriesBufferGuard<'_> {

self.count.fetch_add(new_point_count, Ordering::Release);
}

fn take(&mut self) -> (usize, Vec<Series>) {
let result = self
.sb
.drain()
.map(|(ChannelDescriptor { name, tags }, points)| {
let channel = Channel { name };
let points_obj = Points {
points_type: Some(points),
};
Series {
channel: Some(channel),
tags: tags
.map(|tags| tags.into_iter().collect())
.unwrap_or_default(),
points: Some(points_obj),
}
})
.collect();
let result_count = self
.count
.fetch_update(Ordering::Release, Ordering::Acquire, |_| Some(0))
Comment on lines +642 to +644
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write access to the count now must occur through SeriesBufferGuard, as SeriesBuffer is not in scope.

.unwrap();
(result_count, result)
}
}

impl PartialEq for SeriesBuffer {
Expand Down Expand Up @@ -669,28 +694,7 @@ impl SeriesBuffer {
UNIX_EPOCH.elapsed().unwrap().as_nanos() as u64,
Ordering::Release,
);
Comment on lines 694 to 696
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike count, flush_time is not considered in this PR.

The mechanics of how these two values are accessed are a little bit different, and I haven't considered flush_time deeply.

let result = points
.sb
.drain()
.map(|(ChannelDescriptor { name, tags }, points)| {
let channel = Channel { name };
let points_obj = Points {
points_type: Some(points),
};
Series {
channel: Some(channel),
tags: tags
.map(|tags| tags.into_iter().collect())
.unwrap_or_default(),
points: Some(points_obj),
}
})
.collect();
let result_count = self
.count
.fetch_update(Ordering::Release, Ordering::Acquire, |_| Some(0))
.unwrap();
(result_count, result)
points.take()
}

fn is_empty(&self) -> bool {
Expand Down