Skip to content

Commit 2b5f386

Browse files
piodulwprzytula
andcommitted
{session,tracing}: switch to the new deser framework for tracing info
Adjusts the Session::try_getting_tracing_info method to use the new deserialization framework. Co-authored-by: Wojciech Przytuła <[email protected]>
1 parent f3aae01 commit 2b5f386

File tree

3 files changed

+53
-83
lines changed

3 files changed

+53
-83
lines changed

scylla/src/tracing.rs

Lines changed: 7 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1+
use crate::frame::value::CqlTimestamp;
12
use itertools::Itertools;
23
use scylla_cql::frame::value::CqlTimeuuid;
4+
use scylla_macros::DeserializeRow;
35
use std::collections::HashMap;
46
use std::net::IpAddr;
57

6-
use crate::cql_to_rust::{FromRow, FromRowError};
7-
use crate::frame::response::result::Row;
8-
use crate::frame::value::CqlTimestamp;
9-
108
/// Tracing info retrieved from `system_traces.sessions`
119
/// with all events from `system_traces.events`
12-
#[derive(Debug, Clone, PartialEq, Eq)]
10+
#[derive(Debug, DeserializeRow, Clone, PartialEq, Eq)]
11+
#[scylla(crate = "crate")]
1312
pub struct TracingInfo {
1413
pub client: Option<IpAddr>,
1514
pub command: Option<String>,
@@ -20,11 +19,13 @@ pub struct TracingInfo {
2019
/// started_at is a timestamp - time since unix epoch
2120
pub started_at: Option<CqlTimestamp>,
2221

22+
#[scylla(skip)]
2323
pub events: Vec<TracingEvent>,
2424
}
2525

2626
/// A single event happening during a traced query
27-
#[derive(Debug, Clone, PartialEq, Eq)]
27+
#[derive(Debug, DeserializeRow, Clone, PartialEq, Eq)]
28+
#[scylla(crate = "crate")]
2829
pub struct TracingEvent {
2930
pub event_id: CqlTimeuuid,
3031
pub activity: Option<String>,
@@ -53,51 +54,3 @@ pub(crate) const TRACES_SESSION_QUERY_STR: &str =
5354
pub(crate) const TRACES_EVENTS_QUERY_STR: &str =
5455
"SELECT event_id, activity, source, source_elapsed, thread \
5556
FROM system_traces.events WHERE session_id = ?";
56-
57-
// Converts a row received by performing TRACES_SESSION_QUERY_STR to TracingInfo
58-
impl FromRow for TracingInfo {
59-
fn from_row(row: Row) -> Result<TracingInfo, FromRowError> {
60-
let (client, command, coordinator, duration, parameters, request, started_at) =
61-
<(
62-
Option<IpAddr>,
63-
Option<String>,
64-
Option<IpAddr>,
65-
Option<i32>,
66-
Option<HashMap<String, String>>,
67-
Option<String>,
68-
Option<CqlTimestamp>,
69-
)>::from_row(row)?;
70-
71-
Ok(TracingInfo {
72-
client,
73-
command,
74-
coordinator,
75-
duration,
76-
parameters,
77-
request,
78-
started_at,
79-
events: Vec::new(),
80-
})
81-
}
82-
}
83-
84-
// Converts a row received by performing TRACES_SESSION_QUERY_STR to TracingInfo
85-
impl FromRow for TracingEvent {
86-
fn from_row(row: Row) -> Result<TracingEvent, FromRowError> {
87-
let (event_id, activity, source, source_elapsed, thread) = <(
88-
CqlTimeuuid,
89-
Option<String>,
90-
Option<IpAddr>,
91-
Option<i32>,
92-
Option<String>,
93-
)>::from_row(row)?;
94-
95-
Ok(TracingEvent {
96-
event_id,
97-
activity,
98-
source,
99-
source_elapsed,
100-
thread,
101-
})
102-
}
103-
}

scylla/src/transport/errors.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use std::{
1313
};
1414

1515
use scylla_cql::{
16-
cql_to_rust::FromRowError,
1716
frame::{
1817
frame_errors::{
1918
CqlAuthChallengeParseError, CqlAuthSuccessParseError, CqlAuthenticateParseError,
@@ -25,14 +24,17 @@ use scylla_cql::{
2524
response::CqlResponseKind,
2625
value::SerializeValuesError,
2726
},
28-
types::{deserialize::TypeCheckError, serialize::SerializationError},
27+
types::{
28+
deserialize::{DeserializationError, TypeCheckError},
29+
serialize::SerializationError,
30+
},
2931
};
3032

3133
use thiserror::Error;
3234

3335
use crate::{authentication::AuthError, frame::response};
3436

35-
use super::{legacy_query_result::RowsExpectedError, query_result::SingleRowError};
37+
use super::query_result::SingleRowError;
3638

3739
/// Error that occurred during query execution
3840
#[derive(Error, Debug, Clone)]
@@ -360,20 +362,28 @@ pub enum SchemaVersionFetchError {
360362
#[non_exhaustive]
361363
pub enum TracingProtocolError {
362364
/// Response to system_traces.session is not RESULT:Rows.
363-
#[error("Response to system_traces.session is not RESULT:Rows: {0}")]
364-
TracesSessionNotRows(RowsExpectedError),
365+
#[error("Response to system_traces.session is not RESULT:Rows")]
366+
TracesSessionNotRows,
365367

366368
/// system_traces.session has invalid column type.
367369
#[error("system_traces.session has invalid column type: {0}")]
368-
TracesSessionInvalidColumnType(FromRowError),
370+
TracesSessionInvalidColumnType(TypeCheckError),
371+
372+
/// Response to system_traces.session failed to deserialize.
373+
#[error("Response to system_traces.session failed to deserialize: {0}")]
374+
TracesSessionDeserializationFailed(DeserializationError),
369375

370376
/// Response to system_traces.events is not RESULT:Rows.
371-
#[error("Response to system_traces.events is not RESULT:Rows: {0}")]
372-
TracesEventsNotRows(RowsExpectedError),
377+
#[error("Response to system_traces.events is not RESULT:Rows")]
378+
TracesEventsNotRows,
373379

374380
/// system_traces.events has invalid column type.
375381
#[error("system_traces.events has invalid column type: {0}")]
376-
TracesEventsInvalidColumnType(FromRowError),
382+
TracesEventsInvalidColumnType(TypeCheckError),
383+
384+
/// Response to system_traces.events failed to deserialize.
385+
#[error("Response to system_traces.events failed to deserialize: {0}")]
386+
TracesEventsDeserializationFailed(DeserializationError),
377387

378388
/// All tracing queries returned an empty result.
379389
#[error(

scylla/src/transport/session.rs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,20 @@ use super::connection::SslConfig;
4646
use super::errors::TracingProtocolError;
4747
use super::execution_profile::{ExecutionProfile, ExecutionProfileHandle, ExecutionProfileInner};
4848
use super::iterator::QueryPager;
49-
use super::legacy_query_result::MaybeFirstRowTypedError;
5049
#[cfg(feature = "cloud")]
5150
use super::node::CloudEndpoint;
5251
use super::node::{InternalKnownNode, KnownNode};
5352
use super::partitioner::PartitionerName;
53+
use super::query_result::MaybeFirstRowError;
54+
use super::query_result::RowsError;
5455
use super::topology::UntranslatedPeer;
5556
use super::{NodeRef, SelfIdentity};
5657
use crate::frame::response::result;
5758
use crate::prepared_statement::PreparedStatement;
5859
use crate::query::Query;
5960
use crate::routing::{Shard, Token};
6061
use crate::statement::{Consistency, PageSize, PagingState, PagingStateResponse};
61-
use crate::tracing::{TracingEvent, TracingInfo};
62+
use crate::tracing::TracingInfo;
6263
use crate::transport::cluster::{Cluster, ClusterData, ClusterNeatDebug};
6364
use crate::transport::connection::{Connection, ConnectionConfig, VerifiedKeyspaceName};
6465
use crate::transport::connection_pool::PoolConfig;
@@ -1790,15 +1791,18 @@ where
17901791

17911792
// Get tracing info
17921793
let maybe_tracing_info: Option<TracingInfo> = traces_session_res
1793-
.into_legacy_result()?
1794-
.maybe_first_row_typed()
1794+
.into_rows_result()?
1795+
.ok_or(ProtocolError::Tracing(
1796+
TracingProtocolError::TracesSessionNotRows,
1797+
))?
1798+
.maybe_first_row()
17951799
.map_err(|err| match err {
1796-
MaybeFirstRowTypedError::RowsExpected(e) => {
1797-
ProtocolError::Tracing(TracingProtocolError::TracesSessionNotRows(e))
1798-
}
1799-
MaybeFirstRowTypedError::FromRowError(e) => {
1800+
MaybeFirstRowError::TypeCheckFailed(e) => {
18001801
ProtocolError::Tracing(TracingProtocolError::TracesSessionInvalidColumnType(e))
18011802
}
1803+
MaybeFirstRowError::DeserializationFailed(e) => ProtocolError::Tracing(
1804+
TracingProtocolError::TracesSessionDeserializationFailed(e),
1805+
),
18021806
})?;
18031807

18041808
let mut tracing_info = match maybe_tracing_info {
@@ -1807,20 +1811,23 @@ where
18071811
};
18081812

18091813
// Get tracing events
1810-
let tracing_event_rows = traces_events_res
1811-
.into_legacy_result()?
1812-
.rows_typed()
1813-
.map_err(|err| {
1814-
ProtocolError::Tracing(TracingProtocolError::TracesEventsNotRows(err))
1815-
})?;
1816-
1817-
for event in tracing_event_rows {
1818-
let tracing_event: TracingEvent = event.map_err(|err| {
1814+
let tracing_event_rows_result =
1815+
traces_events_res
1816+
.into_rows_result()?
1817+
.ok_or(ProtocolError::Tracing(
1818+
TracingProtocolError::TracesEventsNotRows,
1819+
))?;
1820+
let tracing_event_rows = tracing_event_rows_result.rows().map_err(|err| match err {
1821+
RowsError::TypeCheckFailed(err) => {
18191822
ProtocolError::Tracing(TracingProtocolError::TracesEventsInvalidColumnType(err))
1820-
})?;
1823+
}
1824+
})?;
18211825

1822-
tracing_info.events.push(tracing_event);
1823-
}
1826+
tracing_info.events = tracing_event_rows
1827+
.collect::<Result<_, _>>()
1828+
.map_err(|err| {
1829+
ProtocolError::Tracing(TracingProtocolError::TracesEventsDeserializationFailed(err))
1830+
})?;
18241831

18251832
if tracing_info.events.is_empty() {
18261833
return Ok(None);

0 commit comments

Comments
 (0)