Skip to content

Mitigate LFU struct tearing (new node) #596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

bitfaster
Copy link
Owner

@bitfaster bitfaster commented May 26, 2024

When updating a large struct, instead of updating in place, we can instead create a new node. Since nodes are not updated, no tearing can occur.

Time based expiry is a special case that is handled as follows:

  • The new INodePolicy.Clone method creates the replacement node to insert into the dictionary. For ExpireAfterPolicy this avoids calling expiry calculator on create, and we set current expiry to match old node. We also set GetNextInTimeOrder == self, this is a hack so that ExpireAfterPolicy.OnWrite knows the node was not created and is currently detached from the TimerWheel.
  • In ExpireAfterPolicy.OnWrite, check if next == self to schedule/reschedule. Schedule will just overwrite next to a valid node.
  • Add note to GetNextInTimeOrder to explain

TODO:

  • Unit test
  • Soak test
  • Verify TLFU logic

@coveralls
Copy link

coveralls commented May 26, 2024

Coverage Status

coverage: 98.702% (-0.4%) from 99.141%
when pulling 15edc9f on users/alexpeck/tornwrite3
into 07f8a1c on main.

@bitfaster bitfaster changed the title Mitigate LFU struct tearing Mitigate LFU struct tearing (new node) May 28, 2024
@bitfaster
Copy link
Owner Author

Superseded by #621

@bitfaster bitfaster closed this Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants