1
+ use anyhow;
1
2
use futures:: stream:: StreamExt ;
2
3
use scylla:: batch:: Consistency ;
3
4
use scylla:: cql_to_rust:: { FromCqlVal , FromCqlValError } ;
4
5
use scylla:: frame:: response:: result:: { CqlValue , Row } ;
5
6
use scylla:: frame:: value:: { Timestamp , Value , ValueTooBig } ;
6
7
use scylla:: query:: Query ;
7
8
use scylla:: { FromRow , IntoTypedRows , Session } ;
8
- use std:: error:: Error ;
9
9
use std:: sync:: Arc ;
10
10
11
11
#[ derive( Debug , Clone , Eq , PartialEq , Hash , Ord , PartialOrd , FromRow ) ]
@@ -73,7 +73,7 @@ impl GenerationFetcher {
73
73
74
74
/// In case of a success returns a vector containing all the generations in the database.
75
75
/// Propagates all errors.
76
- pub async fn fetch_all_generations ( & self ) -> Result < Vec < GenerationTimestamp > , Box < dyn Error > > {
76
+ pub async fn fetch_all_generations ( & self ) -> anyhow :: Result < Vec < GenerationTimestamp > > {
77
77
let mut generations = Vec :: new ( ) ;
78
78
79
79
let mut query =
@@ -115,7 +115,7 @@ impl GenerationFetcher {
115
115
pub async fn fetch_generation_by_timestamp (
116
116
& self ,
117
117
time : & chrono:: Duration ,
118
- ) -> Result < Option < GenerationTimestamp > , Box < dyn Error > > {
118
+ ) -> anyhow :: Result < Option < GenerationTimestamp > > {
119
119
let query =
120
120
new_distributed_system_query ( self . get_generation_by_timestamp_query ( ) , & self . session )
121
121
. await ?;
@@ -146,7 +146,7 @@ impl GenerationFetcher {
146
146
pub async fn fetch_next_generation (
147
147
& self ,
148
148
generation : & GenerationTimestamp ,
149
- ) -> Result < Option < GenerationTimestamp > , Box < dyn Error > > {
149
+ ) -> anyhow :: Result < Option < GenerationTimestamp > > {
150
150
let query =
151
151
new_distributed_system_query ( self . get_next_generation_query ( ) , & self . session ) . await ?;
152
152
@@ -172,7 +172,7 @@ impl GenerationFetcher {
172
172
pub async fn fetch_stream_ids (
173
173
& self ,
174
174
generation : & GenerationTimestamp ,
175
- ) -> Result < Vec < Vec < StreamID > > , Box < dyn Error > > {
175
+ ) -> anyhow :: Result < Vec < Vec < StreamID > > > {
176
176
let mut result_vec = Vec :: new ( ) ;
177
177
178
178
let mut query =
@@ -195,9 +195,7 @@ impl GenerationFetcher {
195
195
}
196
196
197
197
// Return single row containing generation.
198
- fn return_single_row (
199
- row : Option < Vec < Row > > ,
200
- ) -> Result < Option < GenerationTimestamp > , Box < dyn Error > > {
198
+ fn return_single_row ( row : Option < Vec < Row > > ) -> anyhow:: Result < Option < GenerationTimestamp > > {
201
199
if let Some ( row) = row {
202
200
if let Some ( generation) = row. into_typed :: < GenerationTimestamp > ( ) . next ( ) {
203
201
return Ok ( Some ( generation?) ) ;
@@ -209,7 +207,7 @@ impl GenerationFetcher {
209
207
}
210
208
211
209
// Returns current cluster size in case of a success.
212
- async fn get_cluster_size ( session : & Session ) -> Result < usize , Box < dyn Error > > {
210
+ async fn get_cluster_size ( session : & Session ) -> anyhow :: Result < usize > {
213
211
// We are using default consistency here since the system keyspace is special and
214
212
// the coordinator which handles the query will only read local data
215
213
// and will not contact other nodes, so the query will work with any cluster size larger than 0.
@@ -225,18 +223,15 @@ async fn get_cluster_size(session: &Session) -> Result<usize, Box<dyn Error>> {
225
223
}
226
224
227
225
// Choose appropriate consistency level depending on the cluster size.
228
- async fn select_consistency ( session : & Session , query : & mut Query ) -> Result < ( ) , Box < dyn Error > > {
226
+ async fn select_consistency ( session : & Session , query : & mut Query ) -> anyhow :: Result < ( ) > {
229
227
query. set_consistency ( match get_cluster_size ( session) . await ? {
230
228
1 => Consistency :: One ,
231
229
_ => Consistency :: Quorum ,
232
230
} ) ;
233
231
Ok ( ( ) )
234
232
}
235
233
236
- async fn new_distributed_system_query (
237
- stmt : String ,
238
- session : & Session ,
239
- ) -> Result < Query , Box < dyn Error > > {
234
+ async fn new_distributed_system_query ( stmt : String , session : & Session ) -> anyhow:: Result < Query > {
240
235
let mut query = Query :: new ( stmt) ;
241
236
select_consistency ( session, & mut query) . await ?;
242
237
@@ -369,7 +364,7 @@ mod tests {
369
364
}
370
365
371
366
// Create setup for tests.
372
- async fn setup ( ) -> Result < GenerationFetcher , Box < dyn Error > > {
367
+ async fn setup ( ) -> anyhow :: Result < GenerationFetcher > {
373
368
let uri = std:: env:: var ( "SCYLLA_URI" ) . unwrap_or_else ( |_| "127.0.0.1:9042" . to_string ( ) ) ;
374
369
375
370
let session = SessionBuilder :: new ( ) . known_node ( uri) . build ( ) . await ?;
0 commit comments