Skip to content

Commit

Permalink
Fix a bug that eviction listener's key-level locks are not removed
Browse files Browse the repository at this point in the history
when immediate notification mode is used

Add more tests.
  • Loading branch information
tatsuya6502 committed Aug 3, 2023
1 parent 8391d33 commit e86682b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/future/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2009,6 +2009,10 @@ where
fn set_expiration_clock(&self, clock: Option<crate::common::time::Clock>) {
self.base.set_expiration_clock(clock);
}

fn key_locks_map_is_empty(&self) -> bool {
self.base.key_locks_map_is_empty()
}
}

pub struct BlockingOp<'a, K, V, S>(&'a Cache<K, V, S>);
Expand Down Expand Up @@ -2164,6 +2168,7 @@ mod tests {
assert!(!cache.contains_key(&"d"));

verify_notification_vec(&cache, actual, &expected);
assert!(cache.key_locks_map_is_empty());
}

#[test]
Expand Down Expand Up @@ -2353,6 +2358,7 @@ mod tests {
assert_eq!(cache.weighted_size(), 25);

verify_notification_vec(&cache, actual, &expected);
assert!(cache.key_locks_map_is_empty());
}

#[tokio::test]
Expand Down
2 changes: 2 additions & 0 deletions src/sync/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2190,6 +2190,7 @@ mod tests {
assert!(!cache.contains_key(&"d"));

verify_notification_vec(&cache, actual, &expected, delivery_mode);
assert_with_mode!(cache.key_locks_map_is_empty(), delivery_mode);
}
}

Expand Down Expand Up @@ -2320,6 +2321,7 @@ mod tests {
assert_eq_with_mode!(cache.weighted_size(), 25, delivery_mode);

verify_notification_vec(&cache, actual, &expected, delivery_mode);
assert_with_mode!(cache.key_locks_map_is_empty(), delivery_mode);
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/sync/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,13 @@ where

exp_clock
}

fn key_locks_map_is_empty(&self) -> bool {
self.inner
.segments
.iter()
.all(|seg| seg.key_locks_map_is_empty())
}
}

// For unit tests.
Expand Down Expand Up @@ -916,6 +923,7 @@ mod tests {
assert!(!cache.contains_key(&"d"));

verify_notification_vec(&cache, actual, &expected, delivery_mode);
assert_with_mode!(cache.key_locks_map_is_empty(), delivery_mode);
}
}

Expand Down Expand Up @@ -1065,6 +1073,7 @@ mod tests {
assert_eq_with_mode!(cache.weighted_size(), 25, delivery_mode);

verify_notification_vec(&cache, actual, &expected, delivery_mode);
assert_with_mode!(cache.key_locks_map_is_empty(), delivery_mode);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/sync_base/base_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2424,7 +2424,8 @@ where
self.key_locks
.as_ref()
.map(|m| m.is_empty())
.unwrap_or_default()
// If key_locks is None, consider it is empty.
.unwrap_or(true)
}
}

Expand Down

0 comments on commit e86682b

Please sign in to comment.