Skip to content

Commit c1580e1

Browse files
committed
move [NonError]QueryResponse to response module
1 parent 6723dd6 commit c1580e1

File tree

6 files changed

+121
-108
lines changed

6 files changed

+121
-108
lines changed

scylla/src/client/pager.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ use crate::deserialize::DeserializeOwnedRow;
3232
use crate::errors::ProtocolError;
3333
use crate::errors::{QueryError, UserRequestError};
3434
use crate::frame::response::result;
35-
use crate::network::{Connection, NonErrorQueryResponse, QueryResponse};
35+
use crate::network::Connection;
3636
use crate::observability::driver_tracing::RequestSpan;
3737
use crate::observability::history::{self, HistoryListener};
3838
use crate::observability::metrics::Metrics;
3939
use crate::policies::load_balancing::{self, RoutingInfo};
4040
use crate::policies::retry::{QueryInfo, RetryDecision, RetrySession};
41+
use crate::response::{NonErrorQueryResponse, QueryResponse};
4142
use crate::statement::{prepared_statement::PreparedStatement, query::Query};
4243
use crate::transport::query_result::ColumnSpecs;
4344
use tracing::{trace, trace_span, warn, Instrument};

scylla/src/client/session.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@ use crate::errors::{
1818
BadQuery, NewSessionError, ProtocolError, QueryError, TracingProtocolError, UserRequestError,
1919
};
2020
use crate::frame::response::result;
21-
use crate::network::PoolConfig;
2221
#[cfg(feature = "ssl")]
2322
use crate::network::SslConfig;
24-
use crate::network::{
25-
Connection, ConnectionConfig, NonErrorQueryResponse, QueryResponse, VerifiedKeyspaceName,
26-
};
23+
use crate::network::{Connection, ConnectionConfig, PoolConfig, VerifiedKeyspaceName};
2724
use crate::observability::driver_tracing::RequestSpan;
2825
use crate::observability::history::{self, HistoryListener};
2926
use crate::observability::metrics::Metrics;
@@ -35,6 +32,7 @@ use crate::policies::retry::{QueryInfo, RetryDecision, RetrySession};
3532
use crate::policies::speculative_execution;
3633
use crate::prepared_statement::PreparedStatement;
3734
use crate::query::Query;
35+
use crate::response::{NonErrorQueryResponse, QueryResponse};
3836
use crate::routing::partitioner::PartitionerName;
3937
use crate::routing::Shard;
4038
use crate::statement::StatementConfig;

scylla/src/network/connection.rs

Lines changed: 2 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ use crate::frame::protocol_features::ProtocolFeatures;
1717
use crate::frame::{
1818
self,
1919
request::{self, batch, execute, query, register, SerializableRequest},
20-
response::{event::Event, result, NonErrorResponse, Response, ResponseOpcode},
20+
response::{event::Event, result, Response, ResponseOpcode},
2121
server_event_type::EventType,
2222
FrameParams, SerializedRequest,
2323
};
2424
use crate::policies::address_translator::AddressTranslator;
2525
use crate::query::Query;
26+
use crate::response::{NonErrorAuthResponse, NonErrorStartupResponse, QueryResponse};
2627
use crate::routing::locator::tablets::{RawTablet, TabletParsingError};
2728
use crate::routing::{Shard, ShardInfo, Sharder};
2829
use crate::statement::prepared_statement::PreparedStatement;
@@ -208,105 +209,6 @@ struct TaskResponse {
208209
body: Bytes,
209210
}
210211

211-
pub(crate) struct QueryResponse {
212-
pub(crate) response: Response,
213-
pub(crate) tracing_id: Option<Uuid>,
214-
pub(crate) warnings: Vec<String>,
215-
#[allow(dead_code)] // This is not exposed to user (yet?)
216-
pub(crate) custom_payload: Option<HashMap<String, Bytes>>,
217-
}
218-
219-
// A QueryResponse in which response can not be Response::Error
220-
pub(crate) struct NonErrorQueryResponse {
221-
pub(crate) response: NonErrorResponse,
222-
pub(crate) tracing_id: Option<Uuid>,
223-
pub(crate) warnings: Vec<String>,
224-
}
225-
226-
impl QueryResponse {
227-
pub(crate) fn into_non_error_query_response(
228-
self,
229-
) -> Result<NonErrorQueryResponse, UserRequestError> {
230-
Ok(NonErrorQueryResponse {
231-
response: self.response.into_non_error_response()?,
232-
tracing_id: self.tracing_id,
233-
warnings: self.warnings,
234-
})
235-
}
236-
237-
pub(crate) fn into_query_result_and_paging_state(
238-
self,
239-
) -> Result<(QueryResult, PagingStateResponse), UserRequestError> {
240-
self.into_non_error_query_response()?
241-
.into_query_result_and_paging_state()
242-
}
243-
244-
pub(crate) fn into_query_result(self) -> Result<QueryResult, QueryError> {
245-
self.into_non_error_query_response()?.into_query_result()
246-
}
247-
}
248-
249-
impl NonErrorQueryResponse {
250-
pub(crate) fn as_set_keyspace(&self) -> Option<&result::SetKeyspace> {
251-
match &self.response {
252-
NonErrorResponse::Result(result::Result::SetKeyspace(sk)) => Some(sk),
253-
_ => None,
254-
}
255-
}
256-
257-
pub(crate) fn as_schema_change(&self) -> Option<&result::SchemaChange> {
258-
match &self.response {
259-
NonErrorResponse::Result(result::Result::SchemaChange(sc)) => Some(sc),
260-
_ => None,
261-
}
262-
}
263-
264-
pub(crate) fn into_query_result_and_paging_state(
265-
self,
266-
) -> Result<(QueryResult, PagingStateResponse), UserRequestError> {
267-
let (raw_rows, paging_state_response) = match self.response {
268-
NonErrorResponse::Result(result::Result::Rows((rs, paging_state_response))) => {
269-
(Some(rs), paging_state_response)
270-
}
271-
NonErrorResponse::Result(_) => (None, PagingStateResponse::NoMorePages),
272-
_ => {
273-
return Err(UserRequestError::UnexpectedResponse(
274-
self.response.to_response_kind(),
275-
))
276-
}
277-
};
278-
279-
Ok((
280-
QueryResult::new(raw_rows, self.tracing_id, self.warnings),
281-
paging_state_response,
282-
))
283-
}
284-
285-
pub(crate) fn into_query_result(self) -> Result<QueryResult, QueryError> {
286-
let (result, paging_state) = self.into_query_result_and_paging_state()?;
287-
288-
if !paging_state.finished() {
289-
error!(
290-
"Internal driver API misuse or a server bug: nonfinished paging state\
291-
would be discarded by `NonErrorQueryResponse::into_query_result`"
292-
);
293-
return Err(ProtocolError::NonfinishedPagingState.into());
294-
}
295-
296-
Ok(result)
297-
}
298-
}
299-
300-
pub(crate) enum NonErrorStartupResponse {
301-
Ready,
302-
Authenticate(response::authenticate::Authenticate),
303-
}
304-
305-
pub(crate) enum NonErrorAuthResponse {
306-
AuthChallenge(response::authenticate::AuthChallenge),
307-
AuthSuccess(response::authenticate::AuthSuccess),
308-
}
309-
310212
#[cfg(feature = "ssl")]
311213
mod ssl_config {
312214
use openssl::{

scylla/src/network/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
mod connection;
88
#[cfg(feature = "ssl")]
99
pub(crate) use connection::SslConfig;
10-
pub(crate) use connection::{
11-
Connection, ConnectionConfig, NonErrorQueryResponse, QueryResponse, VerifiedKeyspaceName,
12-
};
10+
pub(crate) use connection::{Connection, ConnectionConfig, VerifiedKeyspaceName};
1311

1412
mod connection_pool;
1513

scylla/src/response/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
mod request_response;
12

3+
pub(crate) use request_response::{
4+
NonErrorAuthResponse, NonErrorQueryResponse, NonErrorStartupResponse, QueryResponse,
5+
};
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
use std::collections::HashMap;
2+
3+
use bytes::Bytes;
4+
use scylla_cql::frame::request::query::PagingStateResponse;
5+
use scylla_cql::frame::response::{NonErrorResponse, Response};
6+
use tracing::error;
7+
use uuid::Uuid;
8+
9+
use crate::errors::{ProtocolError, QueryError, UserRequestError};
10+
use crate::frame::response::{self, result};
11+
use crate::QueryResult;
12+
13+
pub(crate) struct QueryResponse {
14+
pub(crate) response: Response,
15+
pub(crate) tracing_id: Option<Uuid>,
16+
pub(crate) warnings: Vec<String>,
17+
#[allow(dead_code)] // This is not exposed to user (yet?)
18+
pub(crate) custom_payload: Option<HashMap<String, Bytes>>,
19+
}
20+
21+
// A QueryResponse in which response can not be Response::Error
22+
pub(crate) struct NonErrorQueryResponse {
23+
pub(crate) response: NonErrorResponse,
24+
pub(crate) tracing_id: Option<Uuid>,
25+
pub(crate) warnings: Vec<String>,
26+
}
27+
28+
impl QueryResponse {
29+
pub(crate) fn into_non_error_query_response(
30+
self,
31+
) -> Result<NonErrorQueryResponse, UserRequestError> {
32+
Ok(NonErrorQueryResponse {
33+
response: self.response.into_non_error_response()?,
34+
tracing_id: self.tracing_id,
35+
warnings: self.warnings,
36+
})
37+
}
38+
39+
pub(crate) fn into_query_result_and_paging_state(
40+
self,
41+
) -> Result<(QueryResult, PagingStateResponse), UserRequestError> {
42+
self.into_non_error_query_response()?
43+
.into_query_result_and_paging_state()
44+
}
45+
46+
pub(crate) fn into_query_result(self) -> Result<QueryResult, QueryError> {
47+
self.into_non_error_query_response()?.into_query_result()
48+
}
49+
}
50+
51+
impl NonErrorQueryResponse {
52+
pub(crate) fn as_set_keyspace(&self) -> Option<&result::SetKeyspace> {
53+
match &self.response {
54+
NonErrorResponse::Result(result::Result::SetKeyspace(sk)) => Some(sk),
55+
_ => None,
56+
}
57+
}
58+
59+
pub(crate) fn as_schema_change(&self) -> Option<&result::SchemaChange> {
60+
match &self.response {
61+
NonErrorResponse::Result(result::Result::SchemaChange(sc)) => Some(sc),
62+
_ => None,
63+
}
64+
}
65+
66+
pub(crate) fn into_query_result_and_paging_state(
67+
self,
68+
) -> Result<(QueryResult, PagingStateResponse), UserRequestError> {
69+
let (raw_rows, paging_state_response) = match self.response {
70+
NonErrorResponse::Result(result::Result::Rows((rs, paging_state_response))) => {
71+
(Some(rs), paging_state_response)
72+
}
73+
NonErrorResponse::Result(_) => (None, PagingStateResponse::NoMorePages),
74+
_ => {
75+
return Err(UserRequestError::UnexpectedResponse(
76+
self.response.to_response_kind(),
77+
))
78+
}
79+
};
80+
81+
Ok((
82+
QueryResult::new(raw_rows, self.tracing_id, self.warnings),
83+
paging_state_response,
84+
))
85+
}
86+
87+
pub(crate) fn into_query_result(self) -> Result<QueryResult, QueryError> {
88+
let (result, paging_state) = self.into_query_result_and_paging_state()?;
89+
90+
if !paging_state.finished() {
91+
error!(
92+
"Internal driver API misuse or a server bug: nonfinished paging state\
93+
would be discarded by `NonErrorQueryResponse::into_query_result`"
94+
);
95+
return Err(ProtocolError::NonfinishedPagingState.into());
96+
}
97+
98+
Ok(result)
99+
}
100+
}
101+
102+
pub(crate) enum NonErrorStartupResponse {
103+
Ready,
104+
Authenticate(response::authenticate::Authenticate),
105+
}
106+
107+
pub(crate) enum NonErrorAuthResponse {
108+
AuthChallenge(response::authenticate::AuthChallenge),
109+
AuthSuccess(response::authenticate::AuthSuccess),
110+
}

0 commit comments

Comments
 (0)