fix MERGE_RESERVE_CTX_ID failed to reserve memory

This commit is contained in:
tushicheng
2024-01-24 04:13:10 +00:00
committed by ob-robot
parent 2fd0c4171c
commit 2efe7b500b
3 changed files with 20 additions and 3 deletions

View File

@ -586,9 +586,7 @@ int64_t ObMallocAllocator::sync_wash(uint64_t tenant_id, uint64_t from_ctx_id, i
i++) { i++) {
int64_t ctx_id = (from_ctx_id + i) % ObCtxIds::MAX_CTX_ID; int64_t ctx_id = (from_ctx_id + i) % ObCtxIds::MAX_CTX_ID;
auto allocator = get_tenant_ctx_allocator(tenant_id, ctx_id); auto allocator = get_tenant_ctx_allocator(tenant_id, ctx_id);
if (NULL == allocator) { if (NULL != allocator && !(CTX_ATTR(ctx_id).disable_sync_wash_)) {
// do-nothing
} else {
washed_size += allocator->sync_wash(wash_size - washed_size); washed_size += allocator->sync_wash(wash_size - washed_size);
} }
} }

View File

@ -27,6 +27,7 @@ struct ObCtxAttr
bool enable_dirty_list_ = false; bool enable_dirty_list_ = false;
bool enable_no_log_ = false; bool enable_no_log_ = false;
int parallel_ = DEFAULT_CTX_PARALLEL; int parallel_ = DEFAULT_CTX_PARALLEL;
bool disable_sync_wash_ = false;
}; };
struct ObCtxAttrCenter struct ObCtxAttrCenter
@ -49,6 +50,10 @@ public:
#define ENABLE_NO_LOG_DEF(name) ctx_attr_[ObCtxIds::name].enable_no_log_ = true; #define ENABLE_NO_LOG_DEF(name) ctx_attr_[ObCtxIds::name].enable_no_log_ = true;
ENABLE_NO_LOG_DEF(LOGGER_CTX_ID) ENABLE_NO_LOG_DEF(LOGGER_CTX_ID)
#undef ENABLE_NO_LOG_DEF #undef ENABLE_NO_LOG_DEF
#define DISABLE_SYNC_WASH_DEF(name) ctx_attr_[ObCtxIds::name].disable_sync_wash_ = true;
DISABLE_SYNC_WASH_DEF(MERGE_RESERVE_CTX_ID)
#undef DISABLE_SYNC_WASH_DEF
} }
static ObCtxAttrCenter &instance(); static ObCtxAttrCenter &instance();
ObCtxAttr attr_of_ctx(int64_t ctx_id) const ObCtxAttr attr_of_ctx(int64_t ctx_id) const

View File

@ -391,6 +391,20 @@ TEST(TestTenantAllocator, sub_ctx_id)
ASSERT_NE(OB_SUCCESS, malloc_allocator->recycle_tenant_allocator(tenant_id_1)); ASSERT_NE(OB_SUCCESS, malloc_allocator->recycle_tenant_allocator(tenant_id_1));
} }
TEST(TestTenantAllocator, MERGE_RESERVE_CTX)
{
const uint64_t tenant_id = 1002;
ObMallocAllocator* malloc_allocator = ObMallocAllocator::get_instance();
ASSERT_EQ(OB_SUCCESS, malloc_allocator->create_and_add_tenant_allocator(tenant_id));
void *ptr_0 = ob_malloc(100L<<10, ObMemAttr(tenant_id, "Test", 0));
void *ptr_1 = ob_malloc(100L<<10, ObMemAttr(tenant_id, "Test", ObCtxIds::MERGE_RESERVE_CTX_ID));
malloc_allocator->sync_wash(tenant_id, 0, INT64_MAX);
AChunk *chunk_0 = AChunk::ptr2chunk(ptr_0);
AChunk *chunk_1 = AChunk::ptr2chunk(ptr_1);
ASSERT_NE(0, chunk_0->washed_size_);
ASSERT_EQ(0, chunk_1->washed_size_);
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
signal(49, SIG_IGN); signal(49, SIG_IGN);