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

Add trace errors in server binary #1314

Open
wants to merge 1 commit into
base: move-server-error-to-error-set
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions server/src/binary/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::binary::sender::Sender;
use crate::command::ServerCommand;
use crate::streaming::session::Session;
use crate::streaming::systems::system::SharedSystem;
use error_set::ResultContext;
use iggy::error::IggyError;
use tracing::{debug, error};

Expand All @@ -38,12 +39,16 @@ pub async fn handle(
Err(error) => {
error!("Command was not handled successfully, session: {session}, error: {error}.");
if let IggyError::ClientNotFound(_) = error {
sender.send_error_response(error).await?;
sender.send_error_response(error).await.with_error(|_| {
format!("BINARY - failed to send error response, session: {session}")
})?;
debug!("TCP error response was sent to: {session}.");
error!("Session: {session} will be deleted.");
Err(IggyError::ClientNotFound(session.client_id))
} else {
sender.send_error_response(error).await?;
sender.send_error_response(error).await.with_error(|_| {
format!("BINARY - failed to send error response, session: {session}")
})?;
debug!("TCP error response was sent to: {session}.");
Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::state::command::EntryCommand;
use crate::streaming::session::Session;
use crate::streaming::systems::system::SharedSystem;
use anyhow::Result;
use error_set::ResultContext;
use iggy::consumer_groups::create_consumer_group::CreateConsumerGroup;
use iggy::error::IggyError;
use tracing::{debug, instrument};
Expand All @@ -27,18 +28,35 @@ pub async fn handle(
command.group_id,
&command.name,
)
.await?;
.await
.with_error(|_| {
format!(
"CONSUMER_GROUP_HANDLER - failed to create consumer group for stream_id: {}, topic_id: {}, group_id: {:?}, session: {:?}",
command.stream_id, command.topic_id, command.group_id, session
)
})?;
let consumer_group = consumer_group.read().await;
response = mapper::map_consumer_group(&consumer_group).await;
}

let system = system.read().await;
let stream_id = command.stream_id.clone();
let topic_id = command.topic_id.clone();
let group_id = command.group_id.clone();

system
.state
.apply(
session.get_user_id(),
EntryCommand::CreateConsumerGroup(command),
)
.await?;
.await
.with_error(|_| {
format!(
"CONSUMER_GROUP_HANDLER - failed to apply create consumer group for stream_id: {}, topic_id: {}, group_id: {:?}, session: {}",
stream_id, topic_id, group_id, session
)
})?;
sender.send_ok_response(&response).await?;
Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::state::command::EntryCommand;
use crate::streaming::session::Session;
use crate::streaming::systems::system::SharedSystem;
use anyhow::Result;
use error_set::ResultContext;
use iggy::consumer_groups::delete_consumer_group::DeleteConsumerGroup;
use iggy::error::IggyError;
use tracing::{debug, instrument};
Expand All @@ -24,16 +25,30 @@ pub async fn handle(
&command.topic_id,
&command.group_id,
)
.await?;
.await.with_error(|_| format!(
"CONSUMER_GROUP_HANDLER - failed to delete consumer group for stream_id: {}, topic_id: {}, group_id: {:?}, session: {}",
command.stream_id, command.topic_id, command.group_id, session
))?;
}

let system = system.read().await;
let stream_id = command.stream_id.clone();
let topic_id = command.topic_id.clone();
let group_id = command.group_id.clone();

system
.state
.apply(
session.get_user_id(),
EntryCommand::DeleteConsumerGroup(command),
)
.await?;
.await
.with_error(|_| {
format!(
"CONSUMER_GROUP_HANDLER - failed to apply delete consumer group for stream_id: {}, topic_id: {}, group_id: {:?}, session: {}",
stream_id, topic_id, group_id, session
)
})?;
sender.send_empty_ok_response().await?;
Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::binary::sender::Sender;
use crate::streaming::session::Session;
use crate::streaming::systems::system::SharedSystem;
use anyhow::Result;
use error_set::ResultContext;
use iggy::consumer_groups::get_consumer_groups::GetConsumerGroups;
use iggy::error::IggyError;
use tracing::debug;
Expand All @@ -15,8 +16,14 @@ pub async fn handle(
) -> Result<(), IggyError> {
debug!("session: {session}, command: {command}");
let system = system.read().await;
let consumer_groups =
system.get_consumer_groups(session, &command.stream_id, &command.topic_id)?;
let consumer_groups = system
.get_consumer_groups(session, &command.stream_id, &command.topic_id)
.with_error(|_| {
format!(
"CONSUMER_GROUP_HANDLER - failed on getting consumer groups for stream_id: {}, topic_id: {}, session: {}",
command.stream_id, command.topic_id, session
)
})?;
let consumer_groups = mapper::map_consumer_groups(&consumer_groups).await;
sender.send_ok_response(&consumer_groups).await?;
Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::binary::sender::Sender;
use crate::streaming::session::Session;
use crate::streaming::systems::system::SharedSystem;
use anyhow::Result;
use error_set::ResultContext;
use iggy::consumer_groups::join_consumer_group::JoinConsumerGroup;
use iggy::error::IggyError;
use tracing::{debug, instrument};
Expand All @@ -22,7 +23,13 @@ pub async fn handle(
&command.topic_id,
&command.group_id,
)
.await?;
.await
.with_error(|_| {
format!(
"CONSUMER_GROUP_HANDLER - failed to join consumer group for stream_id: {}, topic_id: {}, group_id: {}, session: {}",
command.stream_id, command.topic_id, command.group_id, session
)
})?;
sender.send_empty_ok_response().await?;
Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::binary::sender::Sender;
use crate::streaming::session::Session;
use crate::streaming::systems::system::SharedSystem;
use anyhow::Result;
use error_set::ResultContext;
use iggy::consumer_groups::leave_consumer_group::LeaveConsumerGroup;
use iggy::error::IggyError;
use tracing::{debug, instrument};
Expand All @@ -22,7 +23,13 @@ pub async fn handle(
&command.topic_id,
&command.group_id,
)
.await?;
.await
.with_error(|_| {
format!(
"CONSUMER_GROUP_HANDLER - failed to leave consumer group for stream_id: {}, topic_id: {}, group_id: {}, session: {}",
command.stream_id, command.topic_id, command.group_id, session
)
})?;
sender.send_empty_ok_response().await?;
Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::binary::sender::Sender;
use crate::streaming::session::Session;
use crate::streaming::systems::system::SharedSystem;
use anyhow::Result;
use error_set::ResultContext;
use iggy::consumer_offsets::store_consumer_offset::StoreConsumerOffset;
use iggy::error::IggyError;
use tracing::debug;
Expand All @@ -20,10 +21,13 @@ pub async fn handle(
command.consumer,
&command.stream_id,
&command.topic_id,
command.partition_id,
command.offset,
command.partition_id.clone(),
command.offset.clone(),
)
.await?;
.await
.with_error(|_| format!("CONSUMER_OFFSET_HANDLER - failed to store consumer offset for stream_id: {}, topic_id: {}, partition_id: {:?}, offset: {}, session: {}",
Copy link
Contributor

Choose a reason for hiding this comment

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

since this with_error method is lazily called only on error, maybe we could try moving the command.partition_id.clone() and offset inside of there.

command.stream_id, command.topic_id, command.partition_id, command.offset, session
))?;
sender.send_empty_ok_response().await?;
Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::binary::sender::Sender;
use crate::streaming::session::Session;
use crate::streaming::systems::system::SharedSystem;
use anyhow::Result;
use error_set::ResultContext;
use iggy::error::IggyError;
use iggy::messages::flush_unsaved_buffer::FlushUnsavedBuffer;
use tracing::{debug, instrument};
Expand All @@ -15,13 +16,19 @@ pub async fn handle(
) -> Result<(), IggyError> {
debug!("session: {session}, command: {command}");
let system = system.read().await;
let stream_id = command.stream_id;
let topic_id = command.topic_id;
let partition_id = command.partition_id;
let stream_id = command.stream_id.clone();
let topic_id = command.topic_id.clone();
let partition_id = command.partition_id.clone();
let fsync = command.fsync;
system
.flush_unsaved_buffer(session, stream_id, topic_id, partition_id, fsync)
.await?;
.await
.with_error(|_| {
format!(
"MESSAGE_HANDLER - failed to flush unsaved buffer for stream_id: {}, topic_id: {}, partition_id: {}, session: {}",
command.stream_id, command.topic_id, command.partition_id, session
)
})?;
sender.send_empty_ok_response().await?;
Ok(())
}
9 changes: 7 additions & 2 deletions server/src/binary/handlers/messages/poll_messages_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::streaming::session::Session;
use crate::streaming::systems::messages::PollingArgs;
use crate::streaming::systems::system::SharedSystem;
use anyhow::Result;
use error_set::ResultContext;
use iggy::error::IggyError;
use iggy::messages::poll_messages::PollMessages;
use tracing::debug;
Expand All @@ -22,10 +23,14 @@ pub async fn handle(
&command.consumer,
&command.stream_id,
&command.topic_id,
command.partition_id,
command.partition_id.clone(),
PollingArgs::new(command.strategy, command.count, command.auto_commit),
)
.await?;
.await
.with_error(|_| format!(
"MESSAGE_HANDLER - failed to poll messages for consumer: {}, stream_id: {}, topic_id: {}, partition_id: {:?}, session: {}",
command.consumer, command.stream_id, command.topic_id, command.partition_id, session
))?;
let messages = mapper::map_polled_messages(&messages);
sender.send_ok_response(&messages).await?;
Ok(())
Expand Down
15 changes: 11 additions & 4 deletions server/src/binary/handlers/messages/send_messages_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::binary::sender::Sender;
use crate::streaming::session::Session;
use crate::streaming::systems::system::SharedSystem;
use anyhow::Result;
use error_set::ResultContext;
use iggy::error::IggyError;
use iggy::messages::send_messages::SendMessages;
use tracing::debug;
Expand All @@ -14,13 +15,19 @@ pub async fn handle(
) -> Result<(), IggyError> {
debug!("session: {session}, command: {command}");
let system = system.read().await;
let stream_id = command.stream_id;
let topic_id = command.topic_id;
let partitioning = command.partitioning;
let stream_id = command.stream_id.clone();
let topic_id = command.topic_id.clone();
let partitioning = command.partitioning.clone();
let messages = command.messages;
system
.append_messages(session, stream_id, topic_id, partitioning, messages)
.await?;
.await
.with_error(|_| {
format!(
"MESSAGE_HANDLER - failed to append messages for stream_id: {}, topic_id: {}, partitioning: {}, session: {}",
command.stream_id, command.topic_id, command.partitioning, session
)
})?;
sender.send_empty_ok_response().await?;
Ok(())
}
20 changes: 18 additions & 2 deletions server/src/binary/handlers/partitions/create_partitions_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::state::command::EntryCommand;
use crate::streaming::session::Session;
use crate::streaming::systems::system::SharedSystem;
use anyhow::Result;
use error_set::ResultContext;
use iggy::error::IggyError;
use iggy::partitions::create_partitions::CreatePartitions;
use tracing::{debug, instrument};
Expand All @@ -24,17 +25,32 @@ pub async fn handle(
&command.topic_id,
command.partitions_count,
)
.await?;
.await
.with_error(|_| {
format!(
"PARTITIONS_HANDLER - failed to create partitions for stream_id: {}, topic_id: {}, session: {}",
command.stream_id, command.topic_id, session
)
})?;
}

let system = system.read().await;
let stream_id = command.stream_id.clone();
let topic_id = command.topic_id.clone();

system
.state
.apply(
session.get_user_id(),
EntryCommand::CreatePartitions(command),
)
.await?;
.await
.with_error(|_| {
format!(
"PARTITIONS_HANDLER - failed to apply create partitions for stream_id: {}, topic_id: {}, session: {}",
stream_id, topic_id, session
)
})?;
sender.send_empty_ok_response().await?;
Ok(())
}
20 changes: 18 additions & 2 deletions server/src/binary/handlers/partitions/delete_partitions_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::state::command::EntryCommand;
use crate::streaming::session::Session;
use crate::streaming::systems::system::SharedSystem;
use anyhow::Result;
use error_set::ResultContext;
use iggy::error::IggyError;
use iggy::partitions::delete_partitions::DeletePartitions;
use tracing::{debug, instrument};
Expand All @@ -15,6 +16,9 @@ pub async fn handle(
system: &SharedSystem,
) -> Result<(), IggyError> {
debug!("session: {session}, command: {command}");
let stream_id = command.stream_id.clone();
let topic_id = command.topic_id.clone();

{
let mut system = system.write().await;
system
Expand All @@ -24,7 +28,13 @@ pub async fn handle(
&command.topic_id,
command.partitions_count,
)
.await?;
.await
.with_error(|_| {
format!(
"PARTITIONS_HANDLER - failed to delete partitions for stream_id: {}, topic_id: {}, session: {}",
stream_id, topic_id, session
)
})?;
}

let system = system.read().await;
Expand All @@ -34,7 +44,13 @@ pub async fn handle(
session.get_user_id(),
EntryCommand::DeletePartitions(command),
)
.await?;
.await
.with_error(|_| {
format!(
"PARTITIONS_HANDLER - failed to apply delete partitions for stream_id: {}, topic_id: {}, session: {}",
stream_id, topic_id, session
)
})?;
sender.send_empty_ok_response().await?;
Ok(())
}
Loading