Skip to content

Check the configuration and table size when reclaiming keys.#19

Merged
keathley merged 1 commit intomainfrom
avoid-multiple-reclaims
Mar 30, 2026
Merged

Check the configuration and table size when reclaiming keys.#19
keathley merged 1 commit intomainfrom
avoid-multiple-reclaims

Conversation

@keathley
Copy link
Copy Markdown
Member

This should help resolve an issue where multiple reclamations could remove all of the keys in a cache. I believe @jeffutter pointed this out years ago and it took me a while to get around to thinking about it. This is what burnout does to a person.

@keathley keathley force-pushed the avoid-multiple-reclaims branch from bf661e2 to 8ab2c19 Compare March 26, 2026 17:44
Comment thread lib/mentat.ex
@doc false
def remove_oldest(cache, count) do
ms = [{{:_, :_, :"$1", :_}, [], [:"$1"]}]
ms = [{{:"$1", :_, :"$2", :_}, [], [{{:"$2", :"$1"}}]}]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall the PR looks good, can you talk a little about the changes to this function. At first-blush they look effectively equivalent to me, with the exception that I'd assume the former implementation is/could be optimized under the hood when doing that range delete.

Is there some subtlety here I'm missing wherein the updated implementation here is more correct?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous version only looked at the timestamp and then deleted everything less than that timestamp. But that approach will remove more keys than expected if lots of keys were inserted during the same time stamp. This approach pulls back both the key and the timestamp so that we can sort by both and remove a set number of keys. We could make this even more efficient by using an ordered set but...I decided not to do that. I'd want to take better measurements of these functions to make sure that any additional optimization was needed and atm. I just wanted to resolve the bug.

@keathley keathley merged commit 0e39bd4 into main Mar 30, 2026
3 checks passed
@keathley keathley deleted the avoid-multiple-reclaims branch March 30, 2026 14:35
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