Skip to content
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

producer: refactor buffer impl #101

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
35 changes: 21 additions & 14 deletions src/hstreamdb/src/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,11 @@ impl Producer {
}
Ok(shard_id) => match self.shard_buffer.get_mut(&shard_id) {
None => {
let mut buffer_state: BufferState = default();
buffer_state.modify(&record);
let buffer_state: BufferState = {
let mut buffer_state = BufferState::default();
buffer_state.modify(&record);
buffer_state
};
self.shard_buffer_state.insert(shard_id, buffer_state);
self.shard_buffer.insert(shard_id, vec![record]);
self.shard_buffer_result
Expand All @@ -263,18 +266,22 @@ impl Producer {
}
}
Some(buffer) => {
self.shard_buffer_result
.get_mut(&shard_id)
.unwrap()
.push(result_sender);
let buffer_state = self.shard_buffer_state.get_mut(&shard_id).unwrap();
buffer_state.modify(&record);
buffer.push(record);

if buffer_state.check(&self.flush_settings) {
self.flush(shard_id).await.unwrap_or_else(|err| {
log::error!("producer flush error: shard_id = {shard_id}, {err}")
});
if buffer.is_empty() {
todo!()
} else {
self.shard_buffer_result
.get_mut(&shard_id)
.unwrap()
.push(result_sender);
let buffer_state = self.shard_buffer_state.get_mut(&shard_id).unwrap();
buffer_state.modify(&record);
buffer.push(record);

if buffer_state.check(&self.flush_settings) {
self.flush(shard_id).await.unwrap_or_else(|err| {
log::error!("producer flush error: shard_id = {shard_id}, {err}")
});
}
}
}
},
Expand Down