@@ -412,109 +412,6 @@ impl DataStore {
412
412
Ok ( updated)
413
413
}
414
414
415
- /// Attempts to acquire the instance-updater lock for the saga with ID
416
- /// `saga_id` at the current generation.
417
- ///
418
- /// # Arguments
419
- ///
420
- /// - `instance_id`: the UUID of the Instance to lock
421
- /// - `current_gen`: the current generation of the instance's `updater_id`
422
- /// - `saga_id`: the UUID of the saga that's attempting to lock this
423
- /// instance.
424
- ///
425
- /// # Returns
426
- ///
427
- /// - [`Ok`]`(`[`Some`]`(`[`InstanceUpdaterLock`]`))` if the lock was acquired.
428
- /// - [`Ok`]`(`[`None`]`)` if the lock could not be acquired (i.e. the
429
- /// generation has advanced since `current_gen` was captured)
430
- /// - [`Err`] if a database error occurred.
431
- pub async fn instance_updater_try_lock (
432
- & self ,
433
- opctx : & OpContext ,
434
- authz_instance : & authz:: Instance ,
435
- current_gen : Generation ,
436
- saga_lock_id : & Uuid ,
437
- ) -> Result < Option < Generation > , Error > {
438
- use db:: schema:: instance:: dsl;
439
-
440
- // The generation to advance to.
441
- let new_gen = Generation ( current_gen. 0 . next ( ) ) ;
442
-
443
- let instance_id = authz_instance. id ( ) ;
444
-
445
- let locked = diesel:: update ( dsl:: instance)
446
- . filter ( dsl:: time_deleted. is_null ( ) )
447
- . filter ( dsl:: id. eq ( instance_id) )
448
- // If the generation is the same as the captured generation, we can
449
- // lock this instance.
450
- . filter ( dsl:: updater_gen. eq ( current_gen) )
451
- . set ( (
452
- dsl:: updater_gen. eq ( new_gen) ,
453
- dsl:: updater_id. eq ( Some ( * saga_lock_id) ) ,
454
- ) )
455
- . check_if_exists :: < Instance > ( instance_id)
456
- . execute_and_check ( & * self . pool_connection_authorized ( opctx) . await ?)
457
- . await
458
- . map ( |r| match r. status {
459
- UpdateStatus :: Updated => Some ( new_gen) ,
460
- UpdateStatus :: NotUpdatedButExists => None ,
461
- } )
462
- . map_err ( |e| {
463
- public_error_from_diesel (
464
- e,
465
- ErrorHandler :: NotFoundByLookup (
466
- ResourceType :: Instance ,
467
- LookupType :: ById ( instance_id) ,
468
- ) ,
469
- )
470
- } ) ?;
471
-
472
- Ok ( locked)
473
- }
474
-
475
- /// Release the instance-updater lock.
476
- pub async fn instance_updater_unlock (
477
- & self ,
478
- opctx : & OpContext ,
479
- authz_instance : & authz:: Instance ,
480
- saga_lock_id : & Uuid ,
481
- ) -> Result < bool , Error > {
482
- use db:: schema:: instance:: dsl;
483
-
484
- let instance_id = authz_instance. id ( ) ;
485
-
486
- let unlocked = diesel:: update ( dsl:: instance)
487
- . filter ( dsl:: time_deleted. is_null ( ) )
488
- . filter ( dsl:: id. eq ( authz_instance. id ( ) ) )
489
- // Only unlock the instance if:
490
- // - the provided updater ID matches that of the saga that has
491
- // currently locked this instance.
492
- . filter ( dsl:: updater_id. eq ( Some ( * saga_lock_id) ) )
493
- . set ( (
494
- dsl:: updater_gen. eq ( dsl:: updater_gen + 1 ) ,
495
- dsl:: updater_id. eq ( None :: < Uuid > ) ,
496
- ) )
497
- . check_if_exists :: < Instance > ( instance_id)
498
- . execute_and_check ( & * self . pool_connection_authorized ( opctx) . await ?)
499
- . await
500
- . map ( |r| match r. status {
501
- UpdateStatus :: Updated => true ,
502
- // TODO(eliza): should this be an error?
503
- UpdateStatus :: NotUpdatedButExists => false ,
504
- } )
505
- . map_err ( |e| {
506
- public_error_from_diesel (
507
- e,
508
- ErrorHandler :: NotFoundByLookup (
509
- ResourceType :: Instance ,
510
- LookupType :: ById ( instance_id) ,
511
- ) ,
512
- )
513
- } ) ?;
514
-
515
- Ok ( unlocked)
516
- }
517
-
518
415
/// Updates an instance record and a VMM record with a single database
519
416
/// command.
520
417
///
0 commit comments