提交 5dd12c91 编写于 作者: O obdev 提交者: wangzelin.wzl

Fix ObReserveArenaAllocator reuse() and reset(). And reuse...

Fix ObReserveArenaAllocator reuse() and reset(). And reuse rows_info.scan_mem_allocator at the end of exist.
上级 0b9d1f8c
......@@ -80,7 +80,7 @@ public:
}
virtual void reset() override
{
if (pos_ > MAX_RESERVE_SIZE - 1) {
if (allocator_.used() > 0) {
allocator_.reset();
}
pos_ = 0;
......@@ -88,7 +88,7 @@ public:
}
virtual void reuse() override
{
if (pos_ > MAX_RESERVE_SIZE - 1) {
if (allocator_.used() > 0) {
allocator_.reuse();
}
pos_ = 0;
......
......@@ -271,9 +271,9 @@ int ObExprToOutfileRow::print_field(char *buf, const int64_t buf_len, int64_t &p
if (need_enclose) {
OZ(out_info.enclose_.print_plain_str_literal(buf, buf_len, pos, out_info.print_params_));
}
return ret;
}
return ret;
}
int ObExprToOutfileRow::print_wchar_to_buf(char *buf, const int64_t buf_len, int64_t &pos,
int32_t wchar, ObCollationType coll_type)
{
......
......@@ -42,6 +42,7 @@ public:
int check_min_rowkey_boundary(const blocksstable::ObDatumRowkey &max_rowkey, bool &may_exist);
int refine_rowkeys();
int clear_found_rowkey(const int64_t rowkey_idx);
void reuse_scan_mem_allocator() { scan_mem_allocator_.reuse(); }
OB_INLINE bool all_rows_found() { return delete_count_ == rowkeys_.count(); }
TO_STRING_KV(K_(rowkeys), K_(min_key), K_(table_id), K_(delete_count), K_(exist_helper));
public:
......
......@@ -498,6 +498,7 @@ int ObSSTable::exist(ObRowsInfo &rows_info, bool &is_exist, bool &all_rows_found
}
iter->~ObStoreRowIterator();
rows_info.exist_helper_.table_access_context_.allocator_->free(iter);
rows_info.reuse_scan_mem_allocator();
}
}
return ret;
......
......@@ -56,6 +56,7 @@ ob_unittest(test_qsync_lock lock/test_qsync_lock.cpp)
ob_unittest(test_ob_occam_time_guard)
ob_unittest(test_cluster_version)
add_subdirectory(allocator)
add_subdirectory(auto_increment)
add_subdirectory(cache)
add_subdirectory(client_feedback)
......
storage_unittest(test_reserve_arena_allocator)
\ No newline at end of file
/**
* Copyright (c) 2022 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#include <gtest/gtest.h>
#define protected public
#define private public
#include "share/allocator/ob_reserve_arena.h"
#include "share/rc/ob_tenant_base.h"
#define OK(ass) ASSERT_EQ(OB_SUCCESS, (ass))
namespace oceanbase
{
using namespace oceanbase::common;
using namespace oceanbase::share;
using namespace std;
namespace unittest
{
class TestReserveArenaAllocator : public::testing::Test
{
public:
typedef ObReserveArenaAllocator<1024> ObStorageReserveAllocator;
TestReserveArenaAllocator();
virtual ~TestReserveArenaAllocator();
ObReserveArenaAllocator<1024> test_allocator_;
};
TestReserveArenaAllocator::TestReserveArenaAllocator():
test_allocator_(ObModIds::OB_STORE_ROW_EXISTER, OB_MALLOC_NORMAL_BLOCK_SIZE, 500)
{
}
TestReserveArenaAllocator::~TestReserveArenaAllocator()
{
}
TEST_F(TestReserveArenaAllocator, test_reset)
{
// test reset
// alloc buf
int64_t sz = 256;
void* p;
for (int64_t i = 0; i < 3; ++i) {
p = test_allocator_.alloc(sz);
}
ASSERT_EQ(test_allocator_.used(), 768);
ASSERT_EQ(test_allocator_.total(), 768);
ASSERT_EQ(test_allocator_.pos_, 768);
test_allocator_.reset();
ASSERT_EQ(test_allocator_.used(), 0);
ASSERT_EQ(test_allocator_.total(), 0);
ASSERT_EQ(test_allocator_.pos_, 0);
// alloc new page 1k < size < 8k
sz = 2048;
p = test_allocator_.alloc(sz);
STORAGE_LOG(INFO, "alloc 2K", K(test_allocator_.allocator_));
ASSERT_NE(p, nullptr);
ASSERT_EQ(test_allocator_.pos_, 0);
ASSERT_GE(test_allocator_.used(), sz);
ASSERT_GE(test_allocator_.total(), sz);
test_allocator_.reset();
ASSERT_EQ(test_allocator_.pos_, 0);
ASSERT_EQ(test_allocator_.used(), 0);
ASSERT_EQ(test_allocator_.total(), 0);
// alloc new page size > 8k
sz = 10240;
p = test_allocator_.alloc(sz);
STORAGE_LOG(INFO, "alloc 10K", K(test_allocator_.allocator_));
ASSERT_NE(p, nullptr);
ASSERT_EQ(test_allocator_.pos_, 0);
ASSERT_GE(test_allocator_.used(), sz);
ASSERT_GE(test_allocator_.total(), sz);
test_allocator_.reset();
ASSERT_EQ(test_allocator_.pos_, 0);
ASSERT_EQ(test_allocator_.used(), 0);
ASSERT_EQ(test_allocator_.total(), 0);
}
TEST_F(TestReserveArenaAllocator, test_reuse)
{
// test reuse
// alloc buf
int64_t sz = 256;
void* p;
for (int64_t i = 0; i < 3; ++i) {
p = test_allocator_.alloc(sz);
}
ASSERT_EQ(test_allocator_.used(), 768);
ASSERT_EQ(test_allocator_.total(), 768);
ASSERT_EQ(test_allocator_.pos_, 768);
test_allocator_.reuse();
STORAGE_LOG(INFO, "after reuse", K(test_allocator_.allocator_));
ASSERT_EQ(test_allocator_.pos_, 0);
// alloc new page 1k < size < 8k
sz = 2048;
p = test_allocator_.alloc(sz);
STORAGE_LOG(INFO, "alloc 2K", K(test_allocator_.allocator_));
ASSERT_NE(p, nullptr);
ASSERT_EQ(test_allocator_.pos_, 0);
ASSERT_GE(test_allocator_.used(), sz);
ASSERT_GE(test_allocator_.total(), sz);
int allocate_total = test_allocator_.total();
test_allocator_.reuse();
STORAGE_LOG(INFO, "after reuse 2K", K(test_allocator_.allocator_));
ASSERT_EQ(test_allocator_.pos_, 0);
ASSERT_EQ(test_allocator_.used(), 0);
ASSERT_LE(test_allocator_.total(), allocate_total);
// alloc new page size > 8k
sz = 10240;
p = test_allocator_.alloc(sz);
STORAGE_LOG(INFO, "alloc 10K", K(test_allocator_.allocator_));
ASSERT_NE(p, nullptr);
ASSERT_EQ(test_allocator_.pos_, 0);
ASSERT_GE(test_allocator_.used(), sz);
ASSERT_GE(test_allocator_.total(), sz);
allocate_total = test_allocator_.total();
test_allocator_.reuse();
STORAGE_LOG(INFO, "after reuse 10K", K(test_allocator_.allocator_));
ASSERT_EQ(test_allocator_.pos_, 0);
ASSERT_EQ(test_allocator_.used(), 0);
ASSERT_LT(test_allocator_.total(), allocate_total);
}
}//end namespace unittest
}//end namespace oceanbase
int main(int argc, char **argv)
{
system("rm -f test_reserve_arena_allocator.log*");
oceanbase::common::ObLogger::get_logger().set_log_level("DEBUG");
OB_LOGGER.set_file_name("test_reserve_arena_allocator.log", true);
srand(time(NULL));
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册