Skip to content

Fix TTL map wrapping sub #221

@jayshrivastava

Description

@jayshrivastava

I'm pretty sure this is wrong:

let bucket_index = (time.wrapping_sub(1)) % self.buckets.len() as u64;
self.buckets[bucket_index as usize].register_key(key);

Assume there's 10 buckets. When inserting a key at time=0, we want the key to go into bucket 9.

However, it ends up going to bucket 5.

(time.wrapping_sub(1)) % self.buckets.len() as u64
= (0 - 1) % 10
= 18,446,744,073,709,551,615 % 10
= 5

Note that time is a u64 that we increment by 1 each time and wraps around to 0.

Prematurely evicting entries in this rare case is not a significant problem, but it's a bug nonetheless.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions