[CP] record piece entity memory

This commit is contained in:
LiuYoung00 2024-02-07 20:37:16 +00:00 committed by ob-robot
parent b88eb76b6d
commit 244894e676
2 changed files with 12 additions and 13 deletions

View File

@ -368,24 +368,23 @@ int ObPiece::piece_init(ObSQLSessionInfo &session,
lib::ContextParam param;
param.set_mem_attr(session.get_effective_tenant_id(),
ObModIds::OB_PL_TEMP, ObCtxIds::DEFAULT_CTX_ID);
param.set_page_size(OB_MALLOC_BIG_BLOCK_SIZE);
param.set_page_size(OB_MALLOC_NORMAL_BLOCK_SIZE);
if (OB_FAIL((static_cast<ObPieceCache*>(session.get_piece_cache()))
->mem_context_->CREATE_CONTEXT(entity, param))) {
->mem_context_->CREATE_CONTEXT(entity_, param))) {
LOG_WARN("failed to create ref cursor entity", K(ret));
} else if (OB_ISNULL(entity)) {
} else if (OB_ISNULL(entity_)) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("failed to alloc ref cursor entity", K(ret));
} else {
void *buf = NULL;
ObPieceBufferArray *buf_array = NULL;
ObIAllocator *alloc = &entity->get_arena_allocator();
ObIAllocator *alloc = &entity_->get_arena_allocator();
OV (OB_NOT_NULL(buf = alloc->alloc(sizeof(ObPieceBufferArray))),
OB_ALLOCATE_MEMORY_FAILED, sizeof(ObPieceBufferArray));
OX (MEMSET(buf, 0, sizeof(ObPieceBufferArray)));
OV (OB_NOT_NULL(buf_array = new (buf) ObPieceBufferArray(alloc)));
OZ (buf_array->reserve(OB_MAX_PIECE_COUNT));
if (OB_SUCC(ret)) {
set_allocator(alloc);
set_buffer_array(buf_array);
} else {
ret = OB_ERR_UNEXPECTED;

View File

@ -159,17 +159,18 @@ public:
param_id_(-1),
pos_(0),
buffer_array_(NULL),
allocator_(NULL),
is_null_map_(),
err_ret_(OB_SUCCESS) {}
err_ret_(OB_SUCCESS),
entity_(nullptr) {}
~ObPiece() { reset(); }
void reset()
{
if (NULL != buffer_array_) {
reset_buffer_array();
}
if (NULL != allocator_) {
allocator_->reset();
if (nullptr != entity_) {
DESTROY_CONTEXT(entity_);
entity_ = nullptr;
}
stmt_id_ = 0;
param_id_ = -1;
@ -182,7 +183,7 @@ public:
for (uint64_t i = 0; i < buffer_array_->count(); i++) {
ObPieceBuffer piece_buffer = buffer_array_->at(i);
piece_buffer.~ObPieceBuffer();
allocator_->free(&piece_buffer);
entity_->get_arena_allocator().free(&piece_buffer);
}
}
}
@ -193,8 +194,7 @@ public:
void set_position(uint64_t pos) { pos_ = pos; }
uint64_t get_position() { return pos_; }
void add_position() { pos_++; }
void set_allocator(ObIAllocator *alloc) { allocator_ = alloc; }
ObIAllocator *get_allocator() { return allocator_; }
ObIAllocator *get_allocator() { return nullptr != entity_ ? &entity_->get_arena_allocator() : NULL; }
common::ObBitSet<> &get_is_null_map() { return is_null_map_; }
void get_is_null_map(char *map, int64_t count) {
for (int64_t i = 0; i<count; i++) {
@ -213,9 +213,9 @@ private:
uint16_t param_id_;
uint64_t pos_;
ObPieceBufferArray *buffer_array_;
ObIAllocator *allocator_;
common::ObBitSet<> is_null_map_;
int err_ret_;
lib::MemoryContext entity_;
}; // end of class ObPiece
class ObPieceCache {