fix expire cache time#6480
Merged
AlbumenJ merged 2 commits intoapache:masterfrom Mar 26, 2021
wenbochang888:fix-expire-cache
Merged
fix expire cache time#6480AlbumenJ merged 2 commits intoapache:masterfrom wenbochang888:fix-expire-cache
AlbumenJ merged 2 commits intoapache:masterfrom
wenbochang888:fix-expire-cache
Conversation
AlbumenJ
reviewed
Mar 14, 2021
...er/dubbo-filter-cache/src/main/java/org/apache/dubbo/cache/support/expiring/ExpiringMap.java
Outdated
Show resolved
Hide resolved
Author
|
我用中文解释一下 dubbo的缓存 https://dubbo.apache.org/zh/docs/v2.7/user/examples/result-cache/ 其中有一个种为:ExpiringCache 它类似于Redis中的设置key的过期时间,比如我设置了10s后过期,那么我在10s就拿不到了 dubbo官方采用的是一个while循环,processExpires方法,每过一段时间检测map里面所有的key是否过期,如果过期 remove 这种是定时删除,但他有个问题如下描述: 我设置过期时间为10s,同时每10s定时删除。 processExpires会在第0s, 10s, 20s, 30s....执行定期删除 我在第5s放入一个key,第10s检测没有过期,此时我在第17s get的时候,理论上是过期了,但此时我get不为null bug复现,应和Redis一样,不仅采用定时删除,也要采用惰性删除。 即每次get的时候,如果不为空,检测其是否过期。 |
AlbumenJ
approved these changes
Mar 26, 2021
Member
|
LGTM. I will merge it later. @wenbochang888 would you please add some ut test cases for this pr in the future? |
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.
What is the purpose of the change
Let's look at this piece of code. Set the expiration time to 10s and clear the cache every 10s. At the 5s, we put "aaa" and "bbb" into memory. In theory, after 15s, he should be cleared. When we took the aaa-key in 16s, he was still in memory. And when we took the bbb-key in 21s, he was null. At this time we The bug can be located.
Brief changelog
fix expire cache map
Verifying this change
XXXXX
Follow this checklist to help us incorporate your contribution quickly and easily:
[Dubbo-XXX] Fix UnknownException when host config not exist #XXX. Each commit in the pull request should have a meaningful subject line and body.mvn clean install -DskipTests=false&mvn clean test-compile failsafe:integration-testto make sure unit-test and integration-test pass.