Skip to content

Commit

Permalink
[bugfix]teach BufferedBlockMgr2 track memory right (#9722)
Browse files Browse the repository at this point in the history
The problem was introduced by e2d3d01.
  • Loading branch information
dataroaring authored and morningman committed May 27, 2022
1 parent d0c4b5c commit 0dce0ff
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions be/src/runtime/buffered_block_mgr2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,7 @@ bool BufferedBlockMgr2::consume_memory(Client* client, int64_t size) {
}
int buffers_needed = BitUtil::ceil(size, max_block_size());
unique_lock<mutex> lock(_lock);
Status st = _mem_tracker->TryConsume(size);
WARN_IF_ERROR(st, "consume failed");
if (size < max_block_size() && st) {
if (size < max_block_size() && _mem_tracker->TryConsume(size)) {
// For small allocations (less than a block size), just let the allocation through.
client->_tracker->ConsumeLocal(size, client->_query_tracker.get());
// client->_tracker->Consume(size);
Expand All @@ -336,7 +334,7 @@ bool BufferedBlockMgr2::consume_memory(Client* client, int64_t size) {
if (available_buffers(client) + client->_num_tmp_reserved_buffers < buffers_needed) {
return false;
}
st = _mem_tracker->TryConsume(size);
Status st = _mem_tracker->TryConsume(size);
WARN_IF_ERROR(st, "consume failed");
if (st) {
// There was still unallocated memory, don't need to recycle allocated blocks.
Expand Down Expand Up @@ -1094,10 +1092,9 @@ Status BufferedBlockMgr2::find_buffer_for_block(Block* block, bool* in_mem) {
Status BufferedBlockMgr2::find_buffer(unique_lock<mutex>& lock, BufferDescriptor** buffer_desc) {
*buffer_desc = nullptr;

Status st = _mem_tracker->TryConsume(_max_block_size);
WARN_IF_ERROR(st, "try to allocate a new buffer failed");
// First, try to allocate a new buffer.
if (_free_io_buffers.size() < _block_write_threshold && st) {
if (_free_io_buffers.size() < _block_write_threshold &&
_mem_tracker->TryConsume(_max_block_size)) {
uint8_t* new_buffer = new uint8_t[_max_block_size];
*buffer_desc = _obj_pool.add(new BufferDescriptor(new_buffer, _max_block_size));
(*buffer_desc)->all_buffers_it =
Expand Down

0 comments on commit 0dce0ff

Please sign in to comment.