Skip to content

Commit 80368a5

Browse files
committed
more consistent naming for logs
1 parent 8e7a1ef commit 80368a5

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

nexus/db-queries/src/db/datastore/instance.rs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ pub struct InstanceAndVmms {
159159
/// when the lock is released.
160160
#[derive(Debug, serde::Serialize, serde::Deserialize)]
161161
pub struct UpdaterLock {
162-
pub saga_lock_id: Uuid,
163-
pub locked_gen: Generation,
162+
updater_id: Uuid,
163+
locked_gen: Generation,
164164
}
165165

166166
/// Errors returned by [`DataStore::instance_updater_lock`].
@@ -685,7 +685,7 @@ impl DataStore {
685685
/// # Arguments
686686
///
687687
/// - `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
689689
/// instance.
690690
///
691691
/// # Returns
@@ -700,7 +700,7 @@ impl DataStore {
700700
&self,
701701
opctx: &OpContext,
702702
authz_instance: &authz::Instance,
703-
saga_lock_id: Uuid,
703+
updater_id: Uuid,
704704
) -> Result<UpdaterLock, UpdaterLockError> {
705705
use db::schema::instance::dsl;
706706

@@ -726,16 +726,16 @@ impl DataStore {
726726
match instance.updater_id {
727727
// If the `updater_id` field is not null and the ID equals this
728728
// 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 => {
730730
slog::debug!(
731731
&opctx.log,
732732
"instance updater lock acquired!";
733733
"instance_id" => %instance_id,
734-
"saga_id" => %saga_lock_id,
735-
"already_locked" => !did_lock,
734+
"updater_id" => %updater_id,
736735
"locked_gen" => ?locked_gen,
736+
"already_locked" => !did_lock,
737737
);
738-
return Ok(UpdaterLock { saga_lock_id, locked_gen });
738+
return Ok(UpdaterLock { updater_id, locked_gen });
739739
}
740740
// The `updater_id` field is set, but it's not our ID. The instance
741741
// is locked by a different saga, so give up.
@@ -745,7 +745,7 @@ impl DataStore {
745745
"instance is locked by another saga";
746746
"instance_id" => %instance_id,
747747
"locked_by" => %lock_id,
748-
"saga_id" => %saga_lock_id,
748+
"updater_id" => %updater_id,
749749
);
750750
return Err(UpdaterLockError::AlreadyLocked);
751751
}
@@ -761,7 +761,7 @@ impl DataStore {
761761
&opctx.log,
762762
"attempting to acquire instance updater lock";
763763
"instance_id" => %instance_id,
764-
"saga_id" => %saga_lock_id,
764+
"updater_id" => %updater_id,
765765
"current_gen" => ?current_gen,
766766
);
767767

@@ -780,7 +780,7 @@ impl DataStore {
780780
.filter(dsl::updater_gen.eq(current_gen))
781781
.set((
782782
dsl::updater_gen.eq(locked_gen),
783-
dsl::updater_id.eq(Some(saga_lock_id)),
783+
dsl::updater_id.eq(Some(updater_id)),
784784
))
785785
.check_if_exists::<Instance>(instance_id)
786786
.execute_and_check(
@@ -813,7 +813,7 @@ impl DataStore {
813813
&self,
814814
opctx: &OpContext,
815815
authz_instance: &authz::Instance,
816-
UpdaterLock { saga_lock_id: parent_id, locked_gen }: UpdaterLock,
816+
UpdaterLock { updater_id: parent_id, locked_gen }: UpdaterLock,
817817
child_lock_id: Uuid,
818818
) -> Result<UpdaterLock, UpdaterLockError> {
819819
use db::schema::instance::dsl;
@@ -851,11 +851,13 @@ impl DataStore {
851851
&opctx.log,
852852
"inherited lock from {parent_id} to {child_lock_id}";
853853
"instance_id" => %instance_id,
854+
"updater_id" => %child_lock_id,
854855
"locked_gen" => ?new_gen,
856+
"parent_id" => %parent_id,
855857
"parent_gen" => ?locked_gen,
856858
);
857859
Ok(UpdaterLock {
858-
saga_lock_id: child_lock_id,
860+
updater_id: child_lock_id,
859861
locked_gen: new_gen,
860862
})
861863
}
@@ -868,7 +870,7 @@ impl DataStore {
868870
} if found.updater_id == Some(child_lock_id) => {
869871
debug_assert_eq!(found.updater_gen, new_gen,);
870872
Ok(UpdaterLock {
871-
saga_lock_id: child_lock_id,
873+
updater_id: child_lock_id,
872874
locked_gen: new_gen,
873875
})
874876
}
@@ -883,7 +885,7 @@ impl DataStore {
883885
/// [`DataStore::instance_updater_lock`].
884886
///
885887
/// 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
887889
/// different saga UUID, the instance will remain locked. If the instance
888890
/// has already been unlocked, this method will return `false`.
889891
///
@@ -896,7 +898,7 @@ impl DataStore {
896898
&self,
897899
opctx: &OpContext,
898900
authz_instance: &authz::Instance,
899-
UpdaterLock { saga_lock_id, locked_gen }: UpdaterLock,
901+
UpdaterLock { updater_id, locked_gen }: UpdaterLock,
900902
) -> Result<bool, Error> {
901903
use db::schema::instance::dsl;
902904

@@ -908,7 +910,7 @@ impl DataStore {
908910
// Only unlock the instance if:
909911
// - the provided updater ID matches that of the saga that has
910912
// currently locked this instance.
911-
.filter(dsl::updater_id.eq(Some(saga_lock_id)))
913+
.filter(dsl::updater_id.eq(Some(updater_id)))
912914
// - the provided updater generation matches the current updater
913915
// generation.
914916
.filter(dsl::updater_gen.eq(locked_gen))
@@ -947,17 +949,17 @@ impl DataStore {
947949
// is almost certainly a programmer error.
948950
UpdateAndQueryResult { ref found, .. } => {
949951
match found.updater_id {
950-
Some(lock_holder) => {
952+
Some(actual_id) => {
951953
slog::error!(
952954
&opctx.log,
953955
"attempted to release a lock held by another saga";
954956
"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,
957959
"found_gen" => ?found.updater_gen,
958960
"locked_gen" => ?locked_gen,
959961
);
960-
debug_assert_ne!(lock_holder, saga_lock_id);
962+
debug_assert_ne!(actual_id, updater_id);
961963
Err(Error::internal_error(
962964
"attempted to release a lock held by another saga! this is a bug!",
963965
))
@@ -1067,7 +1069,7 @@ mod tests {
10671069
stringify!($id)
10681070
));
10691071
assert_eq!(
1070-
lock.saga_lock_id,
1072+
lock.updater_id,
10711073
$id,
10721074
"instance's `updater_id` must be set to {}",
10731075
stringify!($id),
@@ -1137,7 +1139,7 @@ mod tests {
11371139
.await
11381140
)
11391141
.expect("instance should be locked");
1140-
assert_eq!(lock1.saga_lock_id, saga1);
1142+
assert_eq!(lock1.updater_id, saga1);
11411143

11421144
// doing it again should be fine.
11431145
let lock2 = dbg!(
@@ -1148,7 +1150,7 @@ mod tests {
11481150
.expect(
11491151
"instance_updater_lock should succeed again with the same saga ID",
11501152
);
1151-
assert_eq!(lock2.saga_lock_id, saga1);
1153+
assert_eq!(lock2.updater_id, saga1);
11521154
// the generation should not have changed as a result of the second
11531155
// update.
11541156
assert_eq!(lock1.locked_gen, lock2.locked_gen);
@@ -1209,7 +1211,7 @@ mod tests {
12091211
// an incorrect one is constructed, or a raw database query
12101212
// attempts an invalid unlock operation.
12111213
UpdaterLock {
1212-
saga_lock_id: saga2,
1214+
updater_id: saga2,
12131215
locked_gen: lock1.locked_gen,
12141216
},
12151217
)
@@ -1246,7 +1248,7 @@ mod tests {
12461248
// Again, these fields are private specifically to prevent
12471249
// you from doing this exact thing. But, we should still
12481250
// 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 },
12501252
)
12511253
.await
12521254
)

0 commit comments

Comments
 (0)