use shared block cache to manage a batch of chunk store in em sort
This commit is contained in:
committed by
ob-robot
parent
65ebe32909
commit
d5487f24ae
@ -2393,6 +2393,13 @@ void ObChunkDatumStore::Iterator::reset_cursor(const int64_t file_size)
|
||||
free_block(free_list_.remove_first(), default_block_size_, force_free);
|
||||
}
|
||||
|
||||
if (nullptr != blk_holder_ptr_) {
|
||||
if (blk_holder_ptr_->block_list_.get_size() > 0) {
|
||||
blk_holder_ptr_->release();
|
||||
blk_holder_ptr_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
cur_iter_blk_ = nullptr;
|
||||
cur_nth_blk_ = -1;
|
||||
cur_iter_pos_ = 0;
|
||||
@ -2567,7 +2574,12 @@ void ObChunkDatumStore::Iterator::free_block(Block *blk, const int64_t size,
|
||||
bool do_phy_free = force_free;
|
||||
if (!force_free) {
|
||||
try_free_cached_blocks();
|
||||
if (NULL != age_) {
|
||||
if (NULL != blk_holder_ptr_) {
|
||||
// fill iter ptr at pos of age, since we do not use age in shared cache
|
||||
*((int64_t *)((char *)blk + size - sizeof(int64_t))) = reinterpret_cast<int64_t> (this);
|
||||
blk_holder_ptr_->block_list_.add_last(blk);
|
||||
blk->blk_size_ = size;
|
||||
} else if (NULL != age_) {
|
||||
STATIC_ASSERT(sizeof(BlockBuffer) >= sizeof(int64_t), "unexpected block buffer size");
|
||||
// Save age to the tail of the block, we always allocate one BlockBuffer in tail of block,
|
||||
// it's safe to write it here.
|
||||
@ -2660,5 +2672,18 @@ int ObChunkDatumStore::Iterator::aio_wait()
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ObChunkDatumStore::IteratedBlockHolder::release()
|
||||
{
|
||||
while (block_list_.get_size() > 0) {
|
||||
Block *blk = block_list_.remove_first();
|
||||
Iterator *iter = reinterpret_cast<Iterator *> (*((int64_t *)((char *)blk + blk->blk_size_ - sizeof(int64_t))));
|
||||
if (OB_NOT_NULL(blk) && OB_NOT_NULL(iter)) {
|
||||
iter->free_block(blk, blk->blk_size_, true);
|
||||
} else {
|
||||
LOG_ERROR_RET(OB_ERR_UNEXPECTED, "get unexpected block pair", KP(iter), KP(blk));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // end namespace sql
|
||||
} // end namespace oceanbase
|
||||
|
||||
@ -678,7 +678,17 @@ public:
|
||||
private:
|
||||
int64_t age_;
|
||||
};
|
||||
struct IteratedBlockHolder
|
||||
{
|
||||
IteratedBlockHolder() : block_list_() {}
|
||||
~IteratedBlockHolder()
|
||||
{
|
||||
release();
|
||||
}
|
||||
void release();
|
||||
|
||||
BlockList block_list_;
|
||||
};
|
||||
class Iterator
|
||||
{
|
||||
public:
|
||||
@ -689,6 +699,7 @@ public:
|
||||
DISK_ITER_END = 0x02
|
||||
};
|
||||
friend class ObChunkDatumStore;
|
||||
friend class IteratedBlockHolder;
|
||||
Iterator() : start_iter_(false),
|
||||
store_(NULL),
|
||||
cur_iter_blk_(NULL),
|
||||
@ -704,7 +715,8 @@ public:
|
||||
read_blk_buf_(NULL),
|
||||
aio_blk_(NULL),
|
||||
aio_blk_buf_(NULL),
|
||||
age_(NULL) {}
|
||||
age_(NULL),
|
||||
blk_holder_ptr_(NULL) {}
|
||||
virtual ~Iterator() { reset_cursor(0); }
|
||||
int init(ObChunkDatumStore *row_store, const IterationAge *age = NULL);
|
||||
void set_iteration_age(const IterationAge *age) { age_ = age; }
|
||||
@ -763,10 +775,11 @@ public:
|
||||
void free_block(Block *blk, const int64_t size, bool force_free = false);
|
||||
void try_free_cached_blocks();
|
||||
int64_t get_cur_chunk_row_cnt() const { return chunk_n_rows_;}
|
||||
void set_blk_holder_ptr(IteratedBlockHolder *ptr) { blk_holder_ptr_ = ptr;}
|
||||
TO_STRING_KV(KP_(store), KP_(cur_iter_blk),
|
||||
K_(cur_chunk_n_blocks), K_(cur_iter_pos), K_(file_size),
|
||||
KP_(chunk_mem), KP_(read_blk), KP_(read_blk_buf), KP_(aio_blk),
|
||||
KP_(aio_blk_buf), K_(default_block_size));
|
||||
KP_(aio_blk_buf), K_(default_block_size), KP_(blk_holder_ptr));
|
||||
private:
|
||||
explicit Iterator(ObChunkDatumStore *row_store);
|
||||
protected:
|
||||
@ -799,6 +812,7 @@ public:
|
||||
IterationAge inner_age_;
|
||||
const IterationAge *age_;
|
||||
int64_t default_block_size_;
|
||||
IteratedBlockHolder *blk_holder_ptr_;
|
||||
};
|
||||
|
||||
struct BatchCtx
|
||||
|
||||
Reference in New Issue
Block a user