doris icon indicating copy to clipboard operation
doris copied to clipboard

[Fix](bloom filter) Fix bloom filter memory leak

Open Yukang-Lian opened this issue 9 months ago • 32 comments

Proposed changes

Issue Number: close #xxx

Issue: Doris occasionally encounters an issue where memory usage becomes exceptionally high and does not decrease. The leaked memory is occupied by Bloom filters stored in memory.

Reason: The segment cache stores segment objects read from files into memory. It functions as an LRU cache with an eviction strategy: when the number of segments exceeds the maximum number, or the total memory size of segment objects in the cache exceeds the maximum usage, it evicts the older segments. However, there is a piece of logic in the code that first reads the segment object into memory, assuming it occupies memory size A, then places the read segment object into the cache (at this point, the cache considers the segment object size to be A). It then reads the segment's Bloom filter from the file and assigns it to the segment's Bloom filter member variable, assuming the Bloom filter occupies memory size B. Thus, the total size of the segment object at this point is A+B. However, the cache does not update this size, leading to the actual size of the segment object stored in the cache (A+B) being larger than the size considered by the cache (A). When the number of segment objects in the cache increases to a certain extent, the used memory will surge dramatically. However, the cache does not perceive the size as reaching the eviction limit, so it does not evict the segment objects. In such cases, a memory leak issue arises.

Solution: Since each segment object only reads the Bloom filter once, the issue can be resolved by changing the logic from reading the segment, placing it into the cache, and then reading the Bloom filter to reading the segment, reading the Bloom filter, and then placing it into the cache.

Further comments

If this is a relatively large or complex change, kick off the discussion at [email protected] by explaining why you chose the solution you did and what alternatives you considered, etc...

Yukang-Lian avatar May 14 '24 17:05 Yukang-Lian

Thank you for your contribution to Apache Doris. Don't know what should be done next? See How to process your PR

Since 2024-03-18, the Document has been moved to doris-website. See Doris Document.

doris-robot avatar May 14 '24 17:05 doris-robot

run buildall

Yukang-Lian avatar May 14 '24 17:05 Yukang-Lian

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar May 14 '24 17:05 github-actions[bot]

run buildall

Yukang-Lian avatar May 15 '24 02:05 Yukang-Lian

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar May 15 '24 02:05 github-actions[bot]

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar May 15 '24 02:05 github-actions[bot]

TeamCity be ut coverage result: Function Coverage: 35.65% (8982/25193) Line Coverage: 27.32% (74264/271812) Region Coverage: 26.55% (38373/144512) Branch Coverage: 23.37% (19569/83738) Coverage Report: http://coverage.selectdb-in.cc/coverage/ba50549f489159ad7df63b9249d4544d16f3f4ff_ba50549f489159ad7df63b9249d4544d16f3f4ff/report/index.html

doris-robot avatar May 15 '24 02:05 doris-robot

run buildall

Yukang-Lian avatar May 15 '24 13:05 Yukang-Lian

TeamCity be ut coverage result: Function Coverage: 35.71% (8999/25200) Line Coverage: 27.39% (74481/271969) Region Coverage: 26.61% (38488/144616) Branch Coverage: 23.43% (19639/83806) Coverage Report: http://coverage.selectdb-in.cc/coverage/6d3664a77c67b4962e16f0da9292a96fda602213_6d3664a77c67b4962e16f0da9292a96fda602213/report/index.html

doris-robot avatar May 15 '24 14:05 doris-robot

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar May 16 '24 18:05 github-actions[bot]

run buildall

Yukang-Lian avatar May 16 '24 19:05 Yukang-Lian

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar May 16 '24 19:05 github-actions[bot]

run buildall

Yukang-Lian avatar May 17 '24 07:05 Yukang-Lian

clang-tidy review says "All clean, LGTM! :+1:"

github-actions[bot] avatar May 17 '24 07:05 github-actions[bot]

TeamCity be ut coverage result: Function Coverage: 35.70% (9006/25226) Line Coverage: 27.37% (74526/272261) Region Coverage: 26.61% (38527/144782) Branch Coverage: 23.44% (19658/83878) Coverage Report: http://coverage.selectdb-in.cc/coverage/a60b610b407158dc598e6e2792ae836894d6e368_a60b610b407158dc598e6e2792ae836894d6e368/report/index.html

doris-robot avatar May 17 '24 08:05 doris-robot

PR approved by at least one committer and no changes requested.

github-actions[bot] avatar May 20 '24 11:05 github-actions[bot]

PR approved by anyone and no changes requested.

github-actions[bot] avatar May 20 '24 11:05 github-actions[bot]

run buildall

Yukang-Lian avatar May 20 '24 11:05 Yukang-Lian

run buildall

Yukang-Lian avatar May 20 '24 11:05 Yukang-Lian

run buildall

Yukang-Lian avatar May 20 '24 13:05 Yukang-Lian

run buildall

Yukang-Lian avatar May 20 '24 14:05 Yukang-Lian

TeamCity be ut coverage result: Function Coverage: 35.71% (9016/25250) Line Coverage: 27.36% (74551/272523) Region Coverage: 26.60% (38555/144918) Branch Coverage: 23.43% (19668/83934) Coverage Report: http://coverage.selectdb-in.cc/coverage/35d7eb808d31bd76d65238d5b5613fe183f98ea3_35d7eb808d31bd76d65238d5b5613fe183f98ea3/report/index.html

doris-robot avatar May 20 '24 15:05 doris-robot

run p0

Yukang-Lian avatar May 20 '24 16:05 Yukang-Lian

PR approved by at least one committer and no changes requested.

github-actions[bot] avatar May 21 '24 03:05 github-actions[bot]

run buildall

Yukang-Lian avatar May 21 '24 03:05 Yukang-Lian

run buildall

Yukang-Lian avatar May 21 '24 03:05 Yukang-Lian

TeamCity be ut coverage result: Function Coverage: 35.67% (9013/25265) Line Coverage: 27.33% (74537/272680) Region Coverage: 26.57% (38555/145122) Branch Coverage: 23.41% (19666/84004) Coverage Report: http://coverage.selectdb-in.cc/coverage/a3c78af2f63f0965b830aa39356524c05e48ca0b_a3c78af2f63f0965b830aa39356524c05e48ca0b/report/index.html

doris-robot avatar May 21 '24 04:05 doris-robot

run buildall

Yukang-Lian avatar May 21 '24 05:05 Yukang-Lian

TeamCity be ut coverage result: Function Coverage: 35.68% (9015/25265) Line Coverage: 27.34% (74551/272680) Region Coverage: 26.58% (38571/145124) Branch Coverage: 23.41% (19670/84006) Coverage Report: http://coverage.selectdb-in.cc/coverage/505cd66bdfaeff63c763c04048142e18f5d929a4_505cd66bdfaeff63c763c04048142e18f5d929a4/report/index.html

doris-robot avatar May 21 '24 05:05 doris-robot

run buildall

Yukang-Lian avatar May 21 '24 06:05 Yukang-Lian