Skip to content

Commit

Permalink
[improvement](memory) enable exception for get_free_block to avoid oom
Browse files Browse the repository at this point in the history
  • Loading branch information
dataroaring committed Jun 8, 2024
1 parent 1a2c4bc commit 26e2b42
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
11 changes: 6 additions & 5 deletions be/src/vec/exec/scan/scanner_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,19 @@ std::string ScannerContext::parent_name() {
return _local_state->get_name();
}

vectorized::BlockUPtr ScannerContext::get_free_block(bool force) {
vectorized::BlockUPtr block = nullptr;
Status ScannerContext::get_free_block(bool force, vectorized::BlockUPtr& block) {
block = nullptr;
if (_free_blocks.try_dequeue(block)) {
DCHECK(block->mem_reuse());
_free_blocks_memory_usage -= block->allocated_bytes();
_free_blocks_memory_usage_mark->set(_free_blocks_memory_usage);
} else if (_free_blocks_memory_usage < _max_bytes_in_queue || force) {
_newly_create_free_blocks_num->update(1);
block = vectorized::Block::create_unique(_output_tuple_desc->slots(), 0,
true /*ignore invalid slots*/);
RETURN_IF_CATCH_EXCEPTION(block = vectorized::Block::create_unique(_output_tuple_desc->slots(), 0,
true /*ignore invalid slots*/));
}
return block;

return Status::OK();
}

void ScannerContext::return_free_block(vectorized::BlockUPtr block) {
Expand Down
2 changes: 1 addition & 1 deletion be/src/vec/exec/scan/scanner_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class ScannerContext : public std::enable_shared_from_this<ScannerContext>,
}
Status init();

vectorized::BlockUPtr get_free_block(bool force);
Status get_free_block(bool force, vectorized::BlockUPtr& block);
void return_free_block(vectorized::BlockUPtr block);
inline void inc_free_block_usage(size_t usage) {
_free_blocks_memory_usage += usage;
Expand Down
5 changes: 3 additions & 2 deletions be/src/vec/exec/scan/scanner_scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,9 @@ void ScannerScheduler::_scanner_scan(std::shared_ptr<ScannerContext> ctx,
eos = true;
break;
}
BlockUPtr free_block = ctx->get_free_block(first_read);
if (free_block == nullptr) {
BlockUPtr free_block = nullptr;
status = ctx->get_free_block(first_read, free_block));
if (free_block == nullptr || !status.ok()) {
break;
}
status = scanner->get_block_after_projects(state, free_block.get(), &eos);
Expand Down

0 comments on commit 26e2b42

Please sign in to comment.