Skip to content

Commit

Permalink
Improve partition ID calculation (#1236)
Browse files Browse the repository at this point in the history
  • Loading branch information
spetz authored Sep 11, 2024
1 parent 638dab6 commit 4149a19
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "server"
version = "0.4.40"
version = "0.4.41"
edition = "2021"
build = "src/build.rs"

Expand Down
13 changes: 11 additions & 2 deletions server/src/streaming/topics/consumer_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,18 @@ impl ConsumerGroupMember {

pub fn calculate_partition_id(&mut self) -> u32 {
let partition_index = self.current_partition_index;
let partition_id = *self.partitions.get(&partition_index).unwrap();
let partition_id = if let Some(partition_id) = self.partitions.get(&partition_index) {
*partition_id
} else {
trace!(
"No partition ID found for index: {} for member with ID: {}.",
partition_index,
self.id
);
return 1;
};
self.current_partition_id = partition_id;
if self.partitions.len() == (partition_index + 1) as usize {
if self.partitions.len() <= (partition_index + 1) as usize {
self.current_partition_index = 0;
} else {
self.current_partition_index += 1;
Expand Down
2 changes: 1 addition & 1 deletion server/src/tcp/tcp_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub async fn start(address: &str, system: SharedSystem) -> SocketAddr {
tokio::spawn(async move {
let listener = TcpListener::bind(&address)
.await
.expect("Unable to start TCP TLS server.");
.expect("Unable to start TCP server.");

let local_addr = listener
.local_addr()
Expand Down

0 comments on commit 4149a19

Please sign in to comment.