[#8377] improvement(core): Optimize CaffeineEntityCache using segmented locking#8452
[#8377] improvement(core): Optimize CaffeineEntityCache using segmented locking#8452yuqi1129 merged 3 commits intoapache:mainfrom
Conversation
5f14cf5 to
b0be824
Compare
b0be824 to
66dbd8c
Compare
| // Number of lock segments for cache concurrency optimization | ||
| public static final ConfigEntry<Integer> CACHE_LOCK_SEGMENTS = | ||
| new ConfigBuilder("gravitino.cache.lockSegments") | ||
| .doc("Number of lock segments for cache concurrency optimization.") |
There was a problem hiding this comment.
Could you please provide more details about what this configuration entails? You'd better disclose that you are using guava Striped<lock> to replace the traditional lock for better concurrency performance. In the meantime, a reference link is always appreciated.
| .version(ConfigConstants.VERSION_1_0_0) | ||
| .intConf() | ||
| .checkValue(value -> value > 0, "Lock segments must be positive") | ||
| .createWithDefault(16); |
There was a problem hiding this comment.
Is 16 the advised value by guava?
There was a problem hiding this comment.
No, 16 is not specifically advised by Guava, I referenced the DEFAULT_CAPACITY value of ConcurrentHashMap.
| */ | ||
| public <E extends Exception> void withLockAndThrow( | ||
| Object key, EntityCache.ThrowingRunnable<E> action) throws E { | ||
| waitForGlobalComplete(); |
There was a problem hiding this comment.
I can't understand why we need to obtain a global lock first and then try to lock the segment lock? Could you give me more detail about it?
There was a problem hiding this comment.
@yuqi1129 The global lock was intended for clear()
cc6332e to
efd01a7
Compare
|
@sunxiaojian |
yuqi1129
left a comment
There was a problem hiding this comment.
It generally LGTM except some minor ones.
|
@sunxiaojian We are planning to merge this PR in the 1.0.0, can you please fix the comments mentioned above? If you don't have time, @yuqi1129 can you please help on this? |
ok |
e33b914 to
c35c5d5
Compare
|
Let's wait for the CI pass before proceeding with LGTM. |
c35c5d5 to
cc8b81d
Compare
…ed locking (#8452) <!-- 1. Title: [#<issue>] <type>(<scope>): <subject> Examples: - "[#123] feat(operator): support xxx" - "[#233] fix: check null before access result in xxx" - "[MINOR] refactor: fix typo in variable name" - "[MINOR] docs: fix typo in README" - "[#255] test: fix flaky test NameOfTheTest" Reference: https://www.conventionalcommits.org/en/v1.0.0/ 2. If the PR is unfinished, please mark this PR as draft. --> ### What changes were proposed in this pull request? Optimize CaffeineEntityCache using segmented locking ### Why are the changes needed? Fix: [#(8377)](#8377) ### Does this PR introduce _any_ user-facing change? N/A ### How was this patch tested? TestSegmentedLock.java
…egmented locking (apache#8452) <!-- 1. Title: [#<issue>] <type>(<scope>): <subject> Examples: - "[apache#123] feat(operator): support xxx" - "[apache#233] fix: check null before access result in xxx" - "[MINOR] refactor: fix typo in variable name" - "[MINOR] docs: fix typo in README" - "[apache#255] test: fix flaky test NameOfTheTest" Reference: https://www.conventionalcommits.org/en/v1.0.0/ 2. If the PR is unfinished, please mark this PR as draft. --> ### What changes were proposed in this pull request? Optimize CaffeineEntityCache using segmented locking ### Why are the changes needed? Fix: [#(8377)](apache#8377) ### Does this PR introduce _any_ user-facing change? N/A ### How was this patch tested? TestSegmentedLock.java
…egmented locking (apache#8452) <!-- 1. Title: [#<issue>] <type>(<scope>): <subject> Examples: - "[apache#123] feat(operator): support xxx" - "[apache#233] fix: check null before access result in xxx" - "[MINOR] refactor: fix typo in variable name" - "[MINOR] docs: fix typo in README" - "[apache#255] test: fix flaky test NameOfTheTest" Reference: https://www.conventionalcommits.org/en/v1.0.0/ 2. If the PR is unfinished, please mark this PR as draft. --> ### What changes were proposed in this pull request? Optimize CaffeineEntityCache using segmented locking ### Why are the changes needed? Fix: [#(8377)](apache#8377) ### Does this PR introduce _any_ user-facing change? N/A ### How was this patch tested? TestSegmentedLock.java
…egmented locking (apache#8452) <!-- 1. Title: [#<issue>] <type>(<scope>): <subject> Examples: - "[apache#123] feat(operator): support xxx" - "[apache#233] fix: check null before access result in xxx" - "[MINOR] refactor: fix typo in variable name" - "[MINOR] docs: fix typo in README" - "[apache#255] test: fix flaky test NameOfTheTest" Reference: https://www.conventionalcommits.org/en/v1.0.0/ 2. If the PR is unfinished, please mark this PR as draft. --> ### What changes were proposed in this pull request? Optimize CaffeineEntityCache using segmented locking ### Why are the changes needed? Fix: [#(8377)](apache#8377) ### Does this PR introduce _any_ user-facing change? N/A ### How was this patch tested? TestSegmentedLock.java
What changes were proposed in this pull request?
Optimize CaffeineEntityCache using segmented locking
Why are the changes needed?
Fix: #(8377)
Does this PR introduce any user-facing change?
N/A
How was this patch tested?
TestSegmentedLock.java