Fix replace bridge to align with changes to lox-distributor

This commit is contained in:
onyinyang 2023-05-11 16:51:24 -04:00
parent 508eaf3bdd
commit 0d317cea8c
No known key found for this signature in database
GPG Key ID: 156A6435430C2036
1 changed files with 9 additions and 2 deletions

View File

@ -408,9 +408,7 @@ impl BridgeAuth {
let reachable_bridges = &self.bridge_table.reachable.clone(); let reachable_bridges = &self.bridge_table.reachable.clone();
if let Some(positions) = reachable_bridges.get(bridge) { if let Some(positions) = reachable_bridges.get(bridge) {
for (bucketnum, offset) in positions.iter() { for (bucketnum, offset) in positions.iter() {
// Remove the bridge from the bucket
assert!(self.bridge_table.buckets[*bucketnum as usize][*offset] == *bridge); assert!(self.bridge_table.buckets[*bucketnum as usize][*offset] == *bridge);
self.bridge_table.reachable.remove(bridge);
if available_bridge.is_some() { if available_bridge.is_some() {
self.bridge_table.buckets[*bucketnum as usize][*offset] = self.bridge_table.buckets[*bucketnum as usize][*offset] =
*available_bridge.unwrap(); *available_bridge.unwrap();
@ -418,6 +416,8 @@ impl BridgeAuth {
self.bridge_table self.bridge_table
.reachable .reachable
.insert(*available_bridge.unwrap(), positions.clone()); .insert(*available_bridge.unwrap(), positions.clone());
// Remove the bridge from the bucket
self.bridge_table.reachable.remove(bridge);
res = true res = true
} else if !self.bridge_table.unallocated_bridges.is_empty() { } else if !self.bridge_table.unallocated_bridges.is_empty() {
self.bridge_table.buckets[*bucketnum as usize][*offset] = self.bridge_table.buckets[*bucketnum as usize][*offset] =
@ -427,6 +427,8 @@ impl BridgeAuth {
self.bridge_table.unallocated_bridges.pop().unwrap(), self.bridge_table.unallocated_bridges.pop().unwrap(),
positions.clone(), positions.clone(),
); );
// Remove the bridge from the bucket
self.bridge_table.reachable.remove(bridge);
res = true res = true
} else if !self.bridge_table.spares.is_empty() { } else if !self.bridge_table.spares.is_empty() {
// Get the first spare and remove it from the spares // Get the first spare and remove it from the spares
@ -451,11 +453,16 @@ impl BridgeAuth {
self.bridge_table self.bridge_table
.reachable .reachable
.insert(*replacement, positions.clone()); .insert(*replacement, positions.clone());
// Remove the bridge from the bucket
self.bridge_table.reachable.remove(bridge);
res = true res = true
} }
// If there are no available bridges that can be assigned here, the only thing // If there are no available bridges that can be assigned here, the only thing
// that can be done is return an indication that updating the gone bridge // that can be done is return an indication that updating the gone bridge
// didn't work. // didn't work.
// In this case, we do not mark the bridge as unreachable or remove it from the
// reachable bridges so that we can still find it when a new bridge does become available
// Now we should check that the bucket hasn't become "blocked" due to having no available // Now we should check that the bucket hasn't become "blocked" due to having no available
// bridges // bridges