Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some memory problem in blob ut. #4064

Merged
merged 2 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dbms/src/Storages/Page/V3/tests/gtest_blob_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,8 @@ TEST_F(BlobStoreTest, testBlobStoreGcStats)
std::list<size_t> remove_entries_idx2 = {6, 8};

WriteBatch wb;
char c_buff[buff_size * buff_nums];
{
char c_buff[buff_size * buff_nums];
for (size_t i = 0; i < buff_nums; ++i)
{
for (size_t j = 0; j < buff_size; ++j)
Expand Down Expand Up @@ -774,8 +774,8 @@ TEST_F(BlobStoreTest, testBlobStoreGcStats2)
std::list<size_t> remove_entries_idx = {0, 1, 2, 3, 4, 5, 6, 7};

WriteBatch wb;
char c_buff[buff_size * buff_nums];
{
char c_buff[buff_size * buff_nums];
for (size_t i = 0; i < buff_nums; ++i)
{
for (size_t j = 0; j < buff_size; ++j)
Expand Down
37 changes: 17 additions & 20 deletions dbms/src/Storages/Page/V3/tests/gtest_page_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,28 +178,25 @@ TEST_F(PageStorageTest, MultipleWriteRead)
size_t page_id_max = 100;
for (DB::PageId page_id = 0; page_id <= page_id_max; ++page_id)
{
DB::MemHolder holder;

auto buff = [page_id] {
std::mt19937 size_gen;
size_gen.seed(time(nullptr));
std::uniform_int_distribution<> dist(0, 3000);

const size_t buff_sz = 2 * DB::MB + dist(size_gen);
char * buff = static_cast<char *>(malloc(buff_sz));
if (buff == nullptr)
{
throw DB::Exception("Alloc fix memory failed.", DB::ErrorCodes::LOGICAL_ERROR);
}

const char buff_ch = page_id % 0xFF;
memset(buff, buff_ch, buff_sz);
DB::createMemHolder(buff, [&](char * p) { free(p); });
return std::make_shared<DB::ReadBufferFromMemory>(const_cast<char *>(buff), buff_sz);
}();
std::mt19937 size_gen;
size_gen.seed(time(nullptr));
std::uniform_int_distribution<> dist(0, 3000);

const size_t buff_sz = 2 * DB::MB + dist(size_gen);
char * buff = static_cast<char *>(malloc(buff_sz));
if (buff == nullptr)
{
throw DB::Exception("Alloc fix memory failed.", DB::ErrorCodes::LOGICAL_ERROR);
}

const char buff_ch = page_id % 0xFF;
memset(buff, buff_ch, buff_sz);
DB::MemHolder holder = DB::createMemHolder(buff, [&](char * p) { free(p); });

auto read_buff = std::make_shared<DB::ReadBufferFromMemory>(const_cast<char *>(buff), buff_sz);
Comment on lines -181 to +196
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you can make the return type be std::pair<shared_ptr, MemHolder> for this lambda.

Nevertheless, this is also ok for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just remove lambda may more clear for me. :)


DB::WriteBatch wb;
wb.putPage(page_id, 0, buff, buff->buffer().size());
wb.putPage(page_id, 0, read_buff, read_buff->buffer().size());
page_storage->write(std::move(wb));
}

Expand Down