@@ -70,10 +70,18 @@ impl SyncClient {
70
70
) ) ;
71
71
} ;
72
72
73
- let done = handle. run ( & mut active) ?;
74
- if done {
75
- * state = ClientState :: Idle ;
76
- }
73
+ match handle. run ( & mut active) {
74
+ Err ( e) => {
75
+ * state = ClientState :: Idle ;
76
+ return Err ( e) ;
77
+ }
78
+ Ok ( done) => {
79
+ if done {
80
+ active. instructions . push ( Instruction :: CloseSyncStream ) ;
81
+ * state = ClientState :: Idle ;
82
+ }
83
+ }
84
+ } ;
77
85
78
86
Ok ( active. instructions )
79
87
}
@@ -236,12 +244,12 @@ impl StreamingSyncIteration {
236
244
}
237
245
SyncLine :: CheckpointDiff ( diff) => {
238
246
let Some ( target) = target. target_checkpoint_mut ( ) else {
239
- event . instructions . push ( Instruction :: LogLine {
240
- severity : LogSeverity :: WARNING ,
241
- line : "Received checkpoint_diff without previous checkpoint"
242
- . to_string ( ) ,
243
- } ) ;
244
- break ;
247
+ return Err ( SQLiteError (
248
+ ResultCode :: ABORT ,
249
+ Some (
250
+ "Received checkpoint_diff without previous checkpoint" . to_string ( ) ,
251
+ ) ,
252
+ ) ) ;
245
253
} ;
246
254
247
255
target. apply_diff ( & diff) ;
@@ -255,9 +263,15 @@ impl StreamingSyncIteration {
255
263
) ;
256
264
}
257
265
SyncLine :: CheckpointComplete ( checkpoint_complete) => {
258
- let target = target
259
- . target_checkpoint ( )
260
- . expect ( "should have target checkpoint" ) ;
266
+ let Some ( target) = target. target_checkpoint_mut ( ) else {
267
+ return Err ( SQLiteError (
268
+ ResultCode :: ABORT ,
269
+ Some (
270
+ "Received checkpoint complete without previous checkpoint"
271
+ . to_string ( ) ,
272
+ ) ,
273
+ ) ) ;
274
+ } ;
261
275
let result = self . adapter . sync_local ( target, None ) ?;
262
276
263
277
match result {
@@ -272,7 +286,11 @@ impl StreamingSyncIteration {
272
286
break ;
273
287
}
274
288
SyncLocalResult :: PendingLocalChanges => {
275
- todo ! ( "Await pending uploads and try again" )
289
+ event. instructions . push ( Instruction :: LogLine {
290
+ severity : LogSeverity :: WARNING ,
291
+ line : format ! ( "TODO: Await pending uploads and try again" ) ,
292
+ } ) ;
293
+ break ;
276
294
}
277
295
SyncLocalResult :: ChangesApplied => {
278
296
event. instructions . push ( Instruction :: LogLine {
@@ -290,9 +308,15 @@ impl StreamingSyncIteration {
290
308
}
291
309
SyncLine :: CheckpointPartiallyComplete ( complete) => {
292
310
let priority = complete. priority ;
293
- let target = target
294
- . target_checkpoint ( )
295
- . expect ( "should have target checkpoint" ) ;
311
+ let Some ( target) = target. target_checkpoint_mut ( ) else {
312
+ return Err ( SQLiteError (
313
+ ResultCode :: ABORT ,
314
+ Some (
315
+ "Received checkpoint complete without previous checkpoint"
316
+ . to_string ( ) ,
317
+ ) ,
318
+ ) ) ;
319
+ } ;
296
320
let result = self . adapter . sync_local ( target, Some ( priority) ) ?;
297
321
298
322
match result {
@@ -356,7 +380,7 @@ impl StreamingSyncIteration {
356
380
. update ( |s| s. start_connecting ( ) , & mut event. instructions ) ;
357
381
358
382
let requests = self . adapter . collect_bucket_requests ( ) ?;
359
- let local_bucket_names: Vec < String > = requests. iter ( ) . map ( |s| s. after . clone ( ) ) . collect ( ) ;
383
+ let local_bucket_names: Vec < String > = requests. iter ( ) . map ( |s| s. name . clone ( ) ) . collect ( ) ;
360
384
let request = StreamingSyncRequest {
361
385
buckets : requests,
362
386
include_checksum : true ,
@@ -372,6 +396,7 @@ impl StreamingSyncIteration {
372
396
}
373
397
}
374
398
399
+ #[ derive( Debug ) ]
375
400
enum SyncTarget {
376
401
/// We've received a checkpoint line towards the given checkpoint. The tracked checkpoint is
377
402
/// updated for subsequent checkpoint or checkpoint_diff lines.
@@ -413,6 +438,7 @@ impl SyncTarget {
413
438
}
414
439
}
415
440
441
+ #[ derive( Debug ) ]
416
442
pub struct OwnedCheckpoint {
417
443
pub last_op_id : i64 ,
418
444
pub write_checkpoint : Option < i64 > ,
@@ -446,6 +472,7 @@ impl OwnedCheckpoint {
446
472
}
447
473
}
448
474
475
+ #[ derive( Debug ) ]
449
476
pub struct OwnedBucketChecksum {
450
477
pub bucket : String ,
451
478
pub checksum : i32 ,
@@ -461,13 +488,6 @@ impl OwnedBucketChecksum {
461
488
Some ( prio) => self . priority >= prio,
462
489
}
463
490
}
464
-
465
- fn description ( & self ) -> BucketDescription {
466
- BucketDescription {
467
- priority : self . priority ,
468
- name : self . bucket . clone ( ) ,
469
- }
470
- }
471
491
}
472
492
473
493
impl From < & ' _ BucketChecksum < ' _ > > for OwnedBucketChecksum {
0 commit comments