Closed uchuck closed 1 year ago
Looks like we should use uint64 in https://github.com/allegro/bigcache/blob/982ec3b09cacb9936b88dcfdaed329870065cf23/shard.go#L19 I think it will be backward compatible change. Would you like to contribute a patch with a test for this case?
Looks like we should use uint64 in
https://github.com/allegro/bigcache/blob/982ec3b09cacb9936b88dcfdaed329870065cf23/shard.go#L19
I think it will be backward compatible change. Would you like to contribute a patch with a test for this case?
I was thinking the same change. However, it could potentially increase the total space of the BigCache in the case if people use it to store a huge number of small entries. The size of entries Queue won't change, but the size of map keys will be doubled. Will this be a concern for the original BigCache design?
That's true. The solution could be to change map type when we hit given threshold. I'm wondering if this issue is the root cause of https://github.com/allegro/bigcache/issues/290 Anyway, although change from 32 to 64 bits could double memory overhead I believe this footprint should be small enough that nobody will notice.
Sure, then I can make a patch and test it.
What is the issue you are having? When the entries of a cacheShard is large enough,
set
a new item into the entries, thenget
the item could fail with "not found" error.What is BigCache doing that it shouldn't? The reason is when the entries of a cacheShard is large enough, set a new item into the entries could result in a large index, then this index is converted to uint32 since the hashmap takes uint32 as the value.
Minimal, Complete, and Verifiable Example This issue is found with a stress test when I set an item to the cacheShard, I got an index value "5576813569", but when this index was added to the hashmap, it's converted to uint32, which is "1281846273". Therefore, when I tried to get this item, I got this wrong index(1281846273) from the hashmap, then I got the wrong entry. Since the entry is wrong, the entryKey doesn't match with the actual key passed by
get
function, then BigCache considered this as a Collision and returned ErrEntryNotFound in the following code:For more information on how to provide an MCVE, please see the Stack Overflow documentation.
Environment:
/etc/os-release
or winver.exe): both Mac and Linux 64 bitsgo version go1.19.4 darwin/arm64