From a5cab284c1313d120e9dbd5858f647ec6732e43d Mon Sep 17 00:00:00 2001 From: Kaijie Chen Date: Thu, 26 Sep 2024 10:05:40 +0800 Subject: [PATCH] [fix](load) fix priority queue order in memtable memory limiter (#41278) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Proposed changes #41018 used priority queue when selecting memtables to flush. But the compare function is wrong and causing the order to be the opposite. > Note that the Compare parameter is defined such that it returns true if its first argument comes before its second argument in a weak ordering. But because the priority queue outputs largest elements first, the elements that "come before" are actually output last. That is, the front of the queue contains the "last" element according to the weak ordering imposed by Compare. This PR fixes the compare function to make larger memtables come front. --- be/src/olap/memtable_memory_limiter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/be/src/olap/memtable_memory_limiter.cpp b/be/src/olap/memtable_memory_limiter.cpp index 464e729c1b4499..edb8ab57f87af9 100644 --- a/be/src/olap/memtable_memory_limiter.cpp +++ b/be/src/olap/memtable_memory_limiter.cpp @@ -163,7 +163,7 @@ void MemTableMemoryLimiter::_flush_active_memtables(int64_t need_flush) { } using WriterMem = std::pair, int64_t>; - auto cmp = [](WriterMem left, WriterMem right) { return left.second > right.second; }; + auto cmp = [](WriterMem left, WriterMem right) { return left.second < right.second; }; std::priority_queue, decltype(cmp)> heap(cmp); for (auto writer : _active_writers) {