Increment cache_first_available_item by one in uwsgi_cache_set when an index is reused from cache_unused_stack and cache_first_available_item is equal to the index reused.#160
Closed
laurentluce wants to merge 1 commit intounbit:uwsgi-1.4from
laurentluce:uwsgi-1.4
Closed
Increment cache_first_available_item by one in uwsgi_cache_set when an index is reused from cache_unused_stack and cache_first_available_item is equal to the index reused.#160laurentluce wants to merge 1 commit intounbit:uwsgi-1.4from laurentluce:uwsgi-1.4
laurentluce wants to merge 1 commit intounbit:uwsgi-1.4from
laurentluce:uwsgi-1.4
Conversation
…n index is reused from cache_unused_stack and cache_first_available_item is equal to the index reused.
Owner
|
Great, you have found the problem, but i think it is better to remove the (useless) optimization in cache_del: can you check if it solve your problem ? (i have applied it only in 1.4 branch) |
Author
|
I ran the following test: cache_set('A', pickle.dumps('test1'))
cache_set('B', pickle.dumps('test2'))
cache_del('B')
cache_set('C', pickle.dumps('test3'))
cache_set('D', pickle.dumps('test4'))
if not cache_get('C')
print 'ERROR'With both patches (yours and mine), cache_get returns the value for the key 'C' while it does not with the original code. The issue I was seeing seems fixed now. I agree that your patch is better as it gets rid of the useless optimization in the first place versus mine which is correcting the first available item when the index is reused. |
Owner
|
ok, i will make a couple more tests and i will release 1.4.7. Thanks a lot for your help (your credits will be in the public changelog) |
Author
|
Do you have an ETA for 1.4.7? |
Owner
|
today ;) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cache is empty to start with:
cache_unused_stack_ptr = 0
cache_first_available_item = 1
Add key "A":
key "A" -> cache_items[1]
cache_first_available_item = 2
cache_hashtable[hash("A")] = 1
Add key "B":
key "B" -> cache_items[2]
cache_first_available_item = 3
cache_hashtable[hash("B")] = 2
Delete key "B"
cache_unused_stack[1] = 2
cache_unused_stack_ptr = 1
cache_hashtable[hash("B")] = 0
cache_first_available_item = 2
Add key "C":
key C -> cache_items[2] - reused from cache_unused_stack[1]
cache_unused_stack_ptr = 0
cache_hashtable[hash("C")] = 2
At this point, cache_first_available_item is still equal to 2 and there is nothing to reuse anymore.
Add key "D":
key D -> cache_items[2] - Issue here is that key "C" is already here so it gets overwritten.
cache_hashtable[hash("D")] = 2
Get key "C":
cache_get_index returns 0 because the hash at cache_items[2] is not the same as hash("C"). cache_hashtable[hash("C")] does contains index 2 though.
Now if you try to add key "C". The key "C" will be added over and over and create more and more collisions. Getting key "C" will still return None.
I think cache_first_available_item should be incremented by one in uwsgi_cache_set when an index is reused from cache_unused_stack and cache_first_available_item is equal to the index reused.