yiguolei commented on code in PR #41018:
URL: https://github.com/apache/doris/pull/41018#discussion_r1767893069
##########
be/src/olap/memtable_memory_limiter.cpp:
##########
@@ -155,50 +158,50 @@ void
MemTableMemoryLimiter::_flush_active_memtables(int64_t need_flush) {
if (_active_writers.size() == 0) {
return;
}
+
+ using WriterMem = std::pair<std::weak_ptr<MemTableWriter>, int64_t>;
+ auto cmp = [](WriterMem left, WriterMem right) { return left.second >
right.second; };
+ std::priority_queue<WriterMem, std::vector<WriterMem>, decltype(cmp)>
heap(cmp);
+
+ for (auto writer : _active_writers) {
+ auto w = writer.lock();
+ if (w == nullptr) {
+ continue;
+ }
+ heap.emplace(w, w->active_memtable_mem_consumption());
+ }
+
int64_t mem_flushed = 0;
int64_t num_flushed = 0;
- int64_t avg_mem = _active_mem_usage / _active_writers.size();
- for (auto writer : _active_writers) {
- int64_t mem = _flush_memtable(writer, avg_mem);
+
+ while (mem_flushed < need_flush && !heap.empty()) {
+ auto [writer, sort_mem] = heap.top();
+ heap.pop();
+ auto w = writer.lock();
+ if (w == nullptr) {
+ continue;
+ }
+ int64_t mem = w->active_memtable_mem_consumption();
+ if (mem < sort_mem * 0.9) {
+ // if the memtable writer just got flushed, don't flush it again
Review Comment:
when will reach this code?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]