@@ -6,7 +6,7 @@ use bytes::Bytes;
6
6
use chrono:: Utc ;
7
7
use http:: { HeaderValue , StatusCode } ;
8
8
use hyper:: Body ;
9
- use tokio:: io:: AsyncWriteExt as _;
9
+ use tokio:: { io:: AsyncWriteExt as _, task :: AbortHandle } ;
10
10
use uuid:: Uuid ;
11
11
12
12
#[ cfg( test) ]
@@ -81,6 +81,14 @@ pub struct PushResult {
81
81
baton : Option < String > ,
82
82
}
83
83
84
+ pub struct DropAbort ( pub AbortHandle ) ;
85
+
86
+ impl Drop for DropAbort {
87
+ fn drop ( & mut self ) {
88
+ self . 0 . abort ( ) ;
89
+ }
90
+ }
91
+
84
92
pub enum PushStatus {
85
93
Ok ,
86
94
Conflict ,
@@ -216,7 +224,9 @@ impl SyncContext {
216
224
217
225
match result. status {
218
226
PushStatus :: Conflict => {
219
- return Err ( SyncError :: InvalidPushFrameConflict ( frame_no, result. max_frame_no ) . into ( ) ) ;
227
+ return Err (
228
+ SyncError :: InvalidPushFrameConflict ( frame_no, result. max_frame_no ) . into ( ) ,
229
+ ) ;
220
230
}
221
231
_ => { }
222
232
}
@@ -251,7 +261,11 @@ impl SyncContext {
251
261
tracing:: debug!( ?durable_frame_num, "frame successfully pushed" ) ;
252
262
253
263
// Update our last known max_frame_no from the server.
254
- tracing:: debug!( ?generation, ?durable_frame_num, "updating remote generation and durable_frame_num" ) ;
264
+ tracing:: debug!(
265
+ ?generation,
266
+ ?durable_frame_num,
267
+ "updating remote generation and durable_frame_num"
268
+ ) ;
255
269
self . durable_generation = generation;
256
270
self . durable_frame_num = durable_frame_num;
257
271
@@ -261,7 +275,12 @@ impl SyncContext {
261
275
} )
262
276
}
263
277
264
- async fn push_with_retry ( & self , mut uri : String , body : Bytes , max_retries : usize ) -> Result < PushResult > {
278
+ async fn push_with_retry (
279
+ & self ,
280
+ mut uri : String ,
281
+ body : Bytes ,
282
+ max_retries : usize ,
283
+ ) -> Result < PushResult > {
265
284
let mut nr_retries = 0 ;
266
285
loop {
267
286
let mut req = http:: Request :: post ( uri. clone ( ) ) ;
@@ -402,7 +421,9 @@ impl SyncContext {
402
421
}
403
422
// BUG ALERT: The server returns a 500 error if the remote database is empty.
404
423
// This is a bug and should be fixed.
405
- if res. status ( ) == StatusCode :: BAD_REQUEST || res. status ( ) == StatusCode :: INTERNAL_SERVER_ERROR {
424
+ if res. status ( ) == StatusCode :: BAD_REQUEST
425
+ || res. status ( ) == StatusCode :: INTERNAL_SERVER_ERROR
426
+ {
406
427
let res_body = hyper:: body:: to_bytes ( res. into_body ( ) )
407
428
. await
408
429
. map_err ( SyncError :: HttpBody ) ?;
@@ -417,7 +438,9 @@ impl SyncContext {
417
438
let generation = generation
418
439
. as_u64 ( )
419
440
. ok_or_else ( || SyncError :: JsonValue ( generation. clone ( ) ) ) ?;
420
- return Ok ( PullResult :: EndOfGeneration { max_generation : generation as u32 } ) ;
441
+ return Ok ( PullResult :: EndOfGeneration {
442
+ max_generation : generation as u32 ,
443
+ } ) ;
421
444
}
422
445
if res. status ( ) . is_redirection ( ) {
423
446
uri = match res. headers ( ) . get ( hyper:: header:: LOCATION ) {
@@ -449,7 +472,6 @@ impl SyncContext {
449
472
}
450
473
}
451
474
452
-
453
475
pub ( crate ) fn next_generation ( & mut self ) {
454
476
self . durable_generation += 1 ;
455
477
self . durable_frame_num = 0 ;
@@ -741,9 +763,7 @@ pub async fn bootstrap_db(sync_ctx: &mut SyncContext) -> Result<()> {
741
763
// if we are lagging behind, then we will call the export API and get to the latest
742
764
// generation directly.
743
765
let info = sync_ctx. get_remote_info ( ) . await ?;
744
- sync_ctx
745
- . sync_db_if_needed ( info. current_generation )
746
- . await ?;
766
+ sync_ctx. sync_db_if_needed ( info. current_generation ) . await ?;
747
767
// when sync_ctx is initialised, we set durable_generation to 0. however, once
748
768
// sync_db is called, it should be > 0.
749
769
assert ! ( sync_ctx. durable_generation > 0 , "generation should be > 0" ) ;
@@ -871,7 +891,7 @@ pub async fn try_pull(
871
891
let insert_handle = conn. wal_insert_handle ( ) ?;
872
892
873
893
let mut err = None ;
874
-
894
+
875
895
loop {
876
896
let generation = sync_ctx. durable_generation ( ) ;
877
897
let frame_no = sync_ctx. durable_frame_num ( ) + 1 ;
0 commit comments