Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Duplicate target insert during attempted target mount #2381

Merged
merged 1 commit into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions iml-services/iml-device/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ pub fn find_targets<'a>(
.iter()
.filter(|(k, _)| *k != &fqdn)
.filter_map(|(k, x)| {
tracing::debug!("Searching for device {:?} on {}", &x, &k);
tracing::debug!("Searching for device {:?} on {}", dev_id, &k);
x.0.get(&dev_id)?;

tracing::debug!("found device on {}!", &k);
Expand All @@ -433,7 +433,8 @@ pub fn find_targets<'a>(
})
.collect();

xs.into_iter()
let xs: Vec<_> = xs
.into_iter()
.map(|(fqdn, ids, mntpnt, fs_uuid, dev_path, target)| Target {
state: "mounted".into(),
active_host_id: Some(*fqdn),
Expand All @@ -457,6 +458,30 @@ pub fn find_targets<'a>(
uuid: fs_uuid.into(),
mount_path: Some(mntpnt.0.to_string_lossy().to_string()),
})
.collect();
johnsonw marked this conversation as resolved.
Show resolved Hide resolved

xs.into_iter()
.fold(HashMap::new(), |mut acc: HashMap<String, Target>, x| {
// We may have multiple incoming mounts for the same uuid.
// This could happen when a target moves quickly but not all agents have reported new
// data yet. Handle this case by indexing by uuid and only overwritting
// if the current target has no associated filesystems.
match acc.get(&x.uuid) {
Some(y) if y.filesystems.is_empty() => {
acc.insert(x.uuid.to_string(), x);
}
None => {
acc.insert(x.uuid.to_string(), x);
}
Some(y) => {
tracing::info!("Skipping insert for {:?}, because we have {:?}", x, y);
}
};

acc
})
.into_iter()
.map(|(_, x)| x)
.collect()
}

Expand Down
8 changes: 8 additions & 0 deletions iml-services/iml-device/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ async fn main() -> Result<(), ImlDeviceError> {
.chain(mgs_targets_to_fs_map)
.collect();

tracing::debug!("target_to_fs_map: {:?}", target_to_fs_map);

tracing::debug!("mount_cache: {:?}", mount_cache);

let targets = find_targets(
&device_cache,
&mount_cache,
Expand All @@ -148,6 +152,10 @@ async fn main() -> Result<(), ImlDeviceError> {
&target_to_fs_map,
);

tracing::debug!("targets: {:?}", targets);

tracing::debug!("target_cache: {:?}", target_cache);

let x = targets.get_changes(&target_cache);

let xs = iml_device::build_updates(x);
Expand Down