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

Refactor/better debug #683

Merged
merged 3 commits into from
Mar 13, 2024
Merged
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
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions crates/curp/src/server/storage/wal/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,8 @@ impl std::fmt::Debug for FilePipeline {

#[cfg(test)]
mod tests {
use crate::server::storage::wal::util::get_file_paths_with_ext;

use super::*;
use crate::server::storage::wal::util::get_file_paths_with_ext;

#[tokio::test]
async fn file_pipeline_is_ok() {
Expand Down
6 changes: 2 additions & 4 deletions crates/curp/src/server/storage/wal/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ use tokio::{
use tokio_stream::StreamExt;
use tokio_util::codec::Framed;

use crate::log_entry::LogEntry;

use super::{
codec::{DataFrame, WAL},
error::{CorruptType, WALError},
util::{get_checksum, parse_u64, validate_data, LockedFile},
WAL_FILE_EXT, WAL_MAGIC, WAL_VERSION,
};
use crate::log_entry::LogEntry;

/// The size of wal file header in bytes
const WAL_HEADER_SIZE: usize = 56;
Expand Down Expand Up @@ -415,9 +414,8 @@ mod tests {

use curp_test_utils::test_cmd::TestCommand;

use crate::log_entry::EntryData;

use super::*;
use crate::log_entry::EntryData;

#[tokio::test]
async fn segment_state_transition_is_correct() {
Expand Down
6 changes: 4 additions & 2 deletions crates/curp/src/tracker.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#![allow(unused)] // TODO remove when used

use std::collections::VecDeque;
use std::ops::{AddAssign, Sub};
use std::{
collections::VecDeque,
ops::{AddAssign, Sub},
};

use clippy_utilities::NumericCast;

Expand Down
20 changes: 20 additions & 0 deletions crates/utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,26 @@ pub mod tracing;
use ::tracing::debug;
pub use parser::*;

/// display all elements for the given vector
#[macro_export]
macro_rules! write_vec {
($f:expr, $name:expr, $vector:expr) => {
write!($f, "{}: [ ", { $name })?;
let last_idx = if $vector.is_empty() {
0
} else {
$vector.len() - 1
};
for (idx, element) in $vector.iter().enumerate() {
write!($f, "{}", element)?;
if idx != last_idx {
write!($f, ",")?;
}
}
write!($f, "]")?;
};
}

/// Get current timestamp in seconds
#[must_use]
#[inline]
Expand Down
12 changes: 9 additions & 3 deletions crates/xline/src/server/auth_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ where
&self,
mut request: tonic::Request<AuthUserAddRequest>,
) -> Result<tonic::Response<AuthUserAddResponse>, tonic::Status> {
debug!("Receive AuthUserAddRequest {:?}", request);
let user_add_req = request.get_mut();
debug!("Receive AuthUserAddRequest {}", user_add_req);
rogercloud marked this conversation as resolved.
Show resolved Hide resolved
user_add_req.validation()?;
let hashed_password = Self::hash_password(user_add_req.password.as_bytes());
user_add_req.hashed_password = hashed_password;
Expand Down Expand Up @@ -244,7 +244,10 @@ where
&self,
request: tonic::Request<AuthRoleGrantPermissionRequest>,
) -> Result<tonic::Response<AuthRoleGrantPermissionResponse>, tonic::Status> {
debug!("Receive AuthRoleGrantPermissionRequest {:?}", request);
debug!(
"Receive AuthRoleGrantPermissionRequest {}",
request.get_ref()
);
request.get_ref().validation()?;
self.handle_req(request, false).await
}
Expand All @@ -253,7 +256,10 @@ where
&self,
request: tonic::Request<AuthRoleRevokePermissionRequest>,
) -> Result<tonic::Response<AuthRoleRevokePermissionResponse>, tonic::Status> {
debug!("Receive AuthRoleRevokePermissionRequest {:?}", request);
debug!(
"Receive AuthRoleRevokePermissionRequest {}",
request.get_ref()
);
self.handle_req(request, false).await
}
}
14 changes: 7 additions & 7 deletions crates/xline/src/server/kv_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ where
) -> Result<tonic::Response<RangeResponse>, tonic::Status> {
let range_req = request.get_ref();
range_req.validation()?;
debug!("Receive grpc request: {:?}", range_req);
debug!("Receive grpc request: {}", range_req);
range_req.check_revision(
self.kv_storage.compacted_revision(),
self.kv_storage.revision(),
Expand Down Expand Up @@ -244,7 +244,7 @@ where
) -> Result<tonic::Response<PutResponse>, tonic::Status> {
let put_req: &PutRequest = request.get_ref();
put_req.validation()?;
debug!("Receive grpc request: {:?}", put_req);
debug!("Receive grpc request: {}", put_req);
let auth_info = self.auth_storage.try_get_auth_info_from_request(&request)?;
let is_fast_path = true;
let (cmd_res, sync_res) = self
Expand All @@ -253,7 +253,7 @@ where
let mut res = Self::parse_response_op(cmd_res.into_inner().into());
if let Some(sync_res) = sync_res {
let revision = sync_res.revision();
debug!("Get revision {:?} for PutRequest", revision);
debug!("Get revision {} for PutRequest", revision);
Self::update_header_revision(&mut res, revision);
}
if let Response::ResponsePut(response) = res {
Expand All @@ -273,7 +273,7 @@ where
) -> Result<tonic::Response<DeleteRangeResponse>, tonic::Status> {
let delete_range_req = request.get_ref();
delete_range_req.validation()?;
debug!("Receive grpc request: {:?}", delete_range_req);
debug!("Receive grpc request: {}", delete_range_req);
let auth_info = self.auth_storage.try_get_auth_info_from_request(&request)?;
let is_fast_path = true;
let (cmd_res, sync_res) = self
Expand All @@ -282,7 +282,7 @@ where
let mut res = Self::parse_response_op(cmd_res.into_inner().into());
if let Some(sync_res) = sync_res {
let revision = sync_res.revision();
debug!("Get revision {:?} for DeleteRangeRequest", revision);
debug!("Get revision {} for DeleteRangeRequest", revision);
Self::update_header_revision(&mut res, revision);
}
if let Response::ResponseDeleteRange(response) = res {
Expand All @@ -303,7 +303,7 @@ where
) -> Result<tonic::Response<TxnResponse>, tonic::Status> {
let txn_req = request.get_ref();
txn_req.validation()?;
debug!("Receive grpc request: {:?}", txn_req);
debug!("Receive grpc request: {}", txn_req);
txn_req.check_revision(
self.kv_storage.compacted_revision(),
self.kv_storage.revision(),
Expand All @@ -326,7 +326,7 @@ where
let mut res = Self::parse_response_op(cmd_res.into_inner().into());
if let Some(sync_res) = sync_res {
let revision = sync_res.revision();
debug!("Get revision {:?} for TxnRequest", revision);
debug!("Get revision {} for TxnRequest", revision);
Self::update_header_revision(&mut res, revision);
}
res
Expand Down
3 changes: 1 addition & 2 deletions crates/xline/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ mod watch_server;
/// Xline server
mod xline_server;

pub(crate) use self::auth_server::get_token;
pub(crate) use self::maintenance::MAINTENANCE_SNAPSHOT_CHUNK_SIZE;
pub use self::xline_server::XlineServer;
pub(crate) use self::{auth_server::get_token, maintenance::MAINTENANCE_SNAPSHOT_CHUNK_SIZE};
14 changes: 13 additions & 1 deletion crates/xline/src/storage/kvwatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use tracing::debug;
use utils::{
parking_lot_lock::RwLockMap,
task_manager::{tasks::TaskName, Listener, TaskManager},
write_vec,
};
use xlineapi::command::KeyRange;

Expand Down Expand Up @@ -540,7 +541,6 @@ where
}

/// Watch Event
#[derive(Debug)]
pub(crate) struct WatchEvent {
/// Watch ID
id: WatchId,
Expand All @@ -552,6 +552,18 @@ pub(crate) struct WatchEvent {
compacted: bool,
}

impl std::fmt::Debug for WatchEvent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"WatchEvent {{ id: {}, revision: {}, compacted: {}, ",
self.id, self.revision, self.compacted,
)?;
write_vec!(f, "events", self.events);
write!(f, " }}")
}
}

impl WatchEvent {
/// Get revision
pub(crate) fn revision(&self) -> i64 {
Expand Down
3 changes: 1 addition & 2 deletions crates/xline/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ pub(crate) mod revision;
/// Persistent storage abstraction
pub(crate) mod storage_api;

pub use self::revision::Revision;
pub(crate) use self::{
alarm_store::AlarmStore, auth_store::AuthStore, kv_store::KvStore, lease_store::LeaseStore,
};

pub use self::revision::Revision;
1 change: 1 addition & 0 deletions crates/xlineapi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ prost = "0.12.3"
serde = { version = "1.0.137", features = ["derive"] }
thiserror = "1.0.37"
tonic = { version = "0.4.1", package = "madsim-tonic" }
utils = { path = "../utils", features = ["parking_lot"] }
workspace-hack = { version = "0.1", path = "../../workspace-hack" }

[build-dependencies]
Expand Down
Loading
Loading