@@ -159,8 +159,8 @@ pub struct InstanceAndVmms {
159
159
/// when the lock is released.
160
160
#[ derive( Debug , serde:: Serialize , serde:: Deserialize ) ]
161
161
pub struct UpdaterLock {
162
- pub saga_lock_id : Uuid ,
163
- pub locked_gen : Generation ,
162
+ updater_id : Uuid ,
163
+ locked_gen : Generation ,
164
164
}
165
165
166
166
/// Errors returned by [`DataStore::instance_updater_lock`].
@@ -685,7 +685,7 @@ impl DataStore {
685
685
/// # Arguments
686
686
///
687
687
/// - `authz_instance`: the instance to attempt to lock to lock
688
- /// - `saga_lock_id `: the UUID of the saga that's attempting to lock this
688
+ /// - `updater_id `: the UUID of the saga that's attempting to lock this
689
689
/// instance.
690
690
///
691
691
/// # Returns
@@ -700,7 +700,7 @@ impl DataStore {
700
700
& self ,
701
701
opctx : & OpContext ,
702
702
authz_instance : & authz:: Instance ,
703
- saga_lock_id : Uuid ,
703
+ updater_id : Uuid ,
704
704
) -> Result < UpdaterLock , UpdaterLockError > {
705
705
use db:: schema:: instance:: dsl;
706
706
@@ -726,16 +726,16 @@ impl DataStore {
726
726
match instance. updater_id {
727
727
// If the `updater_id` field is not null and the ID equals this
728
728
// saga's ID, we already have the lock. We're done here!
729
- Some ( lock_id) if lock_id == saga_lock_id => {
729
+ Some ( lock_id) if lock_id == updater_id => {
730
730
slog:: debug!(
731
731
& opctx. log,
732
732
"instance updater lock acquired!" ;
733
733
"instance_id" => %instance_id,
734
- "saga_id" => %saga_lock_id,
735
- "already_locked" => !did_lock,
734
+ "updater_id" => %updater_id,
736
735
"locked_gen" => ?locked_gen,
736
+ "already_locked" => !did_lock,
737
737
) ;
738
- return Ok ( UpdaterLock { saga_lock_id , locked_gen } ) ;
738
+ return Ok ( UpdaterLock { updater_id , locked_gen } ) ;
739
739
}
740
740
// The `updater_id` field is set, but it's not our ID. The instance
741
741
// is locked by a different saga, so give up.
@@ -745,7 +745,7 @@ impl DataStore {
745
745
"instance is locked by another saga" ;
746
746
"instance_id" => %instance_id,
747
747
"locked_by" => %lock_id,
748
- "saga_id " => %saga_lock_id ,
748
+ "updater_id " => %updater_id ,
749
749
) ;
750
750
return Err ( UpdaterLockError :: AlreadyLocked ) ;
751
751
}
@@ -761,7 +761,7 @@ impl DataStore {
761
761
& opctx. log,
762
762
"attempting to acquire instance updater lock" ;
763
763
"instance_id" => %instance_id,
764
- "saga_id " => %saga_lock_id ,
764
+ "updater_id " => %updater_id ,
765
765
"current_gen" => ?current_gen,
766
766
) ;
767
767
@@ -780,7 +780,7 @@ impl DataStore {
780
780
. filter ( dsl:: updater_gen. eq ( current_gen) )
781
781
. set ( (
782
782
dsl:: updater_gen. eq ( locked_gen) ,
783
- dsl:: updater_id. eq ( Some ( saga_lock_id ) ) ,
783
+ dsl:: updater_id. eq ( Some ( updater_id ) ) ,
784
784
) )
785
785
. check_if_exists :: < Instance > ( instance_id)
786
786
. execute_and_check (
@@ -813,7 +813,7 @@ impl DataStore {
813
813
& self ,
814
814
opctx : & OpContext ,
815
815
authz_instance : & authz:: Instance ,
816
- UpdaterLock { saga_lock_id : parent_id, locked_gen } : UpdaterLock ,
816
+ UpdaterLock { updater_id : parent_id, locked_gen } : UpdaterLock ,
817
817
child_lock_id : Uuid ,
818
818
) -> Result < UpdaterLock , UpdaterLockError > {
819
819
use db:: schema:: instance:: dsl;
@@ -851,11 +851,13 @@ impl DataStore {
851
851
& opctx. log,
852
852
"inherited lock from {parent_id} to {child_lock_id}" ;
853
853
"instance_id" => %instance_id,
854
+ "updater_id" => %child_lock_id,
854
855
"locked_gen" => ?new_gen,
856
+ "parent_id" => %parent_id,
855
857
"parent_gen" => ?locked_gen,
856
858
) ;
857
859
Ok ( UpdaterLock {
858
- saga_lock_id : child_lock_id,
860
+ updater_id : child_lock_id,
859
861
locked_gen : new_gen,
860
862
} )
861
863
}
@@ -868,7 +870,7 @@ impl DataStore {
868
870
} if found. updater_id == Some ( child_lock_id) => {
869
871
debug_assert_eq ! ( found. updater_gen, new_gen, ) ;
870
872
Ok ( UpdaterLock {
871
- saga_lock_id : child_lock_id,
873
+ updater_id : child_lock_id,
872
874
locked_gen : new_gen,
873
875
} )
874
876
}
@@ -883,7 +885,7 @@ impl DataStore {
883
885
/// [`DataStore::instance_updater_lock`].
884
886
///
885
887
/// This method will unlock the instance if (and only if) the lock is
886
- /// currently held by the provided `saga_lock_id `. If the lock is held by a
888
+ /// currently held by the provided `updater_id `. If the lock is held by a
887
889
/// different saga UUID, the instance will remain locked. If the instance
888
890
/// has already been unlocked, this method will return `false`.
889
891
///
@@ -896,7 +898,7 @@ impl DataStore {
896
898
& self ,
897
899
opctx : & OpContext ,
898
900
authz_instance : & authz:: Instance ,
899
- UpdaterLock { saga_lock_id , locked_gen } : UpdaterLock ,
901
+ UpdaterLock { updater_id , locked_gen } : UpdaterLock ,
900
902
) -> Result < bool , Error > {
901
903
use db:: schema:: instance:: dsl;
902
904
@@ -908,7 +910,7 @@ impl DataStore {
908
910
// Only unlock the instance if:
909
911
// - the provided updater ID matches that of the saga that has
910
912
// currently locked this instance.
911
- . filter ( dsl:: updater_id. eq ( Some ( saga_lock_id ) ) )
913
+ . filter ( dsl:: updater_id. eq ( Some ( updater_id ) ) )
912
914
// - the provided updater generation matches the current updater
913
915
// generation.
914
916
. filter ( dsl:: updater_gen. eq ( locked_gen) )
@@ -947,17 +949,17 @@ impl DataStore {
947
949
// is almost certainly a programmer error.
948
950
UpdateAndQueryResult { ref found, .. } => {
949
951
match found. updater_id {
950
- Some ( lock_holder ) => {
952
+ Some ( actual_id ) => {
951
953
slog:: error!(
952
954
& opctx. log,
953
955
"attempted to release a lock held by another saga" ;
954
956
"instance_id" => %instance_id,
955
- "saga_id " => %saga_lock_id ,
956
- "lock_holder " => %lock_holder ,
957
+ "updater_id " => %updater_id ,
958
+ "actual_id " => %actual_id ,
957
959
"found_gen" => ?found. updater_gen,
958
960
"locked_gen" => ?locked_gen,
959
961
) ;
960
- debug_assert_ne ! ( lock_holder , saga_lock_id ) ;
962
+ debug_assert_ne ! ( actual_id , updater_id ) ;
961
963
Err ( Error :: internal_error (
962
964
"attempted to release a lock held by another saga! this is a bug!" ,
963
965
) )
@@ -1067,7 +1069,7 @@ mod tests {
1067
1069
stringify!( $id)
1068
1070
) ) ;
1069
1071
assert_eq!(
1070
- lock. saga_lock_id ,
1072
+ lock. updater_id ,
1071
1073
$id,
1072
1074
"instance's `updater_id` must be set to {}" ,
1073
1075
stringify!( $id) ,
@@ -1137,7 +1139,7 @@ mod tests {
1137
1139
. await
1138
1140
)
1139
1141
. expect ( "instance should be locked" ) ;
1140
- assert_eq ! ( lock1. saga_lock_id , saga1) ;
1142
+ assert_eq ! ( lock1. updater_id , saga1) ;
1141
1143
1142
1144
// doing it again should be fine.
1143
1145
let lock2 = dbg ! (
@@ -1148,7 +1150,7 @@ mod tests {
1148
1150
. expect (
1149
1151
"instance_updater_lock should succeed again with the same saga ID" ,
1150
1152
) ;
1151
- assert_eq ! ( lock2. saga_lock_id , saga1) ;
1153
+ assert_eq ! ( lock2. updater_id , saga1) ;
1152
1154
// the generation should not have changed as a result of the second
1153
1155
// update.
1154
1156
assert_eq ! ( lock1. locked_gen, lock2. locked_gen) ;
@@ -1209,7 +1211,7 @@ mod tests {
1209
1211
// an incorrect one is constructed, or a raw database query
1210
1212
// attempts an invalid unlock operation.
1211
1213
UpdaterLock {
1212
- saga_lock_id : saga2,
1214
+ updater_id : saga2,
1213
1215
locked_gen: lock1. locked_gen,
1214
1216
} ,
1215
1217
)
@@ -1246,7 +1248,7 @@ mod tests {
1246
1248
// Again, these fields are private specifically to prevent
1247
1249
// you from doing this exact thing. But, we should still
1248
1250
// test that we handle it gracefully.
1249
- UpdaterLock { saga_lock_id : saga1, locked_gen: next_gen } ,
1251
+ UpdaterLock { updater_id : saga1, locked_gen: next_gen } ,
1250
1252
)
1251
1253
. await
1252
1254
)
0 commit comments