Skip to content
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

缓存更新操作缺失锁,当同条记录高速并发更新的时候,写入的缓存可能是错误的。 #128

Open
OuYangJinTing opened this issue Jan 29, 2021 · 0 comments

Comments

@OuYangJinTing
Copy link
Contributor

OuYangJinTing commented Jan 29, 2021

user = User.create(name: "test", email: "[email protected]")
user1 = User.fetch_by_uniq_keys(id: user.id)
user2 = User.fetch_by_uniq_keys(id: user.id)

user1.update_attribute(:name, "user1")
user2.update_attribute(:email, "[email protected]")

user_from_cache = User.fetch_by_uniq_keys(id: user.id)
user_from_database = User.without_second_level_cache { User.find(user.id) }

assert_equal user_from_database.attributes, user_from_cache.attributes

------------------------------------------------------------------------------------------------------------------------------
bundle exec rake test result:
Failure:
FetchByUinqKeyTest#test_simulation_high_speed_update_same_record [/Code/second_level_cache/test/fetch_by_uniq_key_test.rb:111]:                                           
--- expected                                                                                                                                                              
+++ actual                                                                                                                                                                
@@ -1 +1 @@                                                                                                                                                               
-{"id"=>2, "options"=>[], "json_options"=>nil, "extras"=>{}, "name"=>"user1", "email"=>"[email protected]", "status"=>"active", "books_count"=>0, "images_count"=>0, "created_at"=>2021-01-29 06:42:26.331878 UTC, "updated_at"=>2021-01-29 06:42:28.335177 UTC}                                                                                      
+{"id"=>2, "options"=>[], "json_options"=>nil, "extras"=>{}, "name"=>"test", "email"=>"[email protected]", "status"=>"active", "books_count"=>0, "images_count"=>0, "created_at"=>2021-01-29 06:42:26.331878 UTC, "updated_at"=>2021-01-29 06:42:28.335177 UTC}
@OuYangJinTing OuYangJinTing changed the title 写入操作没有锁,当同条记录高速并发更新的时候,写入的缓存可能是错误的。 缓存更新操作缺失锁,当同条记录高速并发更新的时候,写入的缓存可能是错误的。 Jan 29, 2021
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

No branches or pull requests

1 participant